Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimise the CI pipeline for faster runs and earlier failures #1869

Merged
merged 8 commits into from
Mar 12, 2025
96 changes: 73 additions & 23 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
name: CI

# Enable Buildkit and let compose use it to speed up image building
env:
DOCKER_BUILDKIT: 1
COMPOSE_DOCKER_CLI_BUILD: 1

on:
pull_request:
branches: ["master", "main"]
Expand All @@ -17,7 +12,27 @@ on:
merge_group:

jobs:
linter:
runs-on: ubuntu-latest
steps:
- name: Checkout Code Repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/[email protected]
with:
python-version: "3.12"
cache: pip
cache-dependency-path: |
requirements/base.txt
requirements/local.txt
- name: Run pre-commit
uses: pre-commit/[email protected]
env:
SKIP: no-commit-to-branch,stylelint

build-scss:
needs: linter
runs-on: ubuntu-latest
steps:
- name: Checkout Code Repository
Expand All @@ -33,6 +48,7 @@ jobs:
run: npm run build

js-tests:
needs: linter
runs-on: ubuntu-latest
steps:
- name: Checkout Code Repository
Expand All @@ -47,27 +63,42 @@ jobs:
- name: Run tests
run: npm test

linter:
build-django:
needs: linter
runs-on: ubuntu-latest

steps:
- name: Checkout Code Repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/[email protected]
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Copy .env.example file
uses: canastro/copy-file-action@master
with:
python-version: "3.12"
cache: pip
cache-dependency-path: |
requirements/base.txt
requirements/local.txt
- name: Run pre-commit
uses: pre-commit/[email protected]
env:
SKIP: no-commit-to-branch,stylelint
source: ".env.example"
target: ".env"

- name: Build the Stack
uses: docker/bake-action@v6
with:
targets: django
load: true
set: |
*.cache-from=type=gha
*.cache-to=type=gha,mode=max
*.tags=ds_judgments_public_ui_django:latest
*.output=type=docker,dest=/tmp/django-image.tar

- name: Upload Django image
uses: actions/upload-artifact@v4
with:
name: django-image
path: /tmp/django-image.tar

# With no caching at all the entire ci process takes 4m 30s to complete!
pytest:
needs: build-django
runs-on: ubuntu-latest

steps:
Expand All @@ -83,14 +114,21 @@ jobs:
- name: Create docker network as used in dev
run: docker network create caselaw

- name: Build the Stack
run: docker compose build postgres django
- name: Download Django image
uses: actions/download-artifact@v4
with:
name: django-image
path: /tmp

- name: Load Django image
run: docker load --input /tmp/django-image.tar

- name: Run DB Migrations
run: docker compose run --rm django python manage.py migrate --settings=config.settings.test

- name: Run Django Tests with coverage
run: docker compose run django coverage run -m pytest -vvvv -rsa -m "not local"

- name: Generate coverage XML
run: docker compose run django coverage xml

Expand All @@ -109,6 +147,12 @@ jobs:
run: docker compose down

e2e-tests:
needs:
- linter
- build-scss
- js-tests
- build-django
- pytest
runs-on: ubuntu-latest

steps:
Expand All @@ -124,8 +168,14 @@ jobs:
- name: Create docker network as used in dev
run: docker network create caselaw

- name: Build the Stack
run: docker compose build postgres django
- name: Download Django image
uses: actions/download-artifact@v4
with:
name: django-image
path: /tmp

- name: Load Django image
run: docker load --input /tmp/django-image.tar

- name: Checkout Marklogic repo
uses: actions/checkout@v4
Expand Down Expand Up @@ -158,7 +208,7 @@ jobs:
run: docker compose run --rm django python manage.py migrate --settings=config.settings.test

- name: Setup django server for e2e tests
run: docker compose up -d
run: docker compose up -d django

- name: Install NPM deps
run: npm install
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
services:
django:
image: ds_judgments_public_ui_django
platform: linux/amd64
build:
context: .
Expand Down
Loading