Skip to content

Type hints (#1): Metaprogramming dynamic-class examples #98

Type hints (#1): Metaprogramming dynamic-class examples

Type hints (#1): Metaprogramming dynamic-class examples #98

Workflow file for this run

name: CI
# Gates every push and pull request: the book's examples must still match the
# Markdown, no currently-passing example may regress, the code must stay
# ty-clean and ruff-clean, and the static site must build. Tooling is managed
# by uv.
#
# On a push to master, and only after every gate passes, the freshly built site
# is published to GitHub Pages by the deploy job. Pull requests run the gates
# but do not deploy.
on:
push:
branches: [master]
pull_request:
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v6
with:
python-version: "3.14"
enable-cache: true
- name: Install pandoc
run: sudo apt-get update && sudo apt-get install -y pandoc
- name: Install tooling
run: uv sync --locked
# Hard gate: the book's code blocks must match the committed Examples/
# tree (no drift, no conflicting duplicates).
- name: Check examples match the Markdown
run: uv run python tools/extract_examples.py
- name: Extract examples for running
run: uv run python tools/extract_examples.py --write
# Hard gate: every extracted example must run cleanly (the book is fully
# modernized, so the baseline is empty; use --baseline to gate only
# regressions during future bulk work).
- name: Run examples
run: uv run python tools/run_examples.py
# Hard gate: the book's pytest examples (test_*.py) must pass.
- name: Run the book's pytest examples
run: uv run pytest ExtractedExamples
# Hard gate: the examples must stay ty-clean (zero diagnostics).
- name: Type-check examples with ty
run: uv run ty check ExtractedExamples
# Hard gate: PEP 8 lint (naming, imports, modernization) must pass.
# See pyproject [tool.ruff]; deliberate exceptions live in
# per-file-ignores.
- name: Lint examples with ruff
run: uv run ruff check ExtractedExamples
# Hard gate: the static site must build cleanly.
- name: Build the static site
run: uv run python tools/build_site.py
# On master only, hand the built site to the deploy job below.
- name: Upload Pages artifact
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
uses: actions/upload-pages-artifact@v3
with:
path: build/site
# Publishes the site to GitHub Pages (bruceeckel.github.io/ThinkingInPython),
# but only after the build job's gates have all passed, and only on master.
deploy:
needs: build
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deploy.outputs.page_url }}
concurrency:
group: pages
cancel-in-progress: true
steps:
- name: Deploy to GitHub Pages
id: deploy
uses: actions/deploy-pages@v4