Skip to content
Latchkey

Run tests on a pr workflow (sqlalchemy/sqlalchemy)

The Run tests on a pr workflow from sqlalchemy/sqlalchemy, explained and optimized by Latchkey.

D

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 →
Source: sqlalchemy/sqlalchemy.github/workflows/run-on-pr.yamlLicense MITView source

What it does

This is the Run tests on a pr workflow from the sqlalchemy/sqlalchemy 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

workflow (.yml)
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:
      - "examples/**"

env:
  # global env to all steps
  TOX_WORKERS: -n4

permissions:
  contents: read

jobs:
  run-test-amd64:
    name: test-amd64-${{ matrix.python-version }}-${{ matrix.build-type }}-${{ matrix.architecture }}-${{ 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"
          - "3.14"
        build-type:
          - "cext-greenlet"
          - "cext"
          - "nocext"
        architecture:
          - x64
      # abort all jobs as soon as one fails
      fail-fast: false

    # 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 -v -s github-${{ matrix.build-type }} -- ${{ matrix.pytest-args }}

  run-nox:
    name: ${{ matrix.nox-env }}-${{ matrix.python-version }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os:
          - "ubuntu-22.04"
        python-version:
          - "3.14"
        nox-env:
          - mypy
          - pep484
          - pep8

      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 nox
        run: nox -v -s ${{ matrix.nox-env }} -- ${{ matrix.pytest-args }}

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:
      - "examples/**"
 
env:
  # global env to all steps
  TOX_WORKERS: -n4
 
permissions:
  contents: read
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  run-test-amd64:
    timeout-minutes: 30
    name: test-amd64-${{ matrix.python-version }}-${{ matrix.build-type }}-${{ matrix.architecture }}-${{ 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"
          - "3.14"
        build-type:
          - "cext-greenlet"
          - "cext"
          - "nocext"
        architecture:
          - x64
      # abort all jobs as soon as one fails
      fail-fast: false
 
    # 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 -v -s github-${{ matrix.build-type }} -- ${{ matrix.pytest-args }}
 
  run-nox:
    timeout-minutes: 30
    name: ${{ matrix.nox-env }}-${{ matrix.python-version }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os:
          - "ubuntu-22.04"
        python-version:
          - "3.14"
        nox-env:
          - mypy
          - pep484
          - pep8
 
      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 nox
        run: nox -v -s ${{ matrix.nox-env }} -- ${{ matrix.pytest-args }}
 

What changed

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:

This workflow runs 2 jobs (9 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow