Tests workflow (MagicStack/asyncpg)
The Tests workflow from MagicStack/asyncpg, 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 Tests workflow from the MagicStack/asyncpg repository, a real project running GitHub Actions. It is shown here with attribution under its Apache-2.0 license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
name: Tests
on:
push:
branches:
- master
- ci
pull_request:
branches:
- master
jobs:
test-platforms:
# NOTE: this matrix is for testing various combinations of Python and OS
# versions on the system-installed PostgreSQL version (which is usually
# fairly recent). For a PostgreSQL version matrix see the test-postgres
# job.
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14", "3.14t"]
os: [ubuntu-latest, macos-latest, windows-latest]
loop: [asyncio, uvloop]
exclude:
# uvloop does not support windows
- loop: uvloop
os: windows-latest
runs-on: ${{ matrix.os }}
permissions: {}
defaults:
run:
shell: bash
env:
PIP_DISABLE_PIP_VERSION_CHECK: 1
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 50
submodules: true
persist-credentials: false
- name: Check if release PR.
uses: edgedb/action-release/validate-pr@master
id: release
with:
github_token: ${{ secrets.RELEASE_BOT_GITHUB_TOKEN }}
missing_version_ok: yes
version_file: asyncpg/_version.py
version_line_pattern: |
__version__(?:\s*:\s*typing\.Final)?\s*=\s*(?:['"])([[:PEP440:]])(?:['"])
- name: Setup PostgreSQL
if: "!steps.release.outputs.is_release && matrix.os == 'macos-latest'"
run: |
POSTGRES_FORMULA="postgresql@18"
brew install "$POSTGRES_FORMULA"
echo "$(brew --prefix "$POSTGRES_FORMULA")/bin" >> $GITHUB_PATH
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
if: "!steps.release.outputs.is_release"
with:
python-version: ${{ matrix.python-version }}
- name: Install Python Deps
if: "!steps.release.outputs.is_release"
run: |
[ "$RUNNER_OS" = "Linux" ] && .github/workflows/install-krb5.sh
python -m pip install -U pip setuptools wheel
python -m pip install --group test
python -m pip install -e .
- name: Test
if: "!steps.release.outputs.is_release"
env:
LOOP_IMPL: ${{ matrix.loop }}
run: |
if [ "${LOOP_IMPL}" = "uvloop" ]; then
env USE_UVLOOP=1 python -m unittest -v tests.suite
else
python -m unittest -v tests.suite
fi
test-postgres:
strategy:
matrix:
postgres-version: ["9.5", "9.6", "10", "11", "12", "13", "14", "15", "16", "17", "18"]
runs-on: ubuntu-latest
permissions: {}
env:
PIP_DISABLE_PIP_VERSION_CHECK: 1
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 50
submodules: true
persist-credentials: false
- name: Check if release PR.
uses: edgedb/action-release/validate-pr@master
id: release
with:
github_token: ${{ secrets.RELEASE_BOT_GITHUB_TOKEN }}
missing_version_ok: yes
version_file: asyncpg/_version.py
version_line_pattern: |
__version__(?:\s*:\s*typing\.Final)?\s*=\s*(?:['"])([[:PEP440:]])(?:['"])
- name: Set up PostgreSQL
if: "!steps.release.outputs.is_release"
env:
PGVERSION: ${{ matrix.postgres-version }}
DISTRO_NAME: focal
run: |
sudo env DISTRO_NAME="${DISTRO_NAME}" PGVERSION="${PGVERSION}" \
.github/workflows/install-postgres.sh
echo PGINSTALLATION="/usr/lib/postgresql/${PGVERSION}/bin" \
>> "${GITHUB_ENV}"
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
if: "!steps.release.outputs.is_release"
with:
python-version: "3.x"
- name: Install Python Deps
if: "!steps.release.outputs.is_release"
run: |
[ "$RUNNER_OS" = "Linux" ] && .github/workflows/install-krb5.sh
python -m pip install -U pip setuptools wheel
python -m pip install --group test
python -m pip install -e .
- name: Test
if: "!steps.release.outputs.is_release"
env:
PGVERSION: ${{ matrix.postgres-version }}
run: |
python -m unittest -v tests.suite
# This job exists solely to act as the test job aggregate to be
# targeted by branch policies.
regression-tests:
name: "Regression Tests"
needs: [test-platforms, test-postgres]
runs-on: ubuntu-latest
permissions: {}
steps:
- run: echo OK
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: Tests on: push: branches: - master - ci pull_request: branches: - master concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: test-platforms: timeout-minutes: 30 # NOTE: this matrix is for testing various combinations of Python and OS # versions on the system-installed PostgreSQL version (which is usually # fairly recent). For a PostgreSQL version matrix see the test-postgres # job. strategy: matrix: python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14", "3.14t"] os: [ubuntu-latest, macos-latest, windows-latest] loop: [asyncio, uvloop] exclude: # uvloop does not support windows - loop: uvloop os: windows-latest runs-on: ${{ matrix.os }} permissions: {} defaults: run: shell: bash env: PIP_DISABLE_PIP_VERSION_CHECK: 1 steps: - uses: actions/checkout@v5 with: fetch-depth: 50 submodules: true persist-credentials: false - name: Check if release PR. uses: edgedb/action-release/validate-pr@master id: release with: github_token: ${{ secrets.RELEASE_BOT_GITHUB_TOKEN }} missing_version_ok: yes version_file: asyncpg/_version.py version_line_pattern: | __version__(?:\s*:\s*typing\.Final)?\s*=\s*(?:['"])([[:PEP440:]])(?:['"]) - name: Setup PostgreSQL if: "!steps.release.outputs.is_release && matrix.os == 'macos-latest'" run: | POSTGRES_FORMULA="postgresql@18" brew install "$POSTGRES_FORMULA" echo "$(brew --prefix "$POSTGRES_FORMULA")/bin" >> $GITHUB_PATH - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v6 if: "!steps.release.outputs.is_release" with: cache: 'pip' python-version: ${{ matrix.python-version }} - name: Install Python Deps if: "!steps.release.outputs.is_release" run: | [ "$RUNNER_OS" = "Linux" ] && .github/workflows/install-krb5.sh python -m pip install -U pip setuptools wheel python -m pip install --group test python -m pip install -e . - name: Test if: "!steps.release.outputs.is_release" env: LOOP_IMPL: ${{ matrix.loop }} run: | if [ "${LOOP_IMPL}" = "uvloop" ]; then env USE_UVLOOP=1 python -m unittest -v tests.suite else python -m unittest -v tests.suite fi test-postgres: timeout-minutes: 30 strategy: matrix: postgres-version: ["9.5", "9.6", "10", "11", "12", "13", "14", "15", "16", "17", "18"] runs-on: latchkey-small permissions: {} env: PIP_DISABLE_PIP_VERSION_CHECK: 1 steps: - uses: actions/checkout@v5 with: fetch-depth: 50 submodules: true persist-credentials: false - name: Check if release PR. uses: edgedb/action-release/validate-pr@master id: release with: github_token: ${{ secrets.RELEASE_BOT_GITHUB_TOKEN }} missing_version_ok: yes version_file: asyncpg/_version.py version_line_pattern: | __version__(?:\s*:\s*typing\.Final)?\s*=\s*(?:['"])([[:PEP440:]])(?:['"]) - name: Set up PostgreSQL if: "!steps.release.outputs.is_release" env: PGVERSION: ${{ matrix.postgres-version }} DISTRO_NAME: focal run: | sudo env DISTRO_NAME="${DISTRO_NAME}" PGVERSION="${PGVERSION}" \ .github/workflows/install-postgres.sh echo PGINSTALLATION="/usr/lib/postgresql/${PGVERSION}/bin" \ >> "${GITHUB_ENV}" - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v6 if: "!steps.release.outputs.is_release" with: cache: 'pip' python-version: "3.x" - name: Install Python Deps if: "!steps.release.outputs.is_release" run: | [ "$RUNNER_OS" = "Linux" ] && .github/workflows/install-krb5.sh python -m pip install -U pip setuptools wheel python -m pip install --group test python -m pip install -e . - name: Test if: "!steps.release.outputs.is_release" env: PGVERSION: ${{ matrix.postgres-version }} run: | python -m unittest -v tests.suite # This job exists solely to act as the test job aggregate to be # targeted by branch policies. regression-tests: timeout-minutes: 30 name: "Regression Tests" needs: [test-platforms, test-postgres] runs-on: latchkey-small permissions: {} steps: - run: echo OK
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 (54 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.