Skip to content
Latchkey

Test Suite workflow (encode/starlette)

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

C

CI health: C - fair

Point runs-on at Latchkey and get run de-duplication, job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.

Grade your own workflow free or run it on Latchkey →
Source: encode/starlette.github/workflows/main.ymlLicense BSD-3-ClauseView source

What it does

This is the Test Suite workflow from the encode/starlette 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"]

permissions:
  contents: read

jobs:
  tests:
    name: "Python ${{ matrix.python-version }}"
    runs-on: ubuntu-latest

    strategy:
      matrix:
        python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]

    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: true

      - name: Install dependencies
        run: scripts/install

      - name: Run linting checks
        run: scripts/check
        if: ${{ matrix.python-version != '3.14' }}

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

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

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

  # https://github.com/marketplace/actions/alls-green#why
  check:
    if: always()
    needs: [tests]
    runs-on: ubuntu-latest
    steps:
      - name: Decide whether the needed jobs succeeded or failed
        uses: re-actors/alls-green@05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe # v1.2.2
        with:
          jobs: ${{ toJSON(needs) }}

  docs-cloudflare-preview:
    name: Docs preview (Cloudflare)
    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

    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.11"
          enable-cache: false

      - name: Install dependencies
        run: scripts/install

      - name: Build docs
        run: uv run zensical build --clean

      - uses: cloudflare/wrangler-action@ebbaa1584979971c8614a24965b4405ff95890e0 # v4.0.0
        id: deploy
        if: ${{ env.HAS_CLOUDFLARE_TOKEN == 'true' }}
        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
        if: ${{ steps.deploy.outcome == 'success' }}
        uses: marocchino/sticky-pull-request-comment@0ea0beb66eb9baf113663a64ec522f60e49231c0 # v3.0.4
        with:
          message: |
            **Docs preview:** ${{ steps.deploy.outputs.deployment-url }}

The same workflow, on Latchkey

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

---
name: Test Suite
 
on:
  push:
    branches: ["main"]
  pull_request:
    branches: ["main"]
 
permissions:
  contents: read
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  tests:
    timeout-minutes: 30
    name: "Python ${{ matrix.python-version }}"
    runs-on: latchkey-small
 
    strategy:
      matrix:
        python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
 
    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: true
 
      - name: Install dependencies
        run: scripts/install
 
      - name: Run linting checks
        run: scripts/check
        if: ${{ matrix.python-version != '3.14' }}
 
      - name: "Build package & docs"
        run: scripts/build
 
      - name: "Run tests"
        run: scripts/test
 
      - name: "Enforce coverage"
        run: scripts/coverage
 
  # https://github.com/marketplace/actions/alls-green#why
  check:
    timeout-minutes: 30
    if: always()
    needs: [tests]
    runs-on: latchkey-small
    steps:
      - name: Decide whether the needed jobs succeeded or failed
        uses: re-actors/alls-green@05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe # v1.2.2
        with:
          jobs: ${{ toJSON(needs) }}
 
  docs-cloudflare-preview:
    timeout-minutes: 30
    name: Docs preview (Cloudflare)
    if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
    runs-on: latchkey-small
 
    env:
      HAS_CLOUDFLARE_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN != '' }}
 
    permissions:
      contents: read
      pull-requests: write
 
    environment:
      name: cloudflare
 
    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.11"
          enable-cache: false
 
      - name: Install dependencies
        run: scripts/install
 
      - name: Build docs
        run: uv run zensical build --clean
 
      - uses: cloudflare/wrangler-action@ebbaa1584979971c8614a24965b4405ff95890e0 # v4.0.0
        id: deploy
        if: ${{ env.HAS_CLOUDFLARE_TOKEN == 'true' }}
        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
        if: ${{ steps.deploy.outcome == 'success' }}
        uses: marocchino/sticky-pull-request-comment@0ea0beb66eb9baf113663a64ec522f60e49231c0 # v3.0.4
        with:
          message: |
            **Docs preview:** ${{ steps.deploy.outputs.deployment-url }}
 

What changed

This workflow runs 3 jobs (7 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