2023-02-03 01:13:38 +03:00
|
|
|
#!/usr/bin/env tea
|
|
|
|
|
|
|
|
/*---
|
|
|
|
args:
|
|
|
|
- deno
|
|
|
|
- run
|
|
|
|
- --allow-read
|
|
|
|
- --allow-env
|
|
|
|
- --allow-write
|
|
|
|
---*/
|
|
|
|
|
2023-02-07 08:02:06 +03:00
|
|
|
import { panic } from "utils"
|
|
|
|
import { Package, PackageRequirement } from "types"
|
|
|
|
import * as ARGV from "./utils/args.ts"
|
2023-02-03 01:13:38 +03:00
|
|
|
|
2023-02-07 08:02:06 +03:00
|
|
|
const exceptions: { [project: string]: number } = {
|
|
|
|
"deno.land": 4,
|
|
|
|
"ziglang.org": 8,
|
|
|
|
}
|
|
|
|
|
|
|
|
const packages = await ARGV.toArray(ARGV.pkgs())
|
2023-02-05 02:49:21 +03:00
|
|
|
type Output = {
|
|
|
|
os: OS,
|
|
|
|
buildOs: OS,
|
|
|
|
container?: string,
|
|
|
|
testMatrix: { os: OS, container?: string }[]
|
|
|
|
cacheSet: string
|
|
|
|
}
|
|
|
|
|
|
|
|
type OS = string | string[]
|
|
|
|
|
2023-02-03 01:13:38 +03:00
|
|
|
const platform = Deno.env.get("PLATFORM") ?? panic("$PLATFORM not set")
|
|
|
|
|
2023-02-11 23:46:39 +03:00
|
|
|
|
|
|
|
const home = Deno.env.get("HOME")
|
|
|
|
|
2023-02-05 02:49:21 +03:00
|
|
|
const cacheSets = {
|
2023-02-11 23:46:39 +03:00
|
|
|
"darwin": `${home}/Library/Caches/deno/deps/https/`,
|
|
|
|
"linux": `${home}/.cache/deno/deps/https/`
|
2023-02-05 02:49:21 +03:00
|
|
|
}
|
2023-02-03 01:13:38 +03:00
|
|
|
|
2023-02-05 02:49:21 +03:00
|
|
|
const output: Output = (() => {
|
|
|
|
switch(platform) {
|
|
|
|
case "darwin+x86-64": {
|
2023-02-03 02:12:06 +03:00
|
|
|
// Using GHA resources for now, until we resolve network issues with our runners
|
2023-02-05 02:49:21 +03:00
|
|
|
// buildOs: ["self-hosted", "macOS", "X64"]
|
|
|
|
const os = "macos-11"
|
|
|
|
return {
|
|
|
|
os,
|
|
|
|
buildOs: os,
|
|
|
|
testMatrix: [{ os }],
|
|
|
|
cacheSet: cacheSets["darwin"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case "darwin+aarch64": {
|
|
|
|
const os = ["self-hosted", "macOS", "ARM64"]
|
|
|
|
return {
|
|
|
|
os,
|
|
|
|
buildOs: os,
|
|
|
|
testMatrix: [{ os }],
|
|
|
|
cacheSet: cacheSets["darwin"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case "linux+aarch64": {
|
|
|
|
const os = ["self-hosted", "linux", "ARM64"]
|
|
|
|
return {
|
|
|
|
os,
|
|
|
|
buildOs: os,
|
|
|
|
testMatrix: [{ os }],
|
|
|
|
cacheSet: cacheSets["linux"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case "linux+x86-64": {
|
2023-02-03 01:36:03 +03:00
|
|
|
// Using GHA resources for now, until we resolve network issues with our runners
|
2023-02-05 02:49:21 +03:00
|
|
|
// buildOs: ["self-hosted", "linux", "X64"]
|
|
|
|
// testMatrix.push({ os: buildOs, container: undefined })
|
|
|
|
const os = "ubuntu-latest"
|
|
|
|
const container = "ghcr.io/teaxyz/infuser:latest"
|
|
|
|
return { os,
|
2023-02-07 08:02:06 +03:00
|
|
|
buildOs: sizedUbuntu(packages),
|
2023-02-05 02:49:21 +03:00
|
|
|
container,
|
|
|
|
testMatrix: [
|
|
|
|
{ os },
|
|
|
|
{ os, container },
|
|
|
|
{ os, container: "debian:buster-slim" }
|
|
|
|
],
|
|
|
|
cacheSet: cacheSets["linux"]
|
|
|
|
}
|
|
|
|
}
|
2023-02-03 01:13:38 +03:00
|
|
|
default:
|
|
|
|
panic(`Invalid platform description: ${platform}`)
|
2023-02-05 02:49:21 +03:00
|
|
|
}})()
|
2023-02-03 01:13:38 +03:00
|
|
|
|
2023-02-05 02:49:21 +03:00
|
|
|
const rv = `os=${JSON.stringify(output.os)}\n` +
|
|
|
|
`build-os=${JSON.stringify(output.buildOs)}\n` +
|
|
|
|
`container=${JSON.stringify(output.container)}\n` +
|
|
|
|
`test-matrix=${JSON.stringify(output.testMatrix)}\n` +
|
|
|
|
`cache-set=${JSON.stringify(output.cacheSet)}\n`
|
2023-02-03 01:13:38 +03:00
|
|
|
|
2023-02-05 02:49:21 +03:00
|
|
|
Deno.stdout.write(new TextEncoder().encode(rv))
|
2023-02-03 01:13:38 +03:00
|
|
|
|
|
|
|
if (Deno.env.get("GITHUB_OUTPUT")) {
|
|
|
|
const envFile = Deno.env.get("GITHUB_OUTPUT")!
|
2023-02-05 02:49:21 +03:00
|
|
|
await Deno.writeTextFile(envFile, rv, { append: true})
|
2023-02-03 01:13:38 +03:00
|
|
|
}
|
2023-02-07 08:02:06 +03:00
|
|
|
|
|
|
|
function sizedUbuntu(packages: (Package | PackageRequirement)[]): string {
|
2023-02-07 21:00:18 +03:00
|
|
|
const size = Math.max(2, ...packages.map(p => exceptions[p.project] ?? 2))
|
2023-02-07 08:02:06 +03:00
|
|
|
|
|
|
|
if (size == 2) {
|
|
|
|
return "ubuntu-latest"
|
|
|
|
} else if ([4, 8, 16].includes(size)) {
|
|
|
|
return `ubuntu-latest-${size}-cores`
|
|
|
|
} else {
|
|
|
|
panic(`Invalid size: ${size}`)
|
|
|
|
}
|
|
|
|
}
|