Skip to content
Latchkey LogoLatchkey home

Test Suite workflow (encode/uvicorn)

The Test Suite workflow from encode/uvicorn, explained and optimized by Latchkey.

Source: encode/uvicorn.github/workflows/main.ymlLicense BSD-3-ClauseView source
C
CI health grade
69/100
Health score
3
Jobs per trigger
3
Fixes in the optimized version

In short

  1. CI health: C (fair)
  2. The optimized version below points runs-on at Latchkey managed runners and adds run de-duplication and job timeouts.

What it does

This is the Test Suite workflow from the encode/uvicorn repository, a real project running GitHub Actions. It is shown here with attribution under its BSD-3-Clause license.

Below, Latchkey shows a faster, safer version produced by its optimization engine.

The workflow

workflow (.yml)
name: Test Suite

on:
  push:
    branches: ["main"]
  pull_request:
    branches: ["main"]

jobs:
  tests:
    name: "Python ${{ matrix.python-version }} ${{ matrix.os }}"
    runs-on: "${{ matrix.os }}"
    timeout-minutes: 10

    permissions:
      contents: read

    strategy:
      fail-fast: false
      matrix:
        python-version: ["3.10", "3.11", "3.12", "3.13", "3.14", "3.14t"]
        os: [windows-latest, ubuntu-latest, macos-latest]

    steps:
      - uses: "actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0" # v7.0.0
        with:
          persist-credentials: false

      - name: Install uv
        uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
        with:
          python-version: ${{ matrix.python-version }}
          enable-cache: ${{ matrix.os != 'windows-latest' }}

      - name: Install dependencies
        run: scripts/install
        shell: bash

      - name: Run linting checks
        run: scripts/check
        if: "${{ matrix.os == 'ubuntu-latest'}}"

      - name: "Build package & docs"
        run: scripts/build
        shell: bash

      - name: "Run tests"
        run: scripts/test
        shell: bash

      - name: "Enforce coverage"
        run: scripts/coverage
        shell: bash

  docs-preview:
    if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
    runs-on: ubuntu-latest

    env:
      HAS_CLOUDFLARE_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN != '' }}

    permissions:
      contents: read
      pull-requests: write

    environment:
      name: cloudflare
      url: ${{ steps.deploy.outputs.deployment-url }}

    steps:
      - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
        with:
          persist-credentials: false

      - name: Install uv
        uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
        with:
          python-version: "3.12"
          enable-cache: false

      - name: Install dependencies
        run: scripts/install

      - name: Build docs
        run: uv run zensical build

      - name: Deploy preview to Cloudflare Workers
        id: deploy
        if: ${{ env.HAS_CLOUDFLARE_TOKEN == 'true' }}
        uses: cloudflare/wrangler-action@ebbaa1584979971c8614a24965b4405ff95890e0 # v4.0.0
        with:
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
          command: versions upload --tag pr-${{ github.event.pull_request.number }}

      - name: Comment preview URL on PR
        if: ${{ steps.deploy.outcome == 'success' }}
        uses: thollander/actions-comment-pull-request@24bffb9b452ba05a4f3f77933840a6a841d1b32b # v3.0.1
        with:
          message: |
            :book: Docs preview: ${{ steps.deploy.outputs.deployment-url }}
          comment-tag: docs-preview

  # https://github.com/marketplace/actions/alls-green#why
  check:
    if: always()
    needs: [tests]
    runs-on: ubuntu-latest

    permissions:
      contents: read

    steps:
      - name: Decide whether the needed jobs succeeded or failed
        uses: re-actors/alls-green@05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe # v1.2.2
        with:
          jobs: ${{ toJSON(needs) }}

The same workflow, on Latchkey

Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.

workflow (.yml), optimized
name: Test Suite

on:
  push:
    branches: ["main"]
  pull_request:
    branches: ["main"]

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  tests:
    name: "Python ${{ matrix.python-version }} ${{ matrix.os }}"
    runs-on: "${{ matrix.os }}"
    timeout-minutes: 10

    permissions:
      contents: read

    strategy:
      fail-fast: false
      matrix:
        python-version: ["3.10", "3.11", "3.12", "3.13", "3.14", "3.14t"]
        os: [windows-latest, ubuntu-latest, macos-latest]

    steps:
      - uses: "actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0" # v7.0.0
        with:
          persist-credentials: false

      - name: Install uv
        uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
        with:
          python-version: ${{ matrix.python-version }}
          enable-cache: ${{ matrix.os != 'windows-latest' }}

      - name: Install dependencies
        run: scripts/install
        shell: bash

      - name: Run linting checks
        run: scripts/check
        if: "${{ matrix.os == 'ubuntu-latest'}}"

      - name: "Build package & docs"
        run: scripts/build
        shell: bash

      - name: "Run tests"
        run: scripts/test
        shell: bash

      - name: "Enforce coverage"
        run: scripts/coverage
        shell: bash

  docs-preview:
    timeout-minutes: 30
    if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
    runs-on: ubuntu-latest
    runs-on: latchkey-small

    env:
      HAS_CLOUDFLARE_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN != '' }}

    permissions:
      contents: read
      pull-requests: write

    environment:
      name: cloudflare
      url: ${{ steps.deploy.outputs.deployment-url }}

    steps:
      - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
        with:
          persist-credentials: false

      - name: Install uv
        uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
        with:
          python-version: "3.12"
          enable-cache: false

      - name: Install dependencies
        run: scripts/install

      - name: Build docs
        run: uv run zensical build

      - name: Deploy preview to Cloudflare Workers
        id: deploy
        if: ${{ env.HAS_CLOUDFLARE_TOKEN == 'true' }}
        uses: cloudflare/wrangler-action@ebbaa1584979971c8614a24965b4405ff95890e0 # v4.0.0
        with:
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
          command: versions upload --tag pr-${{ github.event.pull_request.number }}

      - name: Comment preview URL on PR
        if: ${{ steps.deploy.outcome == 'success' }}
        uses: thollander/actions-comment-pull-request@24bffb9b452ba05a4f3f77933840a6a841d1b32b # v3.0.1
        with:
          message: |
            :book: Docs preview: ${{ steps.deploy.outputs.deployment-url }}
          comment-tag: docs-preview

  # https://github.com/marketplace/actions/alls-green#why
  check:
    timeout-minutes: 30
    if: always()
    needs: [tests]
    runs-on: ubuntu-latest
    runs-on: latchkey-small

    permissions:
      contents: read

    steps:
      - name: Decide whether the needed jobs succeeded or failed
        uses: re-actors/alls-green@05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe # v1.2.2
        with:
          jobs: ${{ toJSON(needs) }}

What changed

  1. Run on Latchkey managed runners with one line (runs-on), which apply the fixes below automatically and self-heal transient failures. Each Linux x64 job moves to the Latchkey size matching its vCPU count, latchkey-small for a standard 2 vCPU runner; macOS, Windows and arm64 jobs stay as written.
  2. Cancel superseded runs when a branch or PR gets a newer push.
  3. Add a job timeout so a hung step cannot burn hours of runner time.

Left runs-on as written on the tests job: matrix.os mixes Linux with Windows and macOS, which Latchkey does not run. Point only the Linux legs at Latchkey, for example with a matrix include entry that sets the runner.

This workflow runs 3 jobs (20 with the matrix expanded) per trigger. 8 of the 20 run on a standard GitHub-hosted Linux x64 runner, which in a private repository bills $0.006 a minute against $0.0025 on latchkey-small, 58% lower; in a public repository like this one they are free. 12 of the 20 run on Windows and macOS, which Latchkey does not offer, so those stay where they are. Estimate the monthly difference with your own run counts.

Actions used in this workflow

  • astral-sh/setup-uv
  • actions/checkout
  • cloudflare/wrangler-action
  • thollander/actions-comment-pull-request
  • re-actors/alls-green

Frequently asked questions

What does the Test Suite workflow (encode/uvicorn) workflow do?
This is the Test Suite workflow from the encode/uvicorn repository, a real project running GitHub Actions. It is shown here with attribution under its BSD-3-Clause license.
What CI health grade does this workflow get?
This Automation and other workflow grades C. Paste your own workflow into the Latchkey grader to see its grade and the exact fixes.
How can I improve this Automation and other workflow?
Add run de-duplication and job timeouts. Latchkey applies these automatically on managed runners when you point runs-on at Latchkey.

References