Skip to content

Commit 1c3acc7

Browse files
authored
have get-platforms return the available input projects (#100)
* use get-platform to filter, rather than kill on multiple packages * GHA doesn't like the undefineds * or quoted empty strings
1 parent 9c335c4 commit 1c3acc7

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

actions/get-platform/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ outputs:
2626
description: the matrix of os/containers for test tasks
2727
value: ${{ steps.platform.outputs.test-matrix }}
2828
available:
29-
description: whether the platform is unavailable for one or more of the packages
29+
description: which packages are available for the requested platform
3030
value: ${{ steps.platform.outputs.available }}
3131

3232
runs:

actions/get-platform/get-platform.ts

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ args:
99
- --allow-write
1010
---*/
1111

12-
import { parse } from "utils/pkg.ts"
12+
import { parse, str } from "utils/pkg.ts"
1313
import { panic } from "utils"
1414
import tea_init from "../../lib/init().ts"
15-
import { PackageRequirement } from "types"
1615
import usePantry from "../../lib/usePantry.ts"
1716

1817
// These are only needed if we switch back to GHA runners
@@ -31,14 +30,28 @@ type Output = {
3130
buildOs: OS,
3231
container?: string,
3332
testMatrix: { os: OS, container?: string }[]
34-
available: boolean
33+
available: string
3534
}
3635

3736
type OS = string | string[]
3837

3938
const platform = Deno.env.get("PLATFORM") ?? panic("$PLATFORM not set")
4039

41-
const available = await getAvailability(packages)
40+
const available = await (async () => {
41+
const pantry = usePantry()
42+
const platform_ = platform.replace(/\+/, "/")
43+
44+
if (!packages) return ""
45+
46+
const rv = []
47+
48+
for (const pkg of packages) {
49+
const a = await pantry.getPlatforms(pkg)
50+
if (a.includes(platform_)) rv.push(pkg)
51+
}
52+
53+
return rv.map(str).join(" ")
54+
})()
4255

4356
const output: Output = (() => {
4457
switch(platform) {
@@ -48,7 +61,7 @@ const output: Output = (() => {
4861
os,
4962
buildOs: ["self-hosted", "macOS", "X64"],
5063
testMatrix: [{ os }],
51-
available: available.has("darwin/x86-64"),
64+
available,
5265
}
5366
}
5467
case "darwin+aarch64": {
@@ -57,7 +70,7 @@ const output: Output = (() => {
5770
os,
5871
buildOs: os,
5972
testMatrix: [{ os }],
60-
available: available.has("darwin/aarch64"),
73+
available,
6174
}
6275
}
6376
case "linux+aarch64": {
@@ -66,7 +79,7 @@ const output: Output = (() => {
6679
os,
6780
buildOs: os,
6881
testMatrix: [{ os }],
69-
available: available.has("linux/aarch64"),
82+
available,
7083
}
7184
}
7285
case "linux+x86-64": {
@@ -79,7 +92,7 @@ const output: Output = (() => {
7992
{ os, container: "ubuntu:focal", 'name-extra': "(ubuntu focal)" },
8093
{ os, container: "debian:buster-slim", 'name-extra': "(debian buster)" },
8194
],
82-
available: available.has("linux/x86-64"),
95+
available,
8396
}
8497
}
8598
default:
@@ -90,7 +103,7 @@ const rv = `os=${JSON.stringify(output.os)}\n` +
90103
`build-os=${JSON.stringify(output.buildOs)}\n` +
91104
`container=${JSON.stringify(output.container)}\n` +
92105
`test-matrix=${JSON.stringify(output.testMatrix)}\n` +
93-
`available=${JSON.stringify(output.available)}\n`
106+
`available=${output.available}\n`
94107

95108
Deno.stdout.write(new TextEncoder().encode(rv))
96109

@@ -99,20 +112,6 @@ if (Deno.env.get("GITHUB_OUTPUT")) {
99112
await Deno.writeTextFile(envFile, rv, { append: true})
100113
}
101114

102-
async function getAvailability(packages: PackageRequirement[] | undefined): Promise<Set<string>> {
103-
const pantry = usePantry()
104-
let available = new Set<string>(["darwin/x86-64", "darwin/aarch64", "linux/x86-64", "linux/aarch64"])
105-
106-
if (!packages) return available
107-
108-
for (const pkg of packages) {
109-
const a = await pantry.getPlatforms(pkg)
110-
available = new Set(a.filter(x => available.has(x)))
111-
}
112-
113-
return available
114-
}
115-
116115
// Leaving this in case we need to switch back to GHA runners
117116

118117
// function sizedUbuntu(packages: (Package | PackageRequirement)[]): string {

0 commit comments

Comments
 (0)