Run tests and upload coverage workflow (MinishLab/semhash)
The Run tests and upload coverage workflow from MinishLab/semhash, explained and optimized by Latchkey.
CI health: F - at risk
Run this on Latchkey for self-healing, caching, and up to 58% lower cost.
Grade your own workflow free or run it on Latchkey →What it does
This is the Run tests and upload coverage workflow from the MinishLab/semhash 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: Run tests and upload coverage
on:
push
jobs:
test:
name: Run tests with pytest
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["ubuntu-latest", "windows-latest"]
python-version: ["3.10", "3.11", "3.12"]
exclude:
- os: windows-latest
python-version: "3.11"
- os: windows-latest
python-version: "3.12"
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
# Step for Windows: Create and activate a virtual environment
- name: Create and activate a virtual environment (Windows)
if: ${{ runner.os == 'Windows' }}
run: |
irm https://astral.sh/uv/install.ps1 | iex
$env:Path = "C:\Users\runneradmin\.local\bin;$env:Path"
uv venv .venv
"VIRTUAL_ENV=.venv" | Out-File -FilePath $env:GITHUB_ENV -Append
"$PWD/.venv/Scripts" | Out-File -FilePath $env:GITHUB_PATH -Append
# Step for Unix: Create and activate a virtual environment
- name: Create and activate a virtual environment (Unix)
if: ${{ runner.os != 'Windows' }}
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
uv venv .venv
echo "VIRTUAL_ENV=.venv" >> $GITHUB_ENV
echo "$PWD/.venv/bin" >> $GITHUB_PATH
# Install dependencies using uv pip
- name: Install dependencies
run: make install-no-pre-commit
# Run tests with coverage
- name: Run tests under coverage
run: |
coverage run -m pytest
coverage report
# Upload results to Codecov
- name: Upload results to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_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: Run tests and upload coverage on: push concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: test: timeout-minutes: 30 name: Run tests with pytest runs-on: ${{ matrix.os }} strategy: matrix: os: ["ubuntu-latest", "windows-latest"] python-version: ["3.10", "3.11", "3.12"] exclude: - os: windows-latest python-version: "3.11" - os: windows-latest python-version: "3.12" fail-fast: false steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }} uses: actions/setup-python@v5 with: cache: 'pip' python-version: ${{ matrix.python-version }} allow-prereleases: true # Step for Windows: Create and activate a virtual environment - name: Create and activate a virtual environment (Windows) if: ${{ runner.os == 'Windows' }} run: | irm https://astral.sh/uv/install.ps1 | iex $env:Path = "C:\Users\runneradmin\.local\bin;$env:Path" uv venv .venv "VIRTUAL_ENV=.venv" | Out-File -FilePath $env:GITHUB_ENV -Append "$PWD/.venv/Scripts" | Out-File -FilePath $env:GITHUB_PATH -Append # Step for Unix: Create and activate a virtual environment - name: Create and activate a virtual environment (Unix) if: ${{ runner.os != 'Windows' }} run: | curl -LsSf https://astral.sh/uv/install.sh | sh uv venv .venv echo "VIRTUAL_ENV=.venv" >> $GITHUB_ENV echo "$PWD/.venv/bin" >> $GITHUB_PATH # Install dependencies using uv pip - name: Install dependencies run: make install-no-pre-commit # Run tests with coverage - name: Run tests under coverage run: | coverage run -m pytest coverage report # Upload results to Codecov - name: Upload results to Codecov uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }}
What changed
- 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:
- Network fetches
This workflow runs 1 job (6 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.