Skip to content
Latchkey

Tests workflow (cdgriffith/Box)

The Tests workflow from cdgriffith/Box, explained and optimized by Latchkey.

D

CI health: D - needs work

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

Grade your own workflow free or run it on Latchkey →
Source: cdgriffith/Box.github/workflows/tests.ymlLicense MITView source

What it does

This is the Tests workflow from the cdgriffith/Box 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)
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Tests

on:
  push:
    branches: [ test, tests ]
  pull_request:
    branches: [ master, development, develop, test, tests ]

jobs:
  package-checks:
    strategy:
      matrix:
        python-version: ["3.10", "3.11", "3.12", "3.13", "3.14", "pypy-3.11"]
        os: [ubuntu-latest, macos-latest, windows-latest]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
#      - uses: actions/cache@v3
#        with:
#          path: ~/.cache/pip
#          key: package-check-${{ hashFiles('requirements.txt') }}-${{ hashFiles('requirements-test.txt') }}
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt
          pip install -r requirements-test.txt
          pip install coveralls mypy setuptools wheel twine Cython>=3.0.11
      - name: Run mypy
        if: "!startsWith(matrix.python-version, 'pypy')"
        run: mypy box
      - name: Build Wheel and check distribution log description
        run: |
          python setup.py sdist bdist_wheel
          twine check dist/*
      - name: Test packaged wheel on *nix
        if: matrix.os != 'windows-latest'
        run: |
          pip install dist/*.whl
          rm -rf box
          python -m pytest -vv
      - name: Test packaged wheel on Windows
        if: matrix.os == 'windows-latest'
        run: |
          $wheel = (Get-ChildItem dist\*.whl | Sort lastWriteTime | Select-Object -last 1).Name
          pip install dist\${wheel}
          Remove-item box -recurse -force
          python -m pytest -vv
      - name: Upload wheel artifact
        uses: actions/upload-artifact@v4
        with:
          name: python_box_${{matrix.os}}_${{ matrix.python-version }}
          path: dist/*.whl

  package-manylinux-checks:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python 3.13
        uses: actions/setup-python@v5
        with:
          python-version: "3.13"

#      - uses: actions/cache@v3
#        with:
#          path: ~/.cache/pip
#          key: package-manylinux-check-${{ hashFiles('requirements.txt') }}-${{ hashFiles('requirements-test.txt') }}

      - name: Build wheels
        run: |
          python -m pip install --upgrade pip
          pip install cibuildwheel
          python -m cibuildwheel --output-dir dist
        env:
          CIBW_BUILD: cp310-manylinux_x86_64 cp311-manylinux_x86_64 cp312-manylinux_x86_64 cp313-manylinux_x86_64
          CIBW_BEFORE_BUILD: pip install Cython>=3.0.11 setuptools wheel
          CIBW_BUILD_FRONTEND: "build; args: --no-isolation"
          CIBW_BEFORE_TEST: pip install -r requirements.txt -r requirements-test.txt setuptools wheel twine Cython>=3.0.11
          CIBW_BUILD_VERBOSITY: 1
          CIBW_TEST_COMMAND: pytest {package}/test -vv

      - name: Upload wheel artifact
        uses: actions/upload-artifact@v4
        with:
          name: python_box_manylinux
          path: dist/*-manylinux*.whl

  test:
    strategy:
      matrix:
        python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
        os: [ubuntu-latest, macos-latest, windows-latest]
    runs-on: ${{ matrix.os }}
    steps:
    - uses: actions/checkout@v4
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v5
      with:
        python-version: ${{ matrix.python-version }}
#    - uses: actions/cache@v3
#      with:
#        path: ~/.cache/pip
#        key: test-${{ hashFiles('requirements.txt') }}-${{ hashFiles('requirements-test.txt') }}
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt
        pip install -r requirements-test.txt
        pip install setuptools wheel Cython>=3.0.11
        python setup.py build_ext --inplace
    - name: Test with pytest
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      run: |
        pytest --cov=box -vv test/

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.

# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
 
name: Tests
 
on:
  push:
    branches: [ test, tests ]
  pull_request:
    branches: [ master, development, develop, test, tests ]
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  package-checks:
    timeout-minutes: 30
    strategy:
      matrix:
        python-version: ["3.10", "3.11", "3.12", "3.13", "3.14", "pypy-3.11"]
        os: [ubuntu-latest, macos-latest, windows-latest]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v5
        with:
          cache: 'pip'
          python-version: ${{ matrix.python-version }}
#      - uses: actions/cache@v3
#        with:
#          path: ~/.cache/pip
#          key: package-check-${{ hashFiles('requirements.txt') }}-${{ hashFiles('requirements-test.txt') }}
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt
          pip install -r requirements-test.txt
          pip install coveralls mypy setuptools wheel twine Cython>=3.0.11
      - name: Run mypy
        if: "!startsWith(matrix.python-version, 'pypy')"
        run: mypy box
      - name: Build Wheel and check distribution log description
        run: |
          python setup.py sdist bdist_wheel
          twine check dist/*
      - name: Test packaged wheel on *nix
        if: matrix.os != 'windows-latest'
        run: |
          pip install dist/*.whl
          rm -rf box
          python -m pytest -vv
      - name: Test packaged wheel on Windows
        if: matrix.os == 'windows-latest'
        run: |
          $wheel = (Get-ChildItem dist\*.whl | Sort lastWriteTime | Select-Object -last 1).Name
          pip install dist\${wheel}
          Remove-item box -recurse -force
          python -m pytest -vv
      - name: Upload wheel artifact
        uses: actions/upload-artifact@v4
        with:
          name: python_box_${{matrix.os}}_${{ matrix.python-version }}
          path: dist/*.whl
 
  package-manylinux-checks:
    timeout-minutes: 30
    runs-on: latchkey-small
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python 3.13
        uses: actions/setup-python@v5
        with:
          cache: 'pip'
          python-version: "3.13"
 
#      - uses: actions/cache@v3
#        with:
#          path: ~/.cache/pip
#          key: package-manylinux-check-${{ hashFiles('requirements.txt') }}-${{ hashFiles('requirements-test.txt') }}
 
      - name: Build wheels
        run: |
          python -m pip install --upgrade pip
          pip install cibuildwheel
          python -m cibuildwheel --output-dir dist
        env:
          CIBW_BUILD: cp310-manylinux_x86_64 cp311-manylinux_x86_64 cp312-manylinux_x86_64 cp313-manylinux_x86_64
          CIBW_BEFORE_BUILD: pip install Cython>=3.0.11 setuptools wheel
          CIBW_BUILD_FRONTEND: "build; args: --no-isolation"
          CIBW_BEFORE_TEST: pip install -r requirements.txt -r requirements-test.txt setuptools wheel twine Cython>=3.0.11
          CIBW_BUILD_VERBOSITY: 1
          CIBW_TEST_COMMAND: pytest {package}/test -vv
 
      - name: Upload wheel artifact
        uses: actions/upload-artifact@v4
        with:
          name: python_box_manylinux
          path: dist/*-manylinux*.whl
 
  test:
    timeout-minutes: 30
    strategy:
      matrix:
        python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
        os: [ubuntu-latest, macos-latest, windows-latest]
    runs-on: ${{ matrix.os }}
    steps:
    - uses: actions/checkout@v4
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v5
      with:
        cache: 'pip'
        python-version: ${{ matrix.python-version }}
#    - uses: actions/cache@v3
#      with:
#        path: ~/.cache/pip
#        key: test-${{ hashFiles('requirements.txt') }}-${{ hashFiles('requirements-test.txt') }}
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt
        pip install -r requirements-test.txt
        pip install setuptools wheel Cython>=3.0.11
        python setup.py build_ext --inplace
    - name: Test with pytest
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      run: |
        pytest --cov=box -vv test/
 

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 3 jobs (34 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