CI workflow (adamchainz/time-machine)
The CI workflow from adamchainz/time-machine, explained and optimized by Latchkey.
CI health: C - fair
Point runs-on at Latchkey and get caching, job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the CI workflow from the adamchainz/time-machine 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
name: CI
on:
push:
branches:
- main
tags:
- '**'
pull_request:
concurrency:
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
tests:
name: Python ${{ matrix.python-version }}
runs-on: ubuntu-24.04
strategy:
matrix:
python-version:
- '3.10'
- '3.11'
- '3.12'
- '3.13'
- '3.13t'
- '3.14'
- '3.14t'
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
- name: Install uv
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
with:
enable-cache: true
- name: Run tox targets for ${{ matrix.python-version }}
run: uvx --with tox-uv tox run -f py$(echo ${{ matrix.python-version }} | tr -d .)
- name: Upload coverage data
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: coverage-data-${{ matrix.python-version }}
path: '${{ github.workspace }}/.coverage/*'
include-hidden-files: true
if-no-files-found: error
coverage:
name: Coverage
runs-on: ubuntu-24.04
needs: tests
if: always()
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: '3.13'
- name: Install uv
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
- name: Install dependencies
run: uv pip install --system coverage[toml]
- name: Download data
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
path: .coverage
pattern: coverage-data-*
merge-multiple: true
- name: Combine coverage and fail if it's <100%
run: |
python -m coverage combine
python -m coverage html --skip-covered --skip-empty
python -m coverage report --fail-under=100
echo "## Coverage summary" >> $GITHUB_STEP_SUMMARY
python -m coverage report --format=markdown >> $GITHUB_STEP_SUMMARY
- name: Upload HTML report
if: failure()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: html-report
path: htmlcov
build:
name: Build wheels for ${{ matrix.os }}-${{ matrix.arch }}
if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'Build')
strategy:
fail-fast: false
matrix:
include:
- os: linux
arch: aarch64
- os: linux
arch: x86_64
- os: macos
arch: arm64
- os: macos
arch: x86_64
- os: windows
arch: AMD64
- os: windows
arch: ARM64
runs-on: ${{ (matrix.os == 'linux' && matrix.arch == 'aarch64' && 'ubuntu-24.04-arm') || (matrix.os == 'linux' && 'ubuntu-24.04') || (matrix.os == 'macos' && matrix.arch == 'arm64' && 'macos-15') || (matrix.os == 'macos' && matrix.arch == 'x86_64' && 'macos-15-intel') || (matrix.os == 'windows' && matrix.arch == 'ARM64' && 'windows-11-arm') || (matrix.os == 'windows' && 'windows-2022') || 'unknown' }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
with:
enable-cache: false
- name: Build sdist
if: matrix.os == 'linux' && matrix.arch == 'x86_64'
run: uv build --sdist
- name: Build wheels
run: uv run --only-group build cibuildwheel --output-dir dist
- run: ${{ (matrix.os == 'windows' && 'dir') || 'ls -lh' }} dist/
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: dist-${{ matrix.os }}-${{ matrix.arch }}
path: dist
release:
needs: [coverage, build]
if: success() && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-24.04
environment: release
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: get dist artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
merge-multiple: true
pattern: dist-*
path: dist
- uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0
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: branches: - main tags: - '**' pull_request: concurrency: group: ${{ github.head_ref || github.run_id }} cancel-in-progress: true jobs: tests: timeout-minutes: 30 name: Python ${{ matrix.python-version }} runs-on: latchkey-small strategy: matrix: python-version: - '3.10' - '3.11' - '3.12' - '3.13' - '3.13t' - '3.14' - '3.14t' steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: persist-credentials: false - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 with: cache: 'pip' python-version: ${{ matrix.python-version }} allow-prereleases: true - name: Install uv uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0 with: enable-cache: true - name: Run tox targets for ${{ matrix.python-version }} run: uvx --with tox-uv tox run -f py$(echo ${{ matrix.python-version }} | tr -d .) - name: Upload coverage data uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: name: coverage-data-${{ matrix.python-version }} path: '${{ github.workspace }}/.coverage/*' include-hidden-files: true if-no-files-found: error coverage: timeout-minutes: 30 name: Coverage runs-on: latchkey-small needs: tests if: always() steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: persist-credentials: false - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 with: cache: 'pip' python-version: '3.13' - name: Install uv uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0 - name: Install dependencies run: uv pip install --system coverage[toml] - name: Download data uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 with: path: .coverage pattern: coverage-data-* merge-multiple: true - name: Combine coverage and fail if it's <100% run: | python -m coverage combine python -m coverage html --skip-covered --skip-empty python -m coverage report --fail-under=100 echo "## Coverage summary" >> $GITHUB_STEP_SUMMARY python -m coverage report --format=markdown >> $GITHUB_STEP_SUMMARY - name: Upload HTML report if: failure() uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: name: html-report path: htmlcov build: timeout-minutes: 30 name: Build wheels for ${{ matrix.os }}-${{ matrix.arch }} if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'Build') strategy: fail-fast: false matrix: include: - os: linux arch: aarch64 - os: linux arch: x86_64 - os: macos arch: arm64 - os: macos arch: x86_64 - os: windows arch: AMD64 - os: windows arch: ARM64 runs-on: ${{ (matrix.os == 'linux' && matrix.arch == 'aarch64' && 'ubuntu-24.04-arm') || (matrix.os == 'linux' && 'ubuntu-24.04') || (matrix.os == 'macos' && matrix.arch == 'arm64' && 'macos-15') || (matrix.os == 'macos' && matrix.arch == 'x86_64' && 'macos-15-intel') || (matrix.os == 'windows' && matrix.arch == 'ARM64' && 'windows-11-arm') || (matrix.os == 'windows' && 'windows-2022') || 'unknown' }} steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: persist-credentials: false - uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0 with: enable-cache: false - name: Build sdist if: matrix.os == 'linux' && matrix.arch == 'x86_64' run: uv build --sdist - name: Build wheels run: uv run --only-group build cibuildwheel --output-dir dist - run: ${{ (matrix.os == 'windows' && 'dir') || 'ls -lh' }} dist/ - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: name: dist-${{ matrix.os }}-${{ matrix.arch }} path: dist release: timeout-minutes: 30 needs: [coverage, build] if: success() && startsWith(github.ref, 'refs/tags/') runs-on: latchkey-small environment: release permissions: contents: read id-token: write steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: persist-credentials: false - name: get dist artifacts uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 with: merge-multiple: true pattern: dist-* path: dist - uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0
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. - 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.
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 4 jobs (10 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.