Skip to content

Commit

Permalink
ci: include scope in GHA cache
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Nov 6, 2023
1 parent 6bd39c6 commit a90b1e1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
uses: crazy-max/ghaction-github-runtime@v3

- name: build test images
run: ./buildTestImages.ts --buildOpts="--cache-from type=gha --cache-to type=gha,mode=max"
run: ./buildTestImages.ts

- name: run test images
run: ./runTestImages.ts
Expand Down
14 changes: 11 additions & 3 deletions buildTestImages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,36 @@ import { refreshDockerfile } from './makeDockerfile';
refreshDockerfile();

const options = {
buildOpts: { type: 'string' },
match: { short: 'm', type: 'string' },
dry: { type: 'boolean' },
} as const;
const { values } = parseArgs({ options });

const { buildOpts, match, dry } = values;
const { match, dry } = values;

const allProposals = readProposals();

const proposals = match
? allProposals.filter(p => p.proposalName.includes(match))
: allProposals;

function buildOptsFor(name: string) {
// use GitHub Actions Cache if enabled https://docs.docker.com/build/cache/backends/gha/
if (process.env.ACTIONS_RUNTIME_TOKEN) {
const refName = process.env.GITHUB_REF_NAME;
return `--cache-from type=gha,scope=${refName}-${name} --cache-to type=gha,mode=max,scope=${refName}-${name}`;
}
}

for (const proposal of proposals) {
if (!dry) {
console.log(`\nBuilding test image for proposal ${proposal.proposalName}`);
}
const { name, target } = imageNameForProposalTest(proposal);
const opts = buildOptsFor(name);
// 'load' to ensure the images are output to the Docker client. Seems to be necessary
// for the CI docker/build-push-action to re-use the cached stages.
const cmd = `docker buildx build ${buildOpts} --load --tag ${name} --target ${target} .`;
const cmd = `docker buildx build ${opts} --load --tag ${name} --target ${target} .`;
console.log(cmd);
if (!dry) {
execSync(cmd, { stdio: 'inherit' });
Expand Down

0 comments on commit a90b1e1

Please sign in to comment.