Notify about Coverage workflow (tenpy/tenpy)
The Notify about Coverage workflow from tenpy/tenpy, explained and optimized by Latchkey.
CI health: C - fair
Point runs-on at Latchkey and get caching, job timeouts, SHA-pinned actions, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the Notify about Coverage workflow from the tenpy/tenpy 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: Notify about Coverage
on:
pull_request_target:
jobs:
calc_coverage:
runs-on: ubuntu-latest
outputs:
COV_PERCENT: ${{ steps.save-coverage.outputs.COV_PERCENT }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools build
python -m pip install --upgrade pytest
python -m pip install --upgrade coverage
- name: Build and install tenpy
# also installs extra dependencies defined in pyproject.toml
run: |
python -m build .
python -m pip install ".[test, extra]"
- name: Run pytest with coverage
# pytest configuration in pyproject.toml
# Note: This runs in the repo root directory, which contains the uncompiled tenpy package.
# To use the version we just installed, it is important to run `coverage`
# instead of `python -m coverage`.
run: |
coverage run -m pytest .
coverage report -m --skip-covered --sort=miss
coverage json
- name: save coverage
id: save-coverage
run: echo "COV_PERCENT=$(jq .totals.percent_covered coverage.json | xargs printf "%.0f")" >> $GITHUB_OUTPUT
comment:
needs: [calc_coverage]
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: mshick/add-pr-comment@v2
with:
message: |
Thank you for working on this Pull request!
Here are some stats on your progress.
The overall test coverage on TenPy, including the changes within this PR, is now ${{ needs.calc_coverage.outputs.COV_PERCENT }}%.
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: Notify about Coverage on: pull_request_target: jobs: calc_coverage: timeout-minutes: 30 runs-on: latchkey-small outputs: COV_PERCENT: ${{ steps.save-coverage.outputs.COV_PERCENT }} steps: - name: Checkout uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: cache: 'pip' python-version: "3.12" - name: Install dependencies run: | python -m pip install --upgrade pip python -m pip install --upgrade setuptools build python -m pip install --upgrade pytest python -m pip install --upgrade coverage - name: Build and install tenpy # also installs extra dependencies defined in pyproject.toml run: | python -m build . python -m pip install ".[test, extra]" - name: Run pytest with coverage # pytest configuration in pyproject.toml # Note: This runs in the repo root directory, which contains the uncompiled tenpy package. # To use the version we just installed, it is important to run `coverage` # instead of `python -m coverage`. run: | coverage run -m pytest . coverage report -m --skip-covered --sort=miss coverage json - name: save coverage id: save-coverage run: echo "COV_PERCENT=$(jq .totals.percent_covered coverage.json | xargs printf "%.0f")" >> $GITHUB_OUTPUT comment: timeout-minutes: 30 needs: [calc_coverage] runs-on: latchkey-small permissions: pull-requests: write steps: - uses: mshick/add-pr-comment@v2 with: message: | Thank you for working on this Pull request! Here are some stats on your progress. The overall test coverage on TenPy, including the changes within this PR, is now ${{ needs.calc_coverage.outputs.COV_PERCENT }}%.
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. - 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 2 jobs per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.