1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-29 16:30:56 -05:00
denoland-deno/tools/gen_workflow_yml.ts
2021-03-05 18:39:39 +01:00

133 lines
3.1 KiB
TypeScript

#!/usr/bin/env -S deno run --unstable --allow-write --allow-read --allow-run
const slowRunners = {
"linux": "ubuntu-18.04",
"macos": "macos-10.15",
"windows": "windows-2019",
};
const fastRunners = {
"linux":
"${{ github.repository == 'denoland/deno' && 'ubuntu-latest-xl' || 'ubuntu-18.04' }}",
"macos": "macos-10.15",
"windows": "windows-2019",
};
const env = {
"CARGO_INCREMENTAL": "0",
"RUST_BACKTRACE": "full",
"CARGO_TERM_COLOR": "always",
};
const platforms = ["linux", "macos", "windows"] as const;
const kinds = ["release", "debug"] as const;
const chechout = [
{
name: "Configure git",
run: "git config --global core.symlinks true",
},
{
name: "Checkout repository",
uses: "actions/checkout@v2",
with: {
"fetch-depth": 5,
submodules: true,
},
},
];
function buildCache(os: string, kind: string) {
return {
name: "Build cache",
uses: "actions/cache@v2",
with: {
path: [
"~/.cargo/registry",
"~/.cargo/git",
".cargo_home",
"target/*/.*",
"target/*/build",
"target/*/deps",
].join("\n"),
key: `${os}-${kind}-\${{ hashFiles('Cargo.lock') }}`,
"restore-keys": `${os}-${kind}-`,
},
};
}
const setupRust = {
name: "Setup Rust",
uses: "actions-rs/toolchain@v1",
with: {
default: true,
override: true,
toolchain: "1.50.0",
},
};
function generateBuildJobs(): Record<string, unknown> {
const jobs: Record<string, unknown> = {};
for (const os of platforms) {
for (const kind of kinds) {
if (os != "linux" && kind == "debug") continue;
jobs[`build_${os}_${kind}`] = {
name: `build / ${os} / ${kind}`,
"runs-on": fastRunners[os],
"timeout-minutes": 60,
env,
steps: [
...chechout,
{
name: "Configure canary",
if: "!startsWith(github.ref, 'refs/tags/')",
shell: "bash",
run: "echo 'DENO_CANARY=true' >> $GITHUB_ENV",
},
buildCache(os, kind),
setupRust,
{
name: `Build ${kind}`,
uses: "actions-rs/cargo@v1",
with: {
"use-cross": false,
command: "build",
args: `--locked --all-targets ${
kind == "release" ? "--release" : ""
}`,
},
},
{
name: "Upload build artifact",
uses: "actions/upload-artifact@v2",
with: {
name: `build-${os}-${kind}`,
path: [
`target/${kind}/deno${os == "windows" ? ".exe" : ""}`,
`target/${kind}/denort${os == "windows" ? ".exe" : ""}`,
].join("\n"),
},
},
],
};
}
}
return jobs;
}
const ci = {
name: "ci",
"runs-on": ["push", "pull_request"],
jobs: {
...generateBuildJobs(),
},
};
const str = JSON.stringify(ci, undefined, 2);
await Deno.writeTextFile(
"./.github/workflows/ci.yml",
`# THIS FILE IS AUTOGENERATED USING ./tools/get_workflow.yml\n${str}`,
);