CI workflow (tfranzel/drf-spectacular)
The CI workflow from tfranzel/drf-spectacular, explained and optimized by Latchkey.
CI health: F - at risk
Point runs-on at Latchkey and get caching, run de-duplication, job timeouts, SHA-pinned actions, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the CI workflow from the tfranzel/drf-spectacular repository, a real project running GitHub Actions. It is shown here with attribution under its BSD-3-Clause license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
name: CI
on: [ push, pull_request ]
jobs:
prep-tests:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-vars.outputs.matrix }}
date: ${{ steps.set-vars.outputs.date }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- run: pip install tox
- name: Generate matrix & vars
id: set-vars
run: python helper/github-ci-vars.py
tests:
needs: prep-tests
runs-on: ubuntu-22.04
name: tests-${{ matrix.setup.toxenv }}
continue-on-error: ${{ matrix.setup.experimental }}
strategy:
matrix:
setup: ${{ fromJson(needs.prep-tests.outputs.matrix) }}
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: ~/.cache/pip
key: pip-${{ needs.prep-tests.date }}
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.setup.python-version }}
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y gdal-bin libsqlite3-mod-spatialite
- name: Install tox
run: pip install tox
- name: Patch pyproject.toml for Python 3.8 (setuptools issue)
if: matrix.setup.python-version == '3.8'
run: python helper/pyproject_license_patch.py
- name: Run Tox
run: tox --skip-missing-interpreters=false -e ${{ matrix.setup.toxenv }}
- uses: codecov/codecov-action@v4
with:
name: ${{ matrix.setup.toxenv }}
token: ${{ secrets.CODECOV_TOKEN }}
passed-tests:
name: Required tests passed
needs: [ tests ]
runs-on: ubuntu-latest
steps:
- run: echo "All Done"
The same workflow, on Latchkey
Estimated ~20% faster on cache hits, plus fewer wasted runs and a safer supply chain. Added and changed lines are highlighted.
name: CI on: [ push, pull_request ] concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: prep-tests: timeout-minutes: 30 runs-on: latchkey-small outputs: matrix: ${{ steps.set-vars.outputs.matrix }} date: ${{ steps.set-vars.outputs.date }} steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: cache: 'pip' python-version: '3.10' - run: pip install tox - name: Generate matrix & vars id: set-vars run: python helper/github-ci-vars.py tests: timeout-minutes: 30 needs: prep-tests runs-on: latchkey-small name: tests-${{ matrix.setup.toxenv }} continue-on-error: ${{ matrix.setup.experimental }} strategy: matrix: setup: ${{ fromJson(needs.prep-tests.outputs.matrix) }} steps: - uses: actions/checkout@v3 - uses: actions/cache@v3 with: path: ~/.cache/pip key: pip-${{ needs.prep-tests.date }} - uses: actions/setup-python@v4 with: cache: 'pip' python-version: ${{ matrix.setup.python-version }} - name: Install system dependencies run: | sudo apt-get update sudo apt-get install -y gdal-bin libsqlite3-mod-spatialite - name: Install tox run: pip install tox - name: Patch pyproject.toml for Python 3.8 (setuptools issue) if: matrix.setup.python-version == '3.8' run: python helper/pyproject_license_patch.py - name: Run Tox run: tox --skip-missing-interpreters=false -e ${{ matrix.setup.toxenv }} - uses: codecov/codecov-action@v4 with: name: ${{ matrix.setup.toxenv }} token: ${{ secrets.CODECOV_TOKEN }} passed-tests: timeout-minutes: 30 name: Required tests passed needs: [ tests ] runs-on: latchkey-small steps: - run: echo "All Done"
What changed
- Run on Latchkey managed runners with one line (
runs-on), which apply the fixes below automatically and self-heal transient failures. This example useslatchkey-small; pick the runner size that fits the job. - Cancel superseded runs when a branch or PR gets a newer push.
- Cache dependency installs on the setup step so they are served from cache.
- Add a job timeout so a hung step cannot burn hours of runner time.
1 third-party action is referenced by a movable tag. Pin it to the commit SHA (Latchkey resolves and applies this automatically) so a repointed tag cannot change what runs.
What Latchkey heals here
This workflow has steps that commonly fail on transient issues (network, registries, flaky browsers). On Latchkey managed runners they are detected, retried, and self-healed instead of failing your build:
- Dependency installs
This workflow runs 3 jobs per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.