Skip to content

Commit

Permalink
Add GHA docker build caching support
Browse files Browse the repository at this point in the history
  • Loading branch information
mnixry committed Feb 3, 2024
1 parent 37da593 commit d3baac7
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,25 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: docker/setup-qemu-action@v2

- uses: docker/setup-buildx-action@v2

- uses: pnpm/action-setup@v2
with:
version: 8

- uses: actions/setup-node@v4
with:
node-version: 18
node-version: 20
cache: pnpm

- name: Install dependencies
run: pnpm install

- name: Build
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: pnpm build

- name: Dry run publish
Expand All @@ -33,4 +39,4 @@ jobs:
- uses: actions/upload-artifact@v4
with:
name: dists
path: ./**/dist/**/*
path: ./**/dist/*
26 changes: 26 additions & 0 deletions packages/binutils/build/dist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const { spawn } = require("child_process");

if (typeof require !== "undefined" && require.main === module) {
const extraArgs = process.argv.slice(2);
if (extraArgs.length > 0) {
console.log("Extra arguments:", extraArgs);
}
if (process.env["GITHUB_TOKEN"]) {
console.log("GITHUB_TOKEN is set, assuming CI environment");
extraArgs.push("--cache-to=type=gha,mode=max", "--cache-from=type=gha");
}
const ret = spawn("docker", [
"buildx",
"build",
"--progress=plain",
"--build-arg=BRANCH=binutils-2_41-branch",
`--output=${process.cwd()}/build`,
...extraArgs,
`${process.cwd()}/build`,
]);
ret.stdout.pipe(process.stdout);
ret.stderr.pipe(process.stderr);
ret.on("exit", (code) => {
process.exit(code ?? 0);
});
}
2 changes: 1 addition & 1 deletion packages/binutils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
],
"scripts": {
"build:wrapper": "tsup",
"build:wasm": "docker buildx build --progress=plain --build-arg BRANCH=binutils-2_41-branch --output ./build ./build",
"build:wasm": "node ./build/dist.js",
"build": "pnpm run build:wasm && pnpm run build:wrapper",
"prebuild": "rm -rf ./build/dist"
},
Expand Down
9 changes: 9 additions & 0 deletions packages/gas/build/dist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,22 @@ const supportedTargets = [
export type SupportedTarget = (typeof supportedTargets)[number];

if (typeof require !== "undefined" && require.main === module) {
const extraArgs = process.argv.slice(2);
if (extraArgs.length > 0) {
console.log("Extra arguments:", extraArgs);
}
if (process.env["GITHUB_TOKEN"]) {
console.log("GITHUB_TOKEN is set, assuming CI environment");
extraArgs.push("--cache-to=type=gha,mode=max", "--cache-from=type=gha");
}
const ret = spawn("docker", [
"buildx",
"build",
"--progress=plain",
"--build-arg=BRANCH=binutils-2_41-branch",
`--build-arg=TARGET=${supportedTargets.join(",")}`,
`--output=${process.cwd()}/build`,
...extraArgs,
`${process.cwd()}/build`,
]);
ret.stdout.pipe(process.stdout);
Expand Down

0 comments on commit d3baac7

Please sign in to comment.