Skip to content
Latchkey

Test workflow (tiangolo/uvicorn-gunicorn-fastapi-docker)

The Test workflow from tiangolo/uvicorn-gunicorn-fastapi-docker, explained and optimized by Latchkey.

D

CI health: D - needs work

Point runs-on at Latchkey and get caching, 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: tiangolo/uvicorn-gunicorn-fastapi-docker.github/workflows/test.ymlLicense MITView source

What it does

This is the Test workflow from the tiangolo/uvicorn-gunicorn-fastapi-docker 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:
  workflow_dispatch:
  schedule:
    # cron every week on monday
    - cron: "0 0 * * 1"
permissions: {}
jobs:
  test:
    permissions:
      contents: read
    strategy:
      matrix:
        image:
          - name: latest
            python_version: "3.11"
          - name: python3.11
            python_version: "3.11"
          - name: python3.10
            python_version: "3.10"
          - name: python3.11-slim
            python_version: "3.11"
          - name: python3.10-slim
            python_version: "3.10"
      fail-fast: true
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
        with:
          persist-credentials: false
      - name: Set Dockerfile name
        if: matrix.image.name != 'latest'
        run: echo "DOCKERFILE_NAME=${{ matrix.image.name }}" >> $GITHUB_ENV
      - name: Set Dockerfile name latest
        if: matrix.image.name == 'latest'
        run: echo "DOCKERFILE_NAME=python${{ matrix.image.python_version }}" >> $GITHUB_ENV
      - name: Build
        uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2.0
        with:
          push: false
          tags: tiangolo/uvicorn-gunicorn-fastapi:${{ matrix.image.name }}
          context: ./docker-images/
          file: ./docker-images/${{ env.DOCKERFILE_NAME }}.dockerfile
      - name: Set up Python
        uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
        with:
          python-version: "3.10"
      - name: Install Dependencies
        run: python -m pip install docker pytest
      - name: Test Image
        run: pytest tests
        env:
          NAME: ${{ matrix.image.name }}
          PYTHON_VERSION: ${{ matrix.image.python_version }}
  check:
    if: always()
    needs:
      - test
    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) }}

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:
  workflow_dispatch:
  schedule:
    # cron every week on monday
    - cron: "0 0 * * 1"
permissions: {}
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  test:
    timeout-minutes: 30
    permissions:
      contents: read
    strategy:
      matrix:
        image:
          - name: latest
            python_version: "3.11"
          - name: python3.11
            python_version: "3.11"
          - name: python3.10
            python_version: "3.10"
          - name: python3.11-slim
            python_version: "3.11"
          - name: python3.10-slim
            python_version: "3.10"
      fail-fast: true
    runs-on: latchkey-small
    steps:
      - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
        with:
          persist-credentials: false
      - name: Set Dockerfile name
        if: matrix.image.name != 'latest'
        run: echo "DOCKERFILE_NAME=${{ matrix.image.name }}" >> $GITHUB_ENV
      - name: Set Dockerfile name latest
        if: matrix.image.name == 'latest'
        run: echo "DOCKERFILE_NAME=python${{ matrix.image.python_version }}" >> $GITHUB_ENV
      - name: Build
        uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2.0
        with:
          push: false
          tags: tiangolo/uvicorn-gunicorn-fastapi:${{ matrix.image.name }}
          context: ./docker-images/
          file: ./docker-images/${{ env.DOCKERFILE_NAME }}.dockerfile
      - name: Set up Python
        uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
        with:
          cache: 'pip'
          python-version: "3.10"
      - name: Install Dependencies
        run: python -m pip install docker pytest
      - name: Test Image
        run: pytest tests
        env:
          NAME: ${{ matrix.image.name }}
          PYTHON_VERSION: ${{ matrix.image.python_version }}
  check:
    timeout-minutes: 30
    if: always()
    needs:
      - test
    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) }}
 

What changed

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 2 jobs (6 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