Skip to content

Commit

Permalink
Initial update to CI
Browse files Browse the repository at this point in the history
We wanted to try and speed up the CI tasks for the Rails Template.

This work introduces the same approach we took to save time on the DfE
Complete project.

We use Docker supplied actions to build the image and cache the layers
to the Github actions cache.

Subsequent jobs are set to use the layers from the cache which, in most
cases, gives us a nice speed boost.

We've split the jobs so they can be run in parallel, as we know the
image is the same for each job they all use the strategy.

We've kept the Shellcheck task separate as this code is not strictly
speaking the application code, so doesn't really need to be inside the
image.
  • Loading branch information
mec committed Nov 12, 2024
1 parent 8375a51 commit a5efd7a
Showing 1 changed file with 121 additions and 8 deletions.
129 changes: 121 additions & 8 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# TODO: Enable GitHub Actions on the repository to test all pull requests
# https://github.com/<org>/<repo>/actions
name: CI Checks

on:
pull_request:
push:
Expand All @@ -8,18 +10,129 @@ on:
- develop

jobs:
test:
build-and-cache:
name: Build and cache image
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
-
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
tags: app_test:latest
cache-from: type=gha
cache-to: type=gha,mode=min

env:
RAILS_ENV: test
lint-and-format:
name: Linting and format application
runs-on: ubuntu-latest
needs: build-and-cache
steps:
-
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: Run linters and formatters
run: |
docker run --rm app_test:latest /bin/bash -c "bundle exec standardrb -f simple && \
yarn run lint:js && \
yarn run lint:css && \
yarn run lint:format"
static-analysis:
name: Static analysis
runs-on: ubuntu-latest
needs: build-and-cache
steps:
- name: Check out code
-
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: Run Brakeman
run: |
docker run --rm app_test:latest /bin/bash -c "bundle exec brakeman -o /dev/stdout"
- name: Build
run: script/ci/cibuild
specs:
name: Specs and coverage
runs-on: ubuntu-latest
needs: build-and-cache
steps:
-
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: Run RSpec and Simplecov
run: |
docker compose -p complete-app -f docker-compose.ci.yml \
run --name app_test test /bin/bash -c "bin/rails spec"
-
name: Shutdown containers
run: docker compose -p app_test down && docker compose -p app_test rm

- name: Test
run: script/ci/test
shellcheck:
name: Linting scripts
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Run Shellceck
run: |
for file in $(git ls-files script/*)
do shellcheck -x "$file"
done

0 comments on commit a5efd7a

Please sign in to comment.