Skip to content
Latchkey

Test workflow (kevin1024/vcrpy)

The Test workflow from kevin1024/vcrpy, explained and optimized by Latchkey.

F

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.

Grade your own workflow free or run it on Latchkey →
Source: kevin1024/vcrpy.github/workflows/main.ymlLicense MITView source

What it does

This is the Test workflow from the kevin1024/vcrpy 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)
name: Test

on:
  push:
    branches:
      - master
  pull_request:
  schedule:
    - cron: "0 16 * * 5" # Every Friday 4pm
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-24.04
    strategy:
      fail-fast: false
      matrix:
        python-version:
          - "3.10"
          - "3.11"
          - "3.12"
          - "3.13"
          - "pypy-3.11"
        test-dependencies:
          - tests
          - tests-niquests

    steps:
      - uses: actions/checkout@v6
      - name: Install uv
        uses: astral-sh/setup-uv@v7

      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v6
        with:
          python-version: ${{ matrix.python-version }}
          allow-prereleases: true

      - name: Install project dependencies
        run: |
          uv pip install --system --upgrade pip setuptools
          uv pip install --system codecov '.[${{ matrix.test-dependencies }}]'
          uv pip check

      - name: Allow creation of user namespaces (e.g. to the unshare command)
        run: |
          # .. so that we don't get error:
          # unshare: write failed /proc/self/uid_map: Operation not permitted
          # Idea from https://github.com/YoYoGames/GameMaker-Bugs/issues/6015#issuecomment-2135552784 .
          sudo sysctl kernel.apparmor_restrict_unprivileged_userns=0

      - name: Run online tests
        run: ./runtests.sh --cov=./vcr --cov-branch --cov-report=xml --cov-append -m online

      - name: Run offline tests with no access to the Internet
        run: |
          # We're using unshare to take Internet access
          # away so that we'll notice whenever some new test
          # is missing @pytest.mark.online decoration in the future
          unshare --map-root-user --net -- \
              sh -c 'ip link set lo up; ./runtests.sh --cov=./vcr --cov-branch --cov-report=xml --cov-append -m "not online"'

      - name: Run coverage
        run: codecov

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: Test
 
on:
  push:
    branches:
      - master
  pull_request:
  schedule:
    - cron: "0 16 * * 5" # Every Friday 4pm
  workflow_dispatch:
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  build:
    timeout-minutes: 30
    runs-on: latchkey-small
    strategy:
      fail-fast: false
      matrix:
        python-version:
          - "3.10"
          - "3.11"
          - "3.12"
          - "3.13"
          - "pypy-3.11"
        test-dependencies:
          - tests
          - tests-niquests
 
    steps:
      - uses: actions/checkout@v6
      - name: Install uv
        uses: astral-sh/setup-uv@v7
 
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v6
        with:
          cache: 'pip'
          python-version: ${{ matrix.python-version }}
          allow-prereleases: true
 
      - name: Install project dependencies
        run: |
          uv pip install --system --upgrade pip setuptools
          uv pip install --system codecov '.[${{ matrix.test-dependencies }}]'
          uv pip check
 
      - name: Allow creation of user namespaces (e.g. to the unshare command)
        run: |
          # .. so that we don't get error:
          # unshare: write failed /proc/self/uid_map: Operation not permitted
          # Idea from https://github.com/YoYoGames/GameMaker-Bugs/issues/6015#issuecomment-2135552784 .
          sudo sysctl kernel.apparmor_restrict_unprivileged_userns=0
 
      - name: Run online tests
        run: ./runtests.sh --cov=./vcr --cov-branch --cov-report=xml --cov-append -m online
 
      - name: Run offline tests with no access to the Internet
        run: |
          # We're using unshare to take Internet access
          # away so that we'll notice whenever some new test
          # is missing @pytest.mark.online decoration in the future
          unshare --map-root-user --net -- \
              sh -c 'ip link set lo up; ./runtests.sh --cov=./vcr --cov-branch --cov-report=xml --cov-append -m "not online"'
 
      - name: Run coverage
        run: codecov
 

What changed

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:

This workflow runs 1 job (10 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