CI workflow (nolar/kopf)
The CI workflow from nolar/kopf, 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 nolar/kopf repository, a real project running GitHub Actions. It is shown here with attribution under its MIT license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
# The quick CI tests run on every push to a PR. They perform a quick check
# if the feature set and codebase are stable in general, but only for
# a representative selection of environments.
name: CI
on:
pull_request:
branches:
- main
- release/**
workflow_dispatch: {}
jobs:
linters:
name: Linting and static analysis
runs-on: ubuntu-24.04
timeout-minutes: 7 # usually 5 mins with coverage
steps:
- uses: actions/checkout@v6
- uses: astral-sh/setup-uv@v7
- uses: actions/setup-python@v6
with:
python-version: "3.14"
- run: uv sync --no-dev --group lint
- run: uv run --no-sync pre-commit run --all-files
- run: uv run --no-sync mypy
- run: |
# Separately, because the shared module name "example.py" causes naming conflicts.
exit_codes=0
for d in $(find examples -maxdepth 1 -mindepth 1 -type d)
do
echo "Checking ${d}"
uv run --no-sync mypy $d
exit_codes=$[${exit_codes} + $?]
done
exit ${exit_codes}
unit-tests:
strategy:
fail-fast: false
matrix:
install-extras: [ "", "full-auth" ]
python-version: [ "3.10", "3.11", "3.12", "3.13", "3.14" ]
include:
- install-extras: "uvloop"
python-version: "3.14"
name: Python ${{ matrix.python-version }}${{ matrix.install-extras && ' ' || '' }}${{ matrix.install-extras }}
runs-on: ubuntu-24.04
timeout-minutes: 7 # usually 5 mins with coverage
steps:
- uses: actions/checkout@v6
- uses: astral-sh/setup-uv@v7
- uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- run: uv sync --no-dev --group test
- run: uv sync --no-dev --group test --extra ${{ matrix.install-extras }}
if: ${{ matrix.install-extras }}
- run: uv run --no-sync coverage run --branch --source=kopf -m pytest --color=yes --timeout=2
- name: Publish coverage to Coveralls.io
uses: coverallsapp/github-action@v2
with:
parallel: true
flag-name: ${{ matrix.python-version }}${{ matrix.install-extras && ' ' || '' }}${{ matrix.install-extras }}
if: success()
continue-on-error: true # tends to fail with no code changes (e.g. only CI/docs)
- name: Publish coverage to CodeCov.io
uses: codecov/codecov-action@v6
env:
PYTHON: ${{ matrix.python-version }}
with:
flags: unit
env_vars: PYTHON
token: ${{ secrets.CODECOV_TOKEN }}
if: success()
# Only the core functionality is tested: no e2e or functional tests (for simplicity).
# No coverage: PyPy performs extremely poorly with tracing/coverage (13 mins vs. 3 mins).
# Extra time: 2-3 mins for building the dependencies (since no binary wheels are available).
# Extra time: PyPy is good with JIT for repetitive code; tests are too unique for JIT.
pypy-tests:
strategy:
fail-fast: false
matrix:
install-extras: [ "", "full-auth" ]
python-version: [ "pypy-3.10", "pypy-3.11" ]
name: Python ${{ matrix.python-version }}${{ matrix.install-extras && ' ' || '' }}${{ matrix.install-extras }}
runs-on: ubuntu-24.04
timeout-minutes: 5
steps:
- uses: actions/checkout@v6
- uses: astral-sh/setup-uv@v7
- uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- run: sudo apt-get update && sudo apt-get install libxml2-dev libxslt-dev
- run: uv sync --no-dev --group test
- run: uv sync --no-dev --group test --extra ${{ matrix.install-extras }}
if: ${{ matrix.install-extras }}
- run: uv run --no-sync pytest --color=yes --timeout=2 --no-cov
functional:
strategy:
fail-fast: false
matrix:
k3s: [latest, v1.33, v1.32, v1.31]
name: K3s ${{matrix.k3s}}
runs-on: ubuntu-24.04
timeout-minutes: 10 # usually 4-5 mins
steps:
- uses: actions/checkout@v6
- uses: astral-sh/setup-uv@v7
- uses: actions/setup-python@v6
with:
python-version: "3.14"
- uses: nolar/setup-k3d-k3s@v1
with:
version: ${{ matrix.k3s }}
github-token: ${{ secrets.GITHUB_TOKEN }}
k3s-args: --disable=metrics-server@server:*
- run: uv sync --no-dev --group test
- run: uv pip install -r examples/requirements.txt
- run: uv run --no-sync pytest --color=yes --timeout=30 --only-e2e
coveralls-finish:
name: Finalize coveralls.io
needs: [unit-tests, pypy-tests, functional]
runs-on: ubuntu-24.04
steps:
- name: Finish coverage at Coveralls.io
uses: coverallsapp/github-action@v2
with:
parallel-finished: true
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.
# The quick CI tests run on every push to a PR. They perform a quick check # if the feature set and codebase are stable in general, but only for # a representative selection of environments. name: CI on: pull_request: branches: - main - release/** workflow_dispatch: {} concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: linters: name: Linting and static analysis runs-on: latchkey-small timeout-minutes: 7 # usually 5 mins with coverage steps: - uses: actions/checkout@v6 - uses: astral-sh/setup-uv@v7 - uses: actions/setup-python@v6 with: cache: 'pip' python-version: "3.14" - run: uv sync --no-dev --group lint - run: uv run --no-sync pre-commit run --all-files - run: uv run --no-sync mypy - run: | # Separately, because the shared module name "example.py" causes naming conflicts. exit_codes=0 for d in $(find examples -maxdepth 1 -mindepth 1 -type d) do echo "Checking ${d}" uv run --no-sync mypy $d exit_codes=$[${exit_codes} + $?] done exit ${exit_codes} unit-tests: strategy: fail-fast: false matrix: install-extras: [ "", "full-auth" ] python-version: [ "3.10", "3.11", "3.12", "3.13", "3.14" ] include: - install-extras: "uvloop" python-version: "3.14" name: Python ${{ matrix.python-version }}${{ matrix.install-extras && ' ' || '' }}${{ matrix.install-extras }} runs-on: latchkey-small timeout-minutes: 7 # usually 5 mins with coverage steps: - uses: actions/checkout@v6 - uses: astral-sh/setup-uv@v7 - uses: actions/setup-python@v6 with: cache: 'pip' python-version: ${{ matrix.python-version }} - run: uv sync --no-dev --group test - run: uv sync --no-dev --group test --extra ${{ matrix.install-extras }} if: ${{ matrix.install-extras }} - run: uv run --no-sync coverage run --branch --source=kopf -m pytest --color=yes --timeout=2 - name: Publish coverage to Coveralls.io uses: coverallsapp/github-action@v2 with: parallel: true flag-name: ${{ matrix.python-version }}${{ matrix.install-extras && ' ' || '' }}${{ matrix.install-extras }} if: success() continue-on-error: true # tends to fail with no code changes (e.g. only CI/docs) - name: Publish coverage to CodeCov.io uses: codecov/codecov-action@v6 env: PYTHON: ${{ matrix.python-version }} with: flags: unit env_vars: PYTHON token: ${{ secrets.CODECOV_TOKEN }} if: success() # Only the core functionality is tested: no e2e or functional tests (for simplicity). # No coverage: PyPy performs extremely poorly with tracing/coverage (13 mins vs. 3 mins). # Extra time: 2-3 mins for building the dependencies (since no binary wheels are available). # Extra time: PyPy is good with JIT for repetitive code; tests are too unique for JIT. pypy-tests: strategy: fail-fast: false matrix: install-extras: [ "", "full-auth" ] python-version: [ "pypy-3.10", "pypy-3.11" ] name: Python ${{ matrix.python-version }}${{ matrix.install-extras && ' ' || '' }}${{ matrix.install-extras }} runs-on: latchkey-small timeout-minutes: 5 steps: - uses: actions/checkout@v6 - uses: astral-sh/setup-uv@v7 - uses: actions/setup-python@v6 with: cache: 'pip' python-version: ${{ matrix.python-version }} - run: sudo apt-get update && sudo apt-get install libxml2-dev libxslt-dev - run: uv sync --no-dev --group test - run: uv sync --no-dev --group test --extra ${{ matrix.install-extras }} if: ${{ matrix.install-extras }} - run: uv run --no-sync pytest --color=yes --timeout=2 --no-cov functional: strategy: fail-fast: false matrix: k3s: [latest, v1.33, v1.32, v1.31] name: K3s ${{matrix.k3s}} runs-on: latchkey-small timeout-minutes: 10 # usually 4-5 mins steps: - uses: actions/checkout@v6 - uses: astral-sh/setup-uv@v7 - uses: actions/setup-python@v6 with: cache: 'pip' python-version: "3.14" - uses: nolar/setup-k3d-k3s@v1 with: version: ${{ matrix.k3s }} github-token: ${{ secrets.GITHUB_TOKEN }} k3s-args: --disable=metrics-server@server:* - run: uv sync --no-dev --group test - run: uv pip install -r examples/requirements.txt - run: uv run --no-sync pytest --color=yes --timeout=30 --only-e2e coveralls-finish: timeout-minutes: 30 name: Finalize coveralls.io needs: [unit-tests, pypy-tests, functional] runs-on: latchkey-small steps: - name: Finish coverage at Coveralls.io uses: coverallsapp/github-action@v2 with: parallel-finished: true
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.
4 third-party actions are referenced by a movable tag. Pin them 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
- End-to-end and browser tests
This workflow runs 5 jobs (20 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.