Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 34 additions & 49 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,79 +7,64 @@ on:
branches: [main]

jobs:
detect-projects:
lint:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4

- name: Find Python projects
id: set-matrix
run: |
# Find all directories containing both pyproject.toml and uv.lock
projects=$(find . -name "pyproject.toml" -exec dirname {} \; | while read dir; do
if [ -f "$dir/uv.lock" ]; then
echo "$dir"
fi
done | sed 's|^\./||' | sed 's/.*/"&"/' | paste -sd, - | sed 's/^/[/;s/$/]/')
echo "matrix={\"project\":$projects}" >> $GITHUB_OUTPUT
echo "Found projects: $projects"
echo "Full matrix output: {\"project\":$projects}"
- name: Install uv
uses: astral-sh/setup-uv@v7

- name: Set up Python
run: uv python install 3.13

- name: Install dependencies
run: uv sync --frozen --all-packages

- name: Run ruff linter
run: uv run ruff check .

- name: Run type checker
run: uv run ty check || true

lint-and-test:
needs: detect-projects
if: ${{ needs.detect-projects.outputs.matrix != '{"project":[]}' }}
test:
needs: lint
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.detect-projects.outputs.matrix) }}
matrix:
include:
- name: platform-home
path: Chapter01/platform-home
- name: parents-portal
path: Chapter02/parents-portal
- name: reservation-service
path: Chapter03/reservation-service
- name: api-gateway
path: Chapter05/api-gateway
- name: sitters-catalog
path: Chapter07/sitters-catalog

defaults:
run:
working-directory: ${{ matrix.project }}
working-directory: ${{ matrix.path }}

steps:
- uses: actions/checkout@v4

- name: Extract Python version from pyproject.toml
id: python-version
run: |
# Extract minimum Python version from requires-python
version=$(grep -oP 'requires-python\s*=\s*">=\K[0-9]+\.[0-9]+' pyproject.toml || echo "3.12")
echo "version=$version" >> $GITHUB_OUTPUT
echo "Using Python $version for ${{ matrix.project }}"

- name: Install uv
uses: astral-sh/setup-uv@v7

- name: Set up Python
run: uv python install ${{ steps.python-version.outputs.version }}
run: uv python install 3.13

- name: Install dependencies
run: uv sync --frozen

- name: Install pre-commit
run: uv tool install pre-commit

- name: Run pre-commit hooks
env:
SKIP: ruff,ty
run: |
# Run pre-commit hooks only on files in this project (skip ruff/ty, we run them separately)
find . -type f \( -name "*.py" -o -name "*.toml" -o -name "*.yaml" -o -name "*.yml" -o -name "*.json" -o -name "*.md" \) -not -path "./.venv/*" | xargs uv tool run pre-commit run --config ${{ github.workspace }}/.pre-commit-config.yaml --files || true

- name: Run ruff linter
run: uv run ruff check . --select "I,E,F,Q,UP,FAST" --line-length 120

- name: Run type checker
run: uv run ty check || true
run: uv sync --frozen --all-packages

- name: Run pytest
- name: Run pytest (${{ matrix.name }})
run: |
# Check if tests directory or test files exist
if [ -d "tests" ] || find . -name "test_*.py" -o -name "*_test.py" | grep -q .; then
uv run pytest -v
else
echo "No tests found in ${{ matrix.project }}"
echo "No tests found in ${{ matrix.path }}"
fi
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/
.idea

# Abstra
# Abstra is an AI-powered process automation framework.
Expand All @@ -199,7 +199,7 @@ cython_debug/
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
# and can be added to the global gitignore or merged into this file. However, if you prefer,
# you could uncomment the following to ignore the entire vscode folder
.vscode/
.vscode

# Ruff stuff:
.ruff_cache/
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repos:
hooks:
- id: ruff
name: ruff (local)
entry: uv run ruff check --fix --select "I,E,F,Q,UP,FAST"
entry: uv run ruff check --fix
language: system
types: [python]

Expand Down
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.13
40 changes: 0 additions & 40 deletions Chapter01/platform-home/.pre-commit-config.yaml

This file was deleted.

6 changes: 0 additions & 6 deletions Chapter01/platform-home/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,3 @@ dev = [
"ruff>=0.12.8",
"ty>=0.0.8"
]

[tool.ruff]
line-length = 61

[tool.ruff.lint]
select = ["I", "E", "F", "Q", "UP", "FAST", "ARG"]
1 change: 0 additions & 1 deletion Chapter01/platform-home/test_main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from fastapi.testclient import TestClient

from main import app


Expand Down
Loading
Loading