From 2b483d5ce75ca9066da716916f8f11f90ce70f90 Mon Sep 17 00:00:00 2001 From: Joshua Gilman Date: Wed, 25 Oct 2023 10:37:19 -0700 Subject: [PATCH] refactor: workflow improvememts (#56) * adds package target and renames integrate to test * reorganizes Earthfiles * consolidates jobs into single reusable workflow --- .github/workflows/ci.yml | 131 +++++++++++++++++++++++++++++ .github/workflows/dogfood.yml | 47 +---------- .github/workflows/publish.yml | 2 +- .github/workflows/release.yml | 4 +- .github/workflows/run.yml | 2 +- actions/configure-runner/Earthfile | 17 ++-- actions/discover/Earthfile | 17 ++-- actions/install/Earthfile | 17 ++-- actions/merge/Earthfile | 17 ++-- actions/push/Earthfile | 17 ++-- actions/run/Earthfile | 17 ++-- cli/Earthfile | 27 +++--- 12 files changed, 214 insertions(+), 101 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..46ad52212 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,131 @@ +on: + workflow_call: + inputs: + aws_ecr_registry: + description: | + The AWS ECR registry that will be used to publish images + required: true + type: string + aws_role_arn: + description: | + The ARN of the AWS role that will be assumed by the workflow. Only + required when configuring a remote Earthly runner or AWS ECR. + required: false + type: string + aws_region: + description: | + The AWS region that will be used by the workflow. Only required when + configuring a remote Earthly runner or AWS ECR. + required: false + type: string + ci_cli_version: + description: | + The version of the CI CLI to use. + required: false + type: string + default: latest + earthly_version: + description: The version of Earthly to use. + required: false + type: string + default: latest + force_artifact: + description: | + When set to true, the workflow will always produce a release artifact + even when the current commit is not tagged. + required: false + type: boolean + default: false + tags: + description: | + A line separated list of additional tags that will be applied to + published images. + required: false + type: string + secrets: + earthly_runner_address: + description: | + The address of the Earthly runner that will be used to build the + Earthly files. + required: false + earthly_runner_secret: + description: | + The ID of the AWS secret holding Earthly remote runner credentials. + This secret must contain the runner address and the necessary TLS + certificates required to authenticate with it. If omitted, a remote + Earthly runner will not be configured. + required: false + +jobs: + check: + uses: ./.github/workflows/run.yml + with: + aws_role_arn: ${{ inputs.aws_role_arn }} + aws_region: ${{ inputs.aws_region }} + ci_cli_version: ${{ inputs.ci_cli_version }} + earthly_version: ${{ inputs.earthly_version }} + target: check + secrets: + earthly_runner_address: ${{ secrets.earthly_runner_address }} + earthly_runner_secret: ${{ secrets.earthly_runner_secret }} + build: + uses: ./.github/workflows/run.yml + needs: [check] + with: + aws_role_arn: ${{ inputs.aws_role_arn }} + aws_region: ${{ inputs.aws_region }} + ci_cli_version: ${{ inputs.ci_cli_version }} + earthly_version: ${{ inputs.earthly_version }} + target: check + secrets: + earthly_runner_address: ${{ secrets.earthly_runner_address }} + earthly_runner_secret: ${{ secrets.earthly_runner_secret }} + package: + uses: ./.github/workflows/run.yml + needs: [build, check] + with: + aws_role_arn: ${{ inputs.aws_role_arn }} + aws_region: ${{ inputs.aws_region }} + ci_cli_version: ${{ inputs.ci_cli_version }} + earthly_version: ${{ inputs.earthly_version }} + target: check + secrets: + earthly_runner_address: ${{ secrets.earthly_runner_address }} + earthly_runner_secret: ${{ secrets.earthly_runner_secret }} + test: + uses: ./.github/workflows/run.yml + needs: [build, check, package] + with: + aws_role_arn: ${{ inputs.aws_role_arn }} + aws_region: ${{ inputs.aws_region }} + ci_cli_version: ${{ inputs.ci_cli_version }} + earthly_version: ${{ inputs.earthly_version }} + target: check + secrets: + earthly_runner_address: ${{ secrets.earthly_runner_address }} + earthly_runner_secret: ${{ secrets.earthly_runner_secret }} + release: + uses: ./.github/workflows/release.yml + needs: [build, check, package, test] + with: + aws_role_arn: ${{ inputs.aws_role_arn }} + aws_region: ${{ inputs.aws_region }} + ci_cli_version: ${{ inputs.ci_cli_version }} + earthly_version: ${{ inputs.earthly_version }} + force_artifact: ${{ inputs.force_artifact }} + secrets: + earthly_runner_address: ${{ secrets.earthly_runner_address }} + earthly_runner_secret: ${{ secrets.earthly_runner_secret }} + publish: + uses: ./.github/workflows/publish.yml + needs: [build, check, package, test] + with: + aws_ecr_registry: ${{ inputs.aws_ecr_registry }} + aws_role_arn: ${{ inputs.aws_role_arn }} + aws_region: ${{ inputs.aws_region }} + ci_cli_version: ${{ inputs.ci_cli_version }} + earthly_version: ${{ inputs.earthly_version }} + tags: ${{ inputs.tags }} + secrets: + earthly_runner_address: ${{ secrets.earthly_runner_address }} + earthly_runner_secret: ${{ secrets.earthly_runner_secret }} \ No newline at end of file diff --git a/.github/workflows/dogfood.yml b/.github/workflows/dogfood.yml index a9ba6a35e..e9449d697 100644 --- a/.github/workflows/dogfood.yml +++ b/.github/workflows/dogfood.yml @@ -9,51 +9,8 @@ permissions: packages: write jobs: - check: - uses: ./.github/workflows/run.yml - with: - aws_role_arn: arn:aws:iam::332405224602:role/ci - aws_region: eu-central-1 - ci_cli_version: 1.3.1 - target: check - secrets: - earthly_runner_address: ${{ secrets.EARTHLY_SATELLITE_ADDRESS }} - earthly_runner_secret: ${{ secrets.EARTHLY_RUNNER_SECRET }} - build: - uses: ./.github/workflows/run.yml - needs: [check] - with: - aws_role_arn: arn:aws:iam::332405224602:role/ci - aws_region: eu-central-1 - ci_cli_version: 1.3.1 - target: build - secrets: - earthly_runner_address: ${{ secrets.EARTHLY_SATELLITE_ADDRESS }} - earthly_runner_secret: ${{ secrets.EARTHLY_RUNNER_SECRET }} - integrate: - uses: ./.github/workflows/run.yml - needs: [build, check] - with: - aws_role_arn: arn:aws:iam::332405224602:role/ci - aws_region: eu-central-1 - ci_cli_version: 1.3.1 - target: integrate - secrets: - earthly_runner_address: ${{ secrets.EARTHLY_SATELLITE_ADDRESS }} - earthly_runner_secret: ${{ secrets.EARTHLY_RUNNER_SECRET }} - release: - uses: ./.github/workflows/release.yml - needs: [build, check, integrate] - with: - aws_role_arn: arn:aws:iam::332405224602:role/ci - aws_region: eu-central-1 - ci_cli_version: 1.3.1 - secrets: - earthly_runner_address: ${{ secrets.EARTHLY_SATELLITE_ADDRESS }} - earthly_runner_secret: ${{ secrets.EARTHLY_RUNNER_SECRET }} - publish: - uses: ./.github/workflows/publish.yml - needs: [build, check, integrate] + ci: + uses: ./.github/workflows/ci.yml with: aws_ecr_registry: 332405224602.dkr.ecr.eu-central-1.amazonaws.com aws_role_arn: arn:aws:iam::332405224602:role/ci diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index b3fb2cae0..f0db73125 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -85,7 +85,7 @@ jobs: echo "json=$output" >> $GITHUB_OUTPUT fi - build: + run: runs-on: ubuntu-latest needs: [discover] if: needs.discover.outputs.json != '[]' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 832451516..2fdfbf6b1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -82,7 +82,7 @@ jobs: echo "json=$output" >> $GITHUB_OUTPUT fi - build: + run: runs-on: ubuntu-latest needs: [discover] if: needs.discover.outputs.json != '[]' @@ -131,7 +131,7 @@ jobs: release: runs-on: ubuntu-latest - needs: [build] + needs: [run] if: startsWith(github.ref, 'refs/tags/') steps: - name: Download artifacts diff --git a/.github/workflows/run.yml b/.github/workflows/run.yml index 9e4efd12d..52ba7faaa 100644 --- a/.github/workflows/run.yml +++ b/.github/workflows/run.yml @@ -72,7 +72,7 @@ jobs: echo "json=$output" >> $GITHUB_OUTPUT fi - build: + run: runs-on: ubuntu-latest needs: [discover] if: needs.discover.outputs.json != '[]' diff --git a/actions/configure-runner/Earthfile b/actions/configure-runner/Earthfile index edb85059d..d48eef04e 100644 --- a/actions/configure-runner/Earthfile +++ b/actions/configure-runner/Earthfile @@ -13,20 +13,25 @@ src: COPY --dir src src COPY .eslintrc.yml tsconfig.json . -package: +build: FROM +src RUN npm run package SAVE ARTIFACT dist dist AS LOCAL dist -check: - FROM +package +test: + FROM +build - RUN npm run format:check - RUN npm run lint RUN npm test + # Verify the package is not out of date COPY --dir dist dist_old RUN npm run package - RUN diff -r dist_old dist \ No newline at end of file + RUN diff -r dist_old dist + +check: + FROM +src + + RUN npm run format:check + RUN npm run lint \ No newline at end of file diff --git a/actions/discover/Earthfile b/actions/discover/Earthfile index edb85059d..d48eef04e 100644 --- a/actions/discover/Earthfile +++ b/actions/discover/Earthfile @@ -13,20 +13,25 @@ src: COPY --dir src src COPY .eslintrc.yml tsconfig.json . -package: +build: FROM +src RUN npm run package SAVE ARTIFACT dist dist AS LOCAL dist -check: - FROM +package +test: + FROM +build - RUN npm run format:check - RUN npm run lint RUN npm test + # Verify the package is not out of date COPY --dir dist dist_old RUN npm run package - RUN diff -r dist_old dist \ No newline at end of file + RUN diff -r dist_old dist + +check: + FROM +src + + RUN npm run format:check + RUN npm run lint \ No newline at end of file diff --git a/actions/install/Earthfile b/actions/install/Earthfile index edb85059d..d48eef04e 100644 --- a/actions/install/Earthfile +++ b/actions/install/Earthfile @@ -13,20 +13,25 @@ src: COPY --dir src src COPY .eslintrc.yml tsconfig.json . -package: +build: FROM +src RUN npm run package SAVE ARTIFACT dist dist AS LOCAL dist -check: - FROM +package +test: + FROM +build - RUN npm run format:check - RUN npm run lint RUN npm test + # Verify the package is not out of date COPY --dir dist dist_old RUN npm run package - RUN diff -r dist_old dist \ No newline at end of file + RUN diff -r dist_old dist + +check: + FROM +src + + RUN npm run format:check + RUN npm run lint \ No newline at end of file diff --git a/actions/merge/Earthfile b/actions/merge/Earthfile index edb85059d..d48eef04e 100644 --- a/actions/merge/Earthfile +++ b/actions/merge/Earthfile @@ -13,20 +13,25 @@ src: COPY --dir src src COPY .eslintrc.yml tsconfig.json . -package: +build: FROM +src RUN npm run package SAVE ARTIFACT dist dist AS LOCAL dist -check: - FROM +package +test: + FROM +build - RUN npm run format:check - RUN npm run lint RUN npm test + # Verify the package is not out of date COPY --dir dist dist_old RUN npm run package - RUN diff -r dist_old dist \ No newline at end of file + RUN diff -r dist_old dist + +check: + FROM +src + + RUN npm run format:check + RUN npm run lint \ No newline at end of file diff --git a/actions/push/Earthfile b/actions/push/Earthfile index edb85059d..d48eef04e 100644 --- a/actions/push/Earthfile +++ b/actions/push/Earthfile @@ -13,20 +13,25 @@ src: COPY --dir src src COPY .eslintrc.yml tsconfig.json . -package: +build: FROM +src RUN npm run package SAVE ARTIFACT dist dist AS LOCAL dist -check: - FROM +package +test: + FROM +build - RUN npm run format:check - RUN npm run lint RUN npm test + # Verify the package is not out of date COPY --dir dist dist_old RUN npm run package - RUN diff -r dist_old dist \ No newline at end of file + RUN diff -r dist_old dist + +check: + FROM +src + + RUN npm run format:check + RUN npm run lint \ No newline at end of file diff --git a/actions/run/Earthfile b/actions/run/Earthfile index edb85059d..d48eef04e 100644 --- a/actions/run/Earthfile +++ b/actions/run/Earthfile @@ -13,20 +13,25 @@ src: COPY --dir src src COPY .eslintrc.yml tsconfig.json . -package: +build: FROM +src RUN npm run package SAVE ARTIFACT dist dist AS LOCAL dist -check: - FROM +package +test: + FROM +build - RUN npm run format:check - RUN npm run lint RUN npm test + # Verify the package is not out of date COPY --dir dist dist_old RUN npm run package - RUN diff -r dist_old dist \ No newline at end of file + RUN diff -r dist_old dist + +check: + FROM +src + + RUN npm run format:check + RUN npm run lint \ No newline at end of file diff --git a/cli/Earthfile b/cli/Earthfile index ac29e3bfb..c297cd46b 100644 --- a/cli/Earthfile +++ b/cli/Earthfile @@ -20,10 +20,11 @@ src: COPY --dir cmd pkg . -test: +check: FROM +src - RUN ginkgo ./... + BUILD +fmt + BUILD +lint build: FROM +src @@ -33,20 +34,10 @@ build: SAVE ARTIFACT bin/ci ci -docker: - FROM debian:bookworm-slim - WORKDIR /workspace - - COPY +build/ci /usr/local/bin/ci - - ENTRYPOINT ["/usr/local/bin/ci"] - -check: - FROM +deps +test: + FROM +build - BUILD +fmt - BUILD +lint - BUILD +test + RUN ginkgo ./... release: FROM +build @@ -54,7 +45,11 @@ release: SAVE ARTIFACT bin/ci ci publish: - FROM +docker + FROM debian:bookworm-slim + WORKDIR /workspace ARG tag=latest + COPY +build/ci /usr/local/bin/ci + + ENTRYPOINT ["/usr/local/bin/ci"] SAVE IMAGE --push ci-cli:${tag} \ No newline at end of file