Run tests on a pr workflow (sqlalchemy/alembic)
The Run tests on a pr workflow from sqlalchemy/alembic, explained and optimized by Latchkey.
CI health: D - needs work
Run this on Latchkey for self-healing, caching, and up to 58% lower cost.
Grade your own workflow free or run it on Latchkey →What it does
This is the Run tests on a pr workflow from the sqlalchemy/alembic 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: Run tests on a pr
on:
# run on pull request to main excluding changes that are only on doc or example folders
pull_request:
branches:
- main
paths-ignore:
- "docs/**"
env:
# global env to all steps
TOX_WORKERS: -n2
permissions:
contents: read
jobs:
run-test-amd64:
name: ${{ matrix.python-version }}-${{ matrix.sqlalchemy }}-${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
# run this job using this matrix, excluding some combinations below.
matrix:
os:
- "ubuntu-22.04"
python-version:
- "3.13"
sqlalchemy:
- sqla14
- sqla20
- sqlamain
# abort all jobs as soon as one fails
fail-fast: true
# steps to run in each job. Some are github actions, others run shell commands
steps:
- name: Checkout repo
uses: actions/checkout@v7
- name: Set up python
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
architecture: ${{ matrix.architecture }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade nox setuptools
pip list
- name: Run tests
run: nox -t py-${{ matrix.sqlalchemy }}
run-pep484:
name: pep484-${{ matrix.python-version }}-${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- "ubuntu-latest"
python-version:
- "3.12"
- "3.13"
fail-fast: false
steps:
- name: Checkout repo
uses: actions/checkout@v7
- name: Set up python
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
architecture: ${{ matrix.architecture }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade nox setuptools
pip list
- name: Run pep484
run: nox -s pep484
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: Run tests on a pr on: # run on pull request to main excluding changes that are only on doc or example folders pull_request: branches: - main paths-ignore: - "docs/**" env: # global env to all steps TOX_WORKERS: -n2 permissions: contents: read concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: run-test-amd64: timeout-minutes: 30 name: ${{ matrix.python-version }}-${{ matrix.sqlalchemy }}-${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: # run this job using this matrix, excluding some combinations below. matrix: os: - "ubuntu-22.04" python-version: - "3.13" sqlalchemy: - sqla14 - sqla20 - sqlamain # abort all jobs as soon as one fails fail-fast: true # steps to run in each job. Some are github actions, others run shell commands steps: - name: Checkout repo uses: actions/checkout@v7 - name: Set up python uses: actions/setup-python@v6 with: cache: 'pip' python-version: ${{ matrix.python-version }} architecture: ${{ matrix.architecture }} - name: Install dependencies run: | python -m pip install --upgrade pip pip install --upgrade nox setuptools pip list - name: Run tests run: nox -t py-${{ matrix.sqlalchemy }} run-pep484: timeout-minutes: 30 name: pep484-${{ matrix.python-version }}-${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: matrix: os: - "ubuntu-latest" python-version: - "3.12" - "3.13" fail-fast: false steps: - name: Checkout repo uses: actions/checkout@v7 - name: Set up python uses: actions/setup-python@v6 with: cache: 'pip' python-version: ${{ matrix.python-version }} architecture: ${{ matrix.architecture }} - name: Install dependencies run: | python -m pip install --upgrade pip pip install --upgrade nox setuptools pip list - name: Run pep484 run: nox -s pep484
What changed
- 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.
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 2 jobs (5 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.