1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00
denoland-deno/tools/gen_workflow_yml.ts

274 lines
7.3 KiB
TypeScript
Raw Normal View History

2021-03-05 12:39:39 -05:00
#!/usr/bin/env -S deno run --unstable --allow-write --allow-read --allow-run
2021-03-05 18:15:20 -05:00
const RUST_VERSION = "1.50.0";
const DENO_VERSION = "v1.7.2";
2021-03-05 12:39:39 -05:00
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",
};
2021-03-05 13:09:22 -05:00
const targets = {
"linux": "x86_64-unknown-linux-gnu",
"macos": "x86_64-apple-darwin",
"windows": "denort-x86_64-pc-windows-msvc",
};
2021-03-05 12:39:39 -05:00
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,
2021-03-05 18:15:20 -05:00
toolchain: RUST_VERSION,
2021-03-05 12:39:39 -05:00
},
};
2021-03-05 18:15:20 -05:00
const setupDeno = {
name: "Setup Deno",
run: [
`curl -fsSL https://deno.land/x/install/install.sh | sh -s ${DENO_VERSION}`,
`echo "$HOME/.deno/bin" >> $\${{ runner.os == 'Windows' && 'env:' || '' }}GITHUB_PATH`,
].join("\n"),
};
2021-03-05 12:39:39 -05:00
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;
2021-03-05 17:30:33 -05:00
const zipSourceStep = {
name: "Package sourcecode",
2021-03-05 17:41:45 -05:00
run: [
"mkdir -p target/release",
2021-03-05 17:30:33 -05:00
`tar --exclude=.cargo_home --exclude=".git*" --exclude=target --exclude=third_party/prebuilt -czf target/release/deno_src.tar.gz -C .. deno`,
2021-03-05 17:43:39 -05:00
].join("\n"),
2021-03-05 17:30:33 -05:00
};
2021-03-05 13:09:22 -05:00
const packageStep = {
name: "Package",
"working-directory": "target/release",
run: (os == "windows"
? [
"Compress-Archive -CompressionLevel Optimal -Force -Path deno.exe -DestinationPath deno-x86_64-pc-windows-msvc.zip",
"Compress-Archive -CompressionLevel Optimal -Force -Path denort.exe -DestinationPath denort-x86_64-pc-windows-msvc.zip",
]
: [
`zip -r deno-${targets[os]}.zip deno`,
`zip -r denort-${targets[os]}.zip denort`,
2021-03-05 17:30:33 -05:00
...(os == "linux" ? ["./deno types > lib.deno.d.ts"] : []),
2021-03-05 13:09:22 -05:00
]).join("\n"),
};
const uploadPackageStep = {
name: "Upload package artifacts",
uses: "actions/upload-artifact@v2",
with: {
name: "package",
path: [
"target/release/deno-x86_64-unknown-linux-gnu.zip",
"target/release/deno-x86_64-pc-windows-msvc.zip",
"target/release/deno-x86_64-apple-darwin.zip",
"target/release/denort-x86_64-unknown-linux-gnu.zip",
"target/release/denort-x86_64-pc-windows-msvc.zip",
"target/release/denort-x86_64-apple-darwin.zip",
"target/release/deno_src.tar.gz",
"target/release/lib.deno.d.ts",
].join("\n"),
"retention-days": 7,
},
};
2021-03-05 12:39:39 -05:00
jobs[`build_${os}_${kind}`] = {
name: `build / ${os} / ${kind}`,
"runs-on": fastRunners[os],
"timeout-minutes": 60,
env,
steps: [
...chechout,
2021-03-05 17:41:45 -05:00
...(kind == "release" && os == "linux" ? [zipSourceStep] : []),
2021-03-05 12:39:39 -05:00
{
name: "Configure canary",
if: "!startsWith(github.ref, 'refs/tags/')",
shell: "bash",
run: "echo 'DENO_CANARY=true' >> $GITHUB_ENV",
},
buildCache(os, kind),
setupRust,
{
2021-03-05 18:15:20 -05:00
name: "Log versions",
run: [
"rustc --version",
"cargo --version",
].join("\n"),
},
{
name: `Build (${kind})`,
2021-03-05 12:39:39 -05:00
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"),
},
},
2021-03-05 13:09:22 -05:00
...(kind == "release" ? [packageStep, uploadPackageStep] : []),
2021-03-05 12:39:39 -05:00
],
};
}
}
return jobs;
}
2021-03-05 18:15:20 -05:00
function downloadBuildCache(os: string, kind: string): unknown[] {
return [
{
name: "Download build artifacts",
uses: "actions/download-artifact@v2",
with: { name: `build-${os}-${kind}` },
},
...(os != "windows"
? [
{
name: "Make build artifacts executable",
run: [
`chmod +x target/${kind}/deno${os == "windows" ? ".exe" : ""}`,
`chmod +x target/${kind}/denort${os == "windows" ? ".exe" : ""}`,
].join("\n"),
},
]
: []),
];
}
2021-03-05 18:03:50 -05:00
function generateTestJobs(): 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[`test_${os}_${kind}`] = {
name: `test / ${os} / ${kind}`,
"runs-on": slowRunners[os],
"timeout-minutes": 60,
2021-03-05 18:15:20 -05:00
step: [`build_${os}_${kind}`],
2021-03-05 18:03:50 -05:00
env,
steps: [
...chechout,
2021-03-05 18:15:20 -05:00
setupRust,
setupDeno,
{
name: "Log versions",
run: [
"rustc --version",
"cargo --version",
"deno --version",
].join("\n"),
},
buildCache(os, kind),
...downloadBuildCache(os, kind),
...(kind == "release"
? [
{
name: "Test (release)",
run: "cargo test --release --locked --all-targets",
},
]
: [
{
name: "Test (debug)",
run: [
"cargo test --locked --doc",
"cargo test --locked --all-targets",
].join("\n"),
},
]),
2021-03-05 18:03:50 -05:00
],
};
}
}
return jobs;
}
2021-03-05 12:39:39 -05:00
const ci = {
name: "ci",
2021-03-05 12:47:12 -05:00
// FIXME
on: [/*"push",*/ "pull_request"],
2021-03-05 12:39:39 -05:00
jobs: {
...generateBuildJobs(),
2021-03-05 18:03:50 -05:00
...generateTestJobs(),
2021-03-05 12:39:39 -05:00
},
};
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}`,
);