Skip to content

Commit

Permalink
DRY up cache loading in CI workflow
Browse files Browse the repository at this point in the history
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: actions/runner#1182
  • Loading branch information
yndajas committed Nov 14, 2024
1 parent 19006d0 commit 29b3eff
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 42 deletions.
20 changes: 20 additions & 0 deletions .github/actions/continuous-integration/load-cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Load cache
description: Loads the cached image in a post-cache continuous integration step
runs:
using: "composite"
steps:
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Load 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
48 changes: 6 additions & 42 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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: |
Expand All @@ -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: |
Expand Down

0 comments on commit 29b3eff

Please sign in to comment.