Continuous Integration workflow (pyvisa/pyvisa)
The Continuous Integration workflow from pyvisa/pyvisa, explained and optimized by Latchkey.
CI health: F - at risk
Point runs-on at Latchkey and get caching, run de-duplication, job timeouts, SHA-pinned actions, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the Continuous Integration workflow from the pyvisa/pyvisa 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: Continuous Integration
on:
schedule:
- cron: "0 0 * * 2"
push:
branches:
- main
- staging
- trying
pull_request:
branches:
- main
paths:
- .github/workflows/ci.yml
- "pyvisa/**"
- pyproject.toml
jobs:
formatting:
name: Check code formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Install tools
run: |
python -m pip install --upgrade pip
pip install ruff mypy pytest numpy
- name: Formatting
run: |
ruff format pyvisa --check;
- name: Linting
if: always()
run: |
ruff check pyvisa;
- name: typing
if: always()
run: |
mypy pyvisa;
tests:
name: Unit tests
runs-on: ${{ matrix.os }}
needs:
- formatting
if: needs.formatting.result == 'success'
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
steps:
- uses: actions/checkout@v7
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install numpy
- name: Install project
run: |
pip install -e .
- name: Test with pytest
run: |
pip install pytest-cov
python -X dev -m pytest --pyargs pyvisa --cov --cov-report xml -v
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v7
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: unittests
name: codecov-umbrella
fail_ci_if_error: true
# Added to summarize the matrix (otherwise we would need to list every single
# job in bors.toml)
tests-result:
name: Tests result
if: always()
needs:
- tests
runs-on: ubuntu-latest
steps:
- name: Mark the job as a success
if: needs.tests.result == 'success'
run: exit 0
- name: Mark the job as a failure
if: needs.tests.result != 'success'
run: exit 1
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: Continuous Integration on: schedule: - cron: "0 0 * * 2" push: branches: - main - staging - trying pull_request: branches: - main paths: - .github/workflows/ci.yml - "pyvisa/**" - pyproject.toml concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: formatting: timeout-minutes: 30 name: Check code formatting runs-on: latchkey-small steps: - uses: actions/checkout@v7 - name: Set up Python uses: actions/setup-python@v6 with: cache: 'pip' python-version: "3.12" - name: Install tools run: | python -m pip install --upgrade pip pip install ruff mypy pytest numpy - name: Formatting run: | ruff format pyvisa --check; - name: Linting if: always() run: | ruff check pyvisa; - name: typing if: always() run: | mypy pyvisa; tests: timeout-minutes: 30 name: Unit tests runs-on: ${{ matrix.os }} needs: - formatting if: needs.formatting.result == 'success' strategy: matrix: os: [ubuntu-latest, windows-latest, macos-latest] python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"] steps: - uses: actions/checkout@v7 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v6 with: cache: 'pip' python-version: ${{ matrix.python-version }} - name: Install dependencies run: | python -m pip install --upgrade pip pip install numpy - name: Install project run: | pip install -e . - name: Test with pytest run: | pip install pytest-cov python -X dev -m pytest --pyargs pyvisa --cov --cov-report xml -v - name: Upload coverage to Codecov uses: codecov/codecov-action@v7 with: token: ${{ secrets.CODECOV_TOKEN }} flags: unittests name: codecov-umbrella fail_ci_if_error: true # Added to summarize the matrix (otherwise we would need to list every single # job in bors.toml) tests-result: timeout-minutes: 30 name: Tests result if: always() needs: - tests runs-on: latchkey-small steps: - name: Mark the job as a success if: needs.tests.result == 'success' run: exit 0 - name: Mark the job as a failure if: needs.tests.result != 'success' run: exit 1
What changed
- Run on Latchkey managed runners with one line (
runs-on), which apply the fixes below automatically and self-heal transient failures. This example useslatchkey-small; pick the runner size that fits the job. - 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.
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:
- Dependency installs
This workflow runs 3 jobs (17 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.