Skip to content
Latchkey

Build Docs workflow (tiangolo/sqlmodel)

The Build Docs workflow from tiangolo/sqlmodel, explained and optimized by Latchkey.

C

CI health: C - fair

The optimized version below adds caching, run de-duplication.

Source: tiangolo/sqlmodel.github/workflows/build-docs.ymlLicense MITView source

What it does

This is the Build Docs workflow from the tiangolo/sqlmodel 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: Build Docs
on:
  push:
    branches:
      - main
  pull_request:
permissions: {}

jobs:
  changes:
    runs-on: ubuntu-latest
    # Required permissions
    permissions:
      pull-requests: read
    timeout-minutes: 5
    # Set job outputs to values from filter step
    outputs:
      docs: ${{ steps.filter.outputs.docs }}
    steps:
    - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
    # For pull requests it's not necessary to checkout the code but for the main branch it is
      with:
        persist-credentials: false
    - uses: dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4.0.1
      id: filter
      with:
        filters: |
          docs:
            - README.md
            - docs/**
            - docs_src/**
            - pyproject.toml
            - uv.lock
            - mkdocs.yml
            - mkdocs.env.yml
            - .github/workflows/build-docs.yml
            - .github/workflows/deploy-docs.yml
            - data/**

  build-docs:
    needs:
      - changes
    if: ${{ needs.changes.outputs.docs == 'true' }}
    runs-on: ubuntu-latest
    timeout-minutes: 5
    steps:
      - name: Dump GitHub context
        env:
          GITHUB_CONTEXT: ${{ toJson(github) }}
        run: echo "$GITHUB_CONTEXT"
      - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
        with:
          persist-credentials: false
      - name: Set up Python
        uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
        with:
          python-version-file: ".python-version"
      - name: Setup uv
        uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
        with:
          # Before upgrading uv version, make sure astral-sh/setup-uv knows its checksum.
          # See: https://github.com/astral-sh/setup-uv/issues/851#issuecomment-4282017837
          version: "0.11.18"
          enable-cache: true
          cache-dependency-glob: |
            pyproject.toml
            uv.lock
      - name: Install docs extras
        run: uv sync --locked --no-dev --group docs
      - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
        with:
          key: mkdocs-cards-${{ github.ref }}
          path: .cache
      - name: Build Docs
        run: uv run ./scripts/docs.py build
      - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: docs-site
          path: ./site/**
          include-hidden-files: true

  # https://github.com/marketplace/actions/alls-green#why
  docs-all-green:  # This job does nothing and is only used for the branch protection
    if: always()
    needs:
      - build-docs
    runs-on: ubuntu-latest
    timeout-minutes: 5
    steps:
      - name: Decide whether the needed jobs succeeded or failed
        uses: re-actors/alls-green@05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe # v1.2.2
        with:
          jobs: ${{ toJSON(needs) }}
          allowed-skips: build-docs

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: Build Docson:  push:    branches:      - main  pull_request:permissions: {} concurrency:  group: ${{ github.workflow }}-${{ github.ref }}  cancel-in-progress: true jobs:  changes:    runs-on: latchkey-small    # Required permissions    permissions:      pull-requests: read    timeout-minutes: 5    # Set job outputs to values from filter step    outputs:      docs: ${{ steps.filter.outputs.docs }}    steps:    - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0    # For pull requests it's not necessary to checkout the code but for the main branch it is      with:        persist-credentials: false    - uses: dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4.0.1      id: filter      with:        filters: |          docs:            - README.md            - docs/**            - docs_src/**            - pyproject.toml            - uv.lock            - mkdocs.yml            - mkdocs.env.yml            - .github/workflows/build-docs.yml            - .github/workflows/deploy-docs.yml            - data/**   build-docs:    needs:      - changes    if: ${{ needs.changes.outputs.docs == 'true' }}    runs-on: latchkey-small    timeout-minutes: 5    steps:      - name: Dump GitHub context        env:          GITHUB_CONTEXT: ${{ toJson(github) }}        run: echo "$GITHUB_CONTEXT"      - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0        with:          persist-credentials: false      - name: Set up Python        uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0        with:          cache: 'pip'          python-version-file: ".python-version"      - name: Setup uv        uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0        with:          # Before upgrading uv version, make sure astral-sh/setup-uv knows its checksum.          # See: https://github.com/astral-sh/setup-uv/issues/851#issuecomment-4282017837          version: "0.11.18"          enable-cache: true          cache-dependency-glob: |            pyproject.toml            uv.lock      - name: Install docs extras        run: uv sync --locked --no-dev --group docs      - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0        with:          key: mkdocs-cards-${{ github.ref }}          path: .cache      - name: Build Docs        run: uv run ./scripts/docs.py build      - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1        with:          name: docs-site          path: ./site/**          include-hidden-files: true   # https://github.com/marketplace/actions/alls-green#why  docs-all-green:  # This job does nothing and is only used for the branch protection    if: always()    needs:      - build-docs    runs-on: latchkey-small    timeout-minutes: 5    steps:      - name: Decide whether the needed jobs succeeded or failed        uses: re-actors/alls-green@05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe # v1.2.2        with:          jobs: ${{ toJSON(needs) }}          allowed-skips: build-docs 

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 uses latchkey-small; pick the runner size that fits the job.
  • Cancel superseded runs when a branch or PR gets a newer push.
  • Cache dependency installs on the setup step so they are served from cache.

This workflow runs 3 jobs per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow

Frequently asked questions

What does the Build Docs workflow (tiangolo/sqlmodel) workflow do?
This is the Build Docs workflow from the tiangolo/sqlmodel repository, a real project running GitHub Actions. It is shown here with attribution under its MIT license.
What CI health grade does this workflow get?
This Python workflow grades C. Paste your own workflow into the Latchkey grader to see its grade and the exact fixes.
How can I improve this Python workflow?
Apply caching, run de-duplication. Latchkey applies these automatically on managed runners when you point runs-on at Latchkey.

References