Skip to content

Commit

Permalink
ci: create the release workflow
Browse files Browse the repository at this point in the history
- pushing a calver formatted tag kicks off a release
- run tests, build app container image, push to GHCR
- for a release tag, make a GitHub release
  • Loading branch information
lalver1 committed Dec 11, 2024
1 parent 2174318 commit 35df4ff
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 1 deletion.
14 changes: 14 additions & 0 deletions .github/lighthouserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"ci": {
"numberOfRuns": 3,
"settings": {
"preset": "desktop"
},
"assert": {
"assertions": {
"categories:accessibility": ["error", { "minScore": 1 }],
"categories:best-practices": ["warn", { "minScore": 0.9 }]
}
}
}
}
104 changes: 104 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Deploy

on:
workflow_dispatch:
push:
branches:
- main
tags:
# pre-release tag
- "202[4-9].[0-9][0-9].[0-9]+-rc[0-9]+"
# release tags
- "202[4-9].[0-9][0-9].[0-9]+"

defaults:
run:
shell: bash

jobs:
tests-ui:
uses: ./.github/workflows/tests-ui.yml
if: github.ref_type == 'tag'

tests-pytest:
uses: ./.github/workflows/tests-pytest.yml
if: github.ref_type == 'tag'

deploy:
runs-on: ubuntu-latest
needs: [tests-ui, tests-pytest]
if: (!cancelled())

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

- uses: actions/setup-python@v5
with:
python-version-file: .github/workflows/.python-version
cache: pip
cache-dependency-path: "**/pyproject.toml"

- name: Write python packages to file
run: |
python -m venv .venv
source .venv/bin/activate
pip install pipdeptree
pip install -e .
pipdeptree
pipdeptree >> pems/static/requirements.txt
- name: Write commit SHA to file
run: echo "${{ github.sha }}" >> pems/static/sha.txt

- name: Write tag to file
run: echo "${{ github.ref_name }}" >> pems/static/version.txt

- name: Docker Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

- name: Build, tag, and push image to GitHub Container Registry
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64
builder: ${{ steps.buildx.outputs.name }}
build-args: GIT-SHA=${{ github.sha }}
cache-from: type=gha,scope=compilerla
cache-to: type=gha,scope=compilerla,mode=max
context: .
file: appcontainer/Dockerfile
push: true
tags: |
ghcr.io/${{ github.repository }}:${{ github.ref_name }}
ghcr.io/${{ github.repository }}:${{ github.sha }}
release:
needs: deploy
if: ${{ github.ref_type == 'tag' && !contains(github.ref, '-rc') }}
runs-on: ubuntu-latest
permissions:
# https://github.com/softprops/action-gh-release#permissions
contents: write

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Release
uses: softprops/action-gh-release@v2
with:
prerelease: false
generate_release_notes: true
31 changes: 31 additions & 0 deletions .github/workflows/tests-ui.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: UI & a11y tests

on:
workflow_call:
workflow_dispatch:
pull_request:
branches: [main]

defaults:
run:
shell: bash

jobs:
tests-ui:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Start app
run: |
cp .env.sample .env
docker compose up --detach app
- name: Run Lighthouse tests for a11y
uses: treosh/lighthouse-ci-action@12.1.0
with:
urls: http://localhost:8000/admin
configPath: ".github/lighthouserc.json"
temporaryPublicStorage: true
uploadArtifacts: true
2 changes: 1 addition & 1 deletion compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
image: caltrans/pems:app
env_file: .env
ports:
- "8000"
- "${DJANGO_LOCAL_PORT:-8000}:8000"

dev:
build:
Expand Down

0 comments on commit 35df4ff

Please sign in to comment.