Skip to content
Latchkey

CI workflow (schireson/pytest-alembic)

The CI workflow from schireson/pytest-alembic, explained and optimized by Latchkey.

C

CI health: C - fair

Point runs-on at Latchkey and get caching, job timeouts, SHA-pinned actions, self-healing for flaky steps, and up to 58% lower cost, applied automatically.

Grade your own workflow free or run it on Latchkey →
Source: schireson/pytest-alembic.github/workflows/build.ymlLicense MITView source

What it does

This is the CI workflow from the schireson/pytest-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

workflow (.yml)
name: CI
on: 
  push:
  pull_request:

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  test:
    services:
      postgres:
        image: postgres:11.12
        env:
          POSTGRES_DB: dev
          POSTGRES_USER: user
          POSTGRES_PASSWORD: password
        ports:
          - 5432:5432
        options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
        pytest-version: ["7.0.0", "8.3.5"]
        pytest-asyncio-version: ["0.16.0", "0.23.0"]
        sqlalchemy-version: ["2.0.40"]

        exclude:
          # old versions of pytest-asyncio use old pytest hook syntax
          - pytest-version: "8.3.5"
            pytest-asyncio-version: "0.16.0"

    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-python@v6
        with:
          python-version: ${{ matrix.python-version }}
      - name: Install poetry
        uses: abatilo/actions-poetry@v3.0.1
        with:
          poetry-version: 2.1.3

      - name: Set up cache
        uses: actions/cache@v5
        with:
          path: ~/.cache/pypoetry/virtualenvs
          key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.pytest-version }}-${{ matrix.pytest-asyncio-version }}-${{ matrix.sqlalchemy-version }}-${{ hashFiles('**/poetry.lock') }}

      - name: Install dependencies
        run: poetry run make install

      - name: Install specific versions
        run: |
          poetry run pip install 'sqlalchemy~=${{ matrix.sqlalchemy-version }}'
          poetry run pip install 'pytest~=${{ matrix.pytest-version }}'
          poetry run pip install 'pytest-asyncio~=${{ matrix.pytest-asyncio-version }}'

      - name: Run linters
        if: ${{ matrix.python-version != '3.8' }}
        run: poetry run make lint

      - name: Run tests
        run: poetry run make test

      - name: Store test result artifacts
        uses: actions/upload-artifact@v7
        with:
          name: covarage-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.pytest-version }}-${{ matrix.pytest-asyncio-version }}-${{ matrix.sqlalchemy-version }}-${{ hashFiles('**/poetry.lock') }}
          path: coverage.xml

      - name: Coveralls
        env:
          COVERALLS_FLAG_NAME: run-${{ inputs.working-directory }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          COVERALLS_PARALLEL: true
        run: |
          pip install tomli coveralls
          coveralls --service=github

  finish:
    needs:
      - test
    runs-on: ubuntu-latest
    steps:
      - name: Coveralls Finished
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          pip install tomli coveralls
          coveralls --service=github --finish

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:
  pull_request:
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  test:
    timeout-minutes: 30
    services:
      postgres:
        image: postgres:11.12
        env:
          POSTGRES_DB: dev
          POSTGRES_USER: user
          POSTGRES_PASSWORD: password
        ports:
          - 5432:5432
        options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
 
    runs-on: latchkey-small
    strategy:
      fail-fast: false
      matrix:
        python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
        pytest-version: ["7.0.0", "8.3.5"]
        pytest-asyncio-version: ["0.16.0", "0.23.0"]
        sqlalchemy-version: ["2.0.40"]
 
        exclude:
          # old versions of pytest-asyncio use old pytest hook syntax
          - pytest-version: "8.3.5"
            pytest-asyncio-version: "0.16.0"
 
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-python@v6
        with:
          cache: 'pip'
          python-version: ${{ matrix.python-version }}
      - name: Install poetry
        uses: abatilo/actions-poetry@v3.0.1
        with:
          poetry-version: 2.1.3
 
      - name: Set up cache
        uses: actions/cache@v5
        with:
          path: ~/.cache/pypoetry/virtualenvs
          key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.pytest-version }}-${{ matrix.pytest-asyncio-version }}-${{ matrix.sqlalchemy-version }}-${{ hashFiles('**/poetry.lock') }}
 
      - name: Install dependencies
        run: poetry run make install
 
      - name: Install specific versions
        run: |
          poetry run pip install 'sqlalchemy~=${{ matrix.sqlalchemy-version }}'
          poetry run pip install 'pytest~=${{ matrix.pytest-version }}'
          poetry run pip install 'pytest-asyncio~=${{ matrix.pytest-asyncio-version }}'
 
      - name: Run linters
        if: ${{ matrix.python-version != '3.8' }}
        run: poetry run make lint
 
      - name: Run tests
        run: poetry run make test
 
      - name: Store test result artifacts
        uses: actions/upload-artifact@v7
        with:
          name: covarage-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.pytest-version }}-${{ matrix.pytest-asyncio-version }}-${{ matrix.sqlalchemy-version }}-${{ hashFiles('**/poetry.lock') }}
          path: coverage.xml
 
      - name: Coveralls
        env:
          COVERALLS_FLAG_NAME: run-${{ inputs.working-directory }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          COVERALLS_PARALLEL: true
        run: |
          pip install tomli coveralls
          coveralls --service=github
 
  finish:
    timeout-minutes: 30
    needs:
      - test
    runs-on: latchkey-small
    steps:
      - name: Coveralls Finished
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          pip install tomli coveralls
          coveralls --service=github --finish
 

What changed

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:

This workflow runs 2 jobs (21 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