Tests workflow (TorchIO-project/torchio)
The Tests workflow from TorchIO-project/torchio, explained and optimized by Latchkey.
CI health: C - fair
Point runs-on at Latchkey and get 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 Tests workflow from the TorchIO-project/torchio repository, a real project running GitHub Actions. It is shown here with attribution under its Apache-2.0 license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
name: Tests
on:
push:
branches:
- main
pull_request:
workflow_dispatch:
schedule:
- cron: "0 4 * * *"
permissions:
contents: read
env:
FORCE_COLOR: 1
jobs:
pytest:
name: Unit tests
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python: ["3.10", "3.11", "3.12", "3.13", "3.14"]
fail-fast: false
runs-on: ${{ matrix.os }}
env:
OS: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v7
- name: Install tox
run: uv tool install --python ${{ matrix.python }} --with tox-uv tox
- name: Add local bin to path on Windows
if: runner.os == 'Windows'
run: echo "C:/Users/runneradmin/.local/bin" >> $GITHUB_PATH
shell: bash
- name: Install ffmpeg for video tests
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y ffmpeg
- name: Setup test suite
run: tox run -v --notest --skip-missing-interpreters false -e test
# Run all tests on schedule, but only non-slow tests on push
- name: Run pytest
run: |
if [ "${{ github.event_name }}" == "schedule" ]; then
tox -e test
else
tox -e test -- -m "not slow"
fi
shell: bash # this wouldn't work on Powershell
- name: Upload coverage reports to Codecov
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python == '3.14' }}
uses: codecov/codecov-action@v7.0.0
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
cli:
name: CLI smoke tests
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Test transforms CLI tool
run: uv run -- torchio transform --help
- name: Test info CLI tool
run: uv run -- torchio info --help
docs:
name: Documentation snippet tests
runs-on: ubuntu-latest
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
steps:
- name: Checkout repository
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Install tox
run: uv tool install --with tox-uv tox
- name: Run doc snippet tests
run: tox -e docs-test
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
name: Tests on: push: branches: - main pull_request: workflow_dispatch: schedule: - cron: "0 4 * * *" permissions: contents: read env: FORCE_COLOR: 1 concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: pytest: timeout-minutes: 30 name: Unit tests strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] python: ["3.10", "3.11", "3.12", "3.13", "3.14"] fail-fast: false runs-on: ${{ matrix.os }} env: OS: ${{ matrix.os }} steps: - name: Checkout repository uses: actions/checkout@v7 with: fetch-depth: 0 - name: Install the latest version of uv uses: astral-sh/setup-uv@v7 - name: Install tox run: uv tool install --python ${{ matrix.python }} --with tox-uv tox - name: Add local bin to path on Windows if: runner.os == 'Windows' run: echo "C:/Users/runneradmin/.local/bin" >> $GITHUB_PATH shell: bash - name: Install ffmpeg for video tests if: runner.os == 'Linux' run: sudo apt-get update && sudo apt-get install -y ffmpeg - name: Setup test suite run: tox run -v --notest --skip-missing-interpreters false -e test # Run all tests on schedule, but only non-slow tests on push - name: Run pytest run: | if [ "${{ github.event_name }}" == "schedule" ]; then tox -e test else tox -e test -- -m "not slow" fi shell: bash # this wouldn't work on Powershell - name: Upload coverage reports to Codecov if: ${{ matrix.os == 'ubuntu-latest' && matrix.python == '3.14' }} uses: codecov/codecov-action@v7.0.0 env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} cli: timeout-minutes: 30 name: CLI smoke tests runs-on: latchkey-small steps: - name: Checkout repository uses: actions/checkout@v7 with: fetch-depth: 0 - name: Install uv uses: astral-sh/setup-uv@v7 - name: Test transforms CLI tool run: uv run -- torchio transform --help - name: Test info CLI tool run: uv run -- torchio info --help docs: timeout-minutes: 30 name: Documentation snippet tests runs-on: latchkey-small if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' steps: - name: Checkout repository uses: actions/checkout@v7 with: fetch-depth: 0 - name: Install uv uses: astral-sh/setup-uv@v7 - name: Install tox run: uv tool install --with tox-uv tox - name: Run doc snippet tests run: tox -e docs-test
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.
- Add a job timeout so a hung step cannot burn hours of runner time.
2 third-party actions are referenced by a movable tag. Pin them 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.