Python workflow (ekassos/swift-book-pdf)
The Python workflow from ekassos/swift-book-pdf, explained and optimized by Latchkey.
CI health: C - fair
Point runs-on at Latchkey and get caching, run de-duplication, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the Python workflow from the ekassos/swift-book-pdf repository, a real project running GitHub Actions. It is shown here with attribution under its Apache-2.0 license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
name: Python
on:
push:
branches: [main]
paths: [src/swift_book_pdf/**, tests/**, uv.lock, pyproject.toml, .github/workflows/**]
pull_request:
branches: [main]
paths: [src/swift_book_pdf/**, tests/**, uv.lock, pyproject.toml, .github/workflows/**]
jobs:
build:
name: Test Python
permissions:
contents: read
timeout-minutes: 10
runs-on: ubuntu-latest
env:
wd: ./
steps:
- name: Check out code
uses: actions/checkout@v6
- name: Setup uv
id: setup-uv
uses: astral-sh/setup-uv@e06108dd0aef18192324c70427afc47652e63a82
with:
enable-cache: true
- name: Set up Python3.x
uses: actions/setup-python@v6
with:
python-version: 3.11.6
id: py
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: 24
- name: Cache npm downloads
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-24-npm-highlightjs-latest
restore-keys: |
${{ runner.os }}-node-24-npm-
- name: Get requirements
working-directory: ${{env.wd}}
run: |
uv sync --locked --color never
- name: Linting, formatting, and type checking
working-directory: ${{env.wd}}
run: uv run pre-commit run --show-diff-on-failure --all-files
- name: Run tests
working-directory: ${{env.wd}}
env:
SWIFT_BOOK_CORPUS_TEST: "1"
run: uv run pytest
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: Python on: push: branches: [main] paths: [src/swift_book_pdf/**, tests/**, uv.lock, pyproject.toml, .github/workflows/**] pull_request: branches: [main] paths: [src/swift_book_pdf/**, tests/**, uv.lock, pyproject.toml, .github/workflows/**] concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: build: name: Test Python permissions: contents: read timeout-minutes: 10 runs-on: latchkey-small env: wd: ./ steps: - name: Check out code uses: actions/checkout@v6 - name: Setup uv id: setup-uv uses: astral-sh/setup-uv@e06108dd0aef18192324c70427afc47652e63a82 with: enable-cache: true - name: Set up Python3.x uses: actions/setup-python@v6 with: python-version: 3.11.6 id: py - name: Set up Node.js uses: actions/setup-node@v6 with: cache: 'npm' node-version: 24 - name: Cache npm downloads uses: actions/cache@v4 with: path: ~/.npm key: ${{ runner.os }}-node-24-npm-highlightjs-latest restore-keys: | ${{ runner.os }}-node-24-npm- - name: Get requirements working-directory: ${{env.wd}} run: | uv sync --locked --color never - name: Linting, formatting, and type checking working-directory: ${{env.wd}} run: uv run pre-commit run --show-diff-on-failure --all-files - name: Run tests working-directory: ${{env.wd}} env: SWIFT_BOOK_CORPUS_TEST: "1" run: uv run pytest
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 useslatchkey-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 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.