From d31559ab8d3fc7f7b44094ab507d9252bb222b9c Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Wed, 17 Jan 2024 15:16:37 -0800 Subject: [PATCH] ci: separate test-proposals --- .github/workflows/ci.yml | 28 +++++++++++++------ packages/synthetic-chain/cli.ts | 19 ++++++++----- packages/synthetic-chain/src/cli/build.ts | 2 +- .../synthetic-chain/src/cli/dockerfileGen.ts | 7 ++++- 4 files changed, 39 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5cc7469b..9c54459c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,8 +36,7 @@ jobs: fi echo "platforms=$platforms" >> $GITHUB_OUTPUT - # see https://docs.docker.com/build/ci/github-actions/test-before-push/ - test-proposals: + use-proposals: needs: [platforms] # UNTIL https://github.com/Agoric/agoric-3-proposals/issues/2 timeout-minutes: 120 @@ -127,11 +126,6 @@ jobs: # If we pushed from PRs, each one would overwrite (e.g. use-upgrade-8) # push: ${{ github.event_name != 'pull_request' }} - # TODO run tests in another (non-matrixed) job once "use" images are available in another worker - - name: run proposal tests - if: ${{ matrix.platform == env.X86_PLATFORM }} - run: node_modules/.bin/synthetic-chain test - # XXX this should be instant for the local platform because all the stages # were already built in the steps above but it's re-building the last # stage. This is deemed good enough for now. see @@ -147,10 +141,28 @@ jobs: tags: ${{ steps.docker-tags.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + # see https://docs.docker.com/build/ci/github-actions/test-before-push/ + test-proposals: + needs: use-proposals + # only test in default platform + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # The .ts scripts depend upon this + - run: tsx --version || npm install --global tsx + # Enable corepack for packageManager config + - run: corepack enable || sudo corepack enable + - run: yarn install + + - name: run proposal tests + run: node_modules/.bin/synthetic-chain test + # Merge the default image from each platform into one multi-arch image, # then publish that multiarch image. docker-publish-multiarch: - needs: [test-proposals, platforms] + needs: [use-proposals, platforms] runs-on: ubuntu-latest permissions: contents: read diff --git a/packages/synthetic-chain/cli.ts b/packages/synthetic-chain/cli.ts index 2a1733d4..db8c52b9 100755 --- a/packages/synthetic-chain/cli.ts +++ b/packages/synthetic-chain/cli.ts @@ -47,15 +47,19 @@ test [--debug] - build the "test" images and run them doctor - diagnostics and quick fixes `; -const prepareDockerBuild = () => { - writeBakefileProposals(allProposals); - writeDockerfile(allProposals, buildConfig.fromTag); - // files the Docker builds depend on - buildProposalSubmissions(proposals); +/** + * Put into places files that building depends upon. + */ +const prepareDockerBuild = (buildSubmissions?: boolean) => { execSync( // XXX very brittle 'cp -r node_modules/@agoric/synthetic-chain/upgrade-test-scripts .', ); + writeDockerfile(allProposals, buildConfig.fromTag); + writeBakefileProposals(allProposals); + if (buildSubmissions) { + buildProposalSubmissions(proposals); + } }; switch (cmd) { @@ -69,8 +73,9 @@ switch (cmd) { break; } case 'test': - // always rebuild all test images. Keeps it simple and these are fast - // as long as the "use" stages are cached because they don't execute anything themselves. + prepareDockerBuild(); + // Always rebuild all test images to keep it simple. With the "use" stages + // cached, these are fast as long because the layers don't execute anything. bakeImages('test', values.dry); if (values.debug) { debugTestImage(matchOneProposal(proposals, match!)); diff --git a/packages/synthetic-chain/src/cli/build.ts b/packages/synthetic-chain/src/cli/build.ts index 1a2dae68..2435efeb 100755 --- a/packages/synthetic-chain/src/cli/build.ts +++ b/packages/synthetic-chain/src/cli/build.ts @@ -1,7 +1,7 @@ import { execSync } from 'node:child_process'; import fs from 'node:fs'; import path from 'node:path'; -import { ProposalInfo, imageNameForProposal } from './proposals.js'; +import { ProposalInfo } from './proposals.js'; export type AgoricSyntheticChainConfig = { /** diff --git a/packages/synthetic-chain/src/cli/dockerfileGen.ts b/packages/synthetic-chain/src/cli/dockerfileGen.ts index 35015c22..133d254b 100755 --- a/packages/synthetic-chain/src/cli/dockerfileGen.ts +++ b/packages/synthetic-chain/src/cli/dockerfileGen.ts @@ -8,6 +8,7 @@ import { type ProposalInfo, type SoftwareUpgradeProposal, encodeUpgradeInfo, + imageNameForProposal, } from './proposals.js'; /** @@ -150,9 +151,13 @@ RUN ./run_use.sh ${proposalIdentifier}:${proposalName} * Needs to be an image to have access to the SwingSet db. run it with `docker run --rm` to not make the container ephemeral. */ TEST({ proposalName, proposalIdentifier }: ProposalInfo) { + // Assumes the 'use' image is built and tagged. + // This isn't necessary for a multi-stage build, but it allows CI + // to split the "test" image building into a separate runner. + const useImage = imageNameForProposal({ proposalName }, 'use').name; return ` # TEST ${proposalName} -FROM use-${proposalName} as test-${proposalName} +FROM ${useImage} as test-${proposalName} WORKDIR /usr/src/upgrade-test-scripts