From 56915a20d15b486c5e229e0c6861e247fe201e29 Mon Sep 17 00:00:00 2001 From: Ynda Jas Date: Thu, 14 Nov 2024 12:13:44 +0000 Subject: [PATCH] DRY up cache loading in CI workflow This adds a composite action to run the two cache-loading steps that are reused across three of the jobs in the continuous integration workflow. The second of these steps is a little long and detailed, and differs slightly but meaningfully from a similar step in the build cache job, so it might be useful to DRY this up. This also allows us to see the meat of the post-cache jobs a little easier in the continuous integration workflow The `actions/checkout@v4` step is needed in each job in order to load our action (and presumably also the external ones used in the composite action) It would be quite nice to use a YAML anchor or alias to do this kind of reuse, but these are currently unsupported in GitHub Actions. They might be on the way soon, so watch this space: https://github.com/actions/runner/issues/1182 --- .../load-cache/action.yml | 19 ++++++++ .github/workflows/continuous-integration.yml | 48 +++---------------- 2 files changed, 25 insertions(+), 42 deletions(-) create mode 100644 .github/actions/continuous-integration/load-cache/action.yml diff --git a/.github/actions/continuous-integration/load-cache/action.yml b/.github/actions/continuous-integration/load-cache/action.yml new file mode 100644 index 00000000..f1b1085d --- /dev/null +++ b/.github/actions/continuous-integration/load-cache/action.yml @@ -0,0 +1,19 @@ +name: Build and cache image +runs: + using: "composite" + steps: + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - + name: Build and cache image + uses: docker/build-push-action@v6 + with: + context: . + file: ./Dockerfile + build-args: | + RAILS_ENV=test + push: false + load: true + tags: app_test:latest + cache-from: type=gha diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 358d8e8f..8ecc7fae 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -41,20 +41,8 @@ jobs: name: Checkout uses: actions/checkout@v4 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Build and cache - uses: docker/build-push-action@v6 - with: - context: . - file: ./Dockerfile - build-args: | - RAILS_ENV=test - push: false - load: true - tags: app_test:latest - cache-from: type=gha + name: Load cache + uses: ./.github/actions/continuous-integration/load-cache - name: Run linters and formatters run: | @@ -72,20 +60,8 @@ jobs: name: Checkout uses: actions/checkout@v4 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Build and cache - uses: docker/build-push-action@v6 - with: - context: . - file: ./Dockerfile - build-args: | - RAILS_ENV=test - push: false - load: true - tags: app_test:latest - cache-from: type=gha + name: Load cache + uses: ./.github/actions/continuous-integration/load-cache - name: Run Brakeman run: | @@ -100,20 +76,8 @@ jobs: name: Checkout uses: actions/checkout@v4 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Build and cache - uses: docker/build-push-action@v6 - with: - context: . - file: ./Dockerfile - build-args: | - RAILS_ENV=test - push: false - load: true - tags: app_test:latest - cache-from: type=gha + name: Load cache + uses: ./.github/actions/continuous-integration/load-cache - name: Run RSpec and Simplecov run: |