Skip to content
Latchkey

PyTest and Publish workflow (chapmanjacobd/library)

The PyTest and Publish workflow from chapmanjacobd/library, explained and optimized by Latchkey.

D

CI health: D - needs work

Point runs-on at Latchkey and get caching, run de-duplication, 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: chapmanjacobd/library.github/workflows/push.yamlLicense BSD-3-ClauseView source

What it does

This is the PyTest and Publish workflow from the chapmanjacobd/library repository, a real project running GitHub Actions. It is shown here with attribution under its BSD-3-Clause license.

Below, Latchkey shows a faster, safer version produced by its optimization engine.

The workflow

workflow (.yml)
name: PyTest and Publish

on:
  push:
    tags: ['v[0-9].[0-9]+.[0-9]+']

jobs:
  test1:
    runs-on: ubuntu-latest
    timeout-minutes: 20

    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: Setup Python
        uses: actions/setup-python@v6
        with:
          python-version: "3.11"

      - run: |
          sudo apt-get update -q -q
          sudo apt-get install --yes ffmpeg

      - name: Install pdm
        run: |
          python -m pip install pdm
          pdm install --no-editable -G test

      - name: Run missing modules test
        run: pdm run pytest tests/test_modules.py  # should run before deluxe deps installed

      - name: Run deluxe pytest
        run: |
          pdm install --no-editable -G deluxe
          pdm run pytest

  test2:
    needs: test1
    strategy:
      fail-fast: false
      max-parallel: 8
      matrix:
        nv: [ {os: windows-latest, py: "3.12"}, {os: macos-latest, py: "3.13"} ]

    runs-on: ${{ matrix.nv.os }}
    timeout-minutes: 20

    steps:
      - uses: actions/checkout@v6
      - name: Set up Python ${{ matrix.nv.py }}
        uses: actions/setup-python@v6
        with:
          python-version: ${{ matrix.nv.py }}

      - if: runner.os == 'Linux'
        run: |
          sudo apt-get update -q -q
          sudo apt-get install --yes ffmpeg
      - if: runner.os == 'macOS'
        run: |
          brew untap aws/tap azure/bicep
          brew install ffmpeg
      - if: runner.os == 'Windows'
        run: choco install ffmpeg

      - name: Install Dependencies
        run: |
          python -m pip install pdm
          pdm install --no-editable -G test

      - name: Run deluxe pytest
        run: |
          pdm install --no-editable -G deluxe
          pdm run pytest

  publish:
    needs: [test1, test2]
    runs-on: ubuntu-latest
    environment: publish
    permissions:
      contents: read
      id-token: write

    timeout-minutes: 20

    steps:
      - uses: actions/checkout@v6

      - uses: pdm-project/setup-pdm@main

      - run: |
          pdm config request_timeout 100
          pdm publish

  release:
    needs: publish
    runs-on: ubuntu-latest
    timeout-minutes: 20

    steps:
      - run: gh release create ${{ github.ref_name }} --repo ${{ github.repository }} --title "Release ${{ github.ref_name }}" --generate-notes
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

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: PyTest and Publish
 
on:
  push:
    tags: ['v[0-9].[0-9]+.[0-9]+']
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  test1:
    runs-on: latchkey-small
    timeout-minutes: 20
 
    steps:
      - name: Checkout
        uses: actions/checkout@v6
 
      - name: Setup Python
        uses: actions/setup-python@v6
        with:
          cache: 'pip'
          python-version: "3.11"
 
      - run: |
          sudo apt-get update -q -q
          sudo apt-get install --yes ffmpeg
 
      - name: Install pdm
        run: |
          python -m pip install pdm
          pdm install --no-editable -G test
 
      - name: Run missing modules test
        run: pdm run pytest tests/test_modules.py  # should run before deluxe deps installed
 
      - name: Run deluxe pytest
        run: |
          pdm install --no-editable -G deluxe
          pdm run pytest
 
  test2:
    needs: test1
    strategy:
      fail-fast: false
      max-parallel: 8
      matrix:
        nv: [ {os: windows-latest, py: "3.12"}, {os: macos-latest, py: "3.13"} ]
 
    runs-on: ${{ matrix.nv.os }}
    timeout-minutes: 20
 
    steps:
      - uses: actions/checkout@v6
      - name: Set up Python ${{ matrix.nv.py }}
        uses: actions/setup-python@v6
        with:
          cache: 'pip'
          python-version: ${{ matrix.nv.py }}
 
      - if: runner.os == 'Linux'
        run: |
          sudo apt-get update -q -q
          sudo apt-get install --yes ffmpeg
      - if: runner.os == 'macOS'
        run: |
          brew untap aws/tap azure/bicep
          brew install ffmpeg
      - if: runner.os == 'Windows'
        run: choco install ffmpeg
 
      - name: Install Dependencies
        run: |
          python -m pip install pdm
          pdm install --no-editable -G test
 
      - name: Run deluxe pytest
        run: |
          pdm install --no-editable -G deluxe
          pdm run pytest
 
  publish:
    needs: [test1, test2]
    runs-on: latchkey-small
    environment: publish
    permissions:
      contents: read
      id-token: write
 
    timeout-minutes: 20
 
    steps:
      - uses: actions/checkout@v6
 
      - uses: pdm-project/setup-pdm@main
 
      - run: |
          pdm config request_timeout 100
          pdm publish
 
  release:
    needs: publish
    runs-on: latchkey-small
    timeout-minutes: 20
 
    steps:
      - run: gh release create ${{ github.ref_name }} --repo ${{ github.repository }} --title "Release ${{ github.ref_name }}" --generate-notes
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
 

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 4 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.

Actions used in this workflow