|
| 1 | +name: CI Pipeline |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + branches: [main] |
| 8 | + |
| 9 | +jobs: |
| 10 | + detect-projects: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + outputs: |
| 13 | + matrix: ${{ steps.set-matrix.outputs.matrix }} |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v4 |
| 16 | + |
| 17 | + - name: Find Python projects |
| 18 | + id: set-matrix |
| 19 | + run: | |
| 20 | + # Find all directories containing both pyproject.toml and uv.lock |
| 21 | + projects=$(find . -name "pyproject.toml" -exec dirname {} \; | while read dir; do |
| 22 | + if [ -f "$dir/uv.lock" ]; then |
| 23 | + echo "$dir" |
| 24 | + fi |
| 25 | + done | sed 's|^\./||' | sed 's/.*/"&"/' | paste -sd, - | sed 's/^/[/;s/$/]/') |
| 26 | + echo "matrix={\"project\":$projects}" >> $GITHUB_OUTPUT |
| 27 | + echo "Found projects: $projects" |
| 28 | + echo "Full matrix output: {\"project\":$projects}" |
| 29 | +
|
| 30 | + lint-and-test: |
| 31 | + needs: detect-projects |
| 32 | + if: ${{ needs.detect-projects.outputs.matrix != '{"project":[]}' }} |
| 33 | + runs-on: ubuntu-latest |
| 34 | + strategy: |
| 35 | + fail-fast: false |
| 36 | + matrix: ${{ fromJson(needs.detect-projects.outputs.matrix) }} |
| 37 | + |
| 38 | + defaults: |
| 39 | + run: |
| 40 | + working-directory: ${{ matrix.project }} |
| 41 | + |
| 42 | + steps: |
| 43 | + - uses: actions/checkout@v4 |
| 44 | + |
| 45 | + - name: Extract Python version from pyproject.toml |
| 46 | + id: python-version |
| 47 | + run: | |
| 48 | + # Extract minimum Python version from requires-python |
| 49 | + version=$(grep -oP 'requires-python\s*=\s*">=\K[0-9]+\.[0-9]+' pyproject.toml || echo "3.12") |
| 50 | + echo "version=$version" >> $GITHUB_OUTPUT |
| 51 | + echo "Using Python $version for ${{ matrix.project }}" |
| 52 | +
|
| 53 | + - name: Install uv |
| 54 | + uses: astral-sh/setup-uv@v7 |
| 55 | + |
| 56 | + - name: Set up Python |
| 57 | + run: uv python install ${{ steps.python-version.outputs.version }} |
| 58 | + |
| 59 | + - name: Install dependencies |
| 60 | + run: uv sync --frozen |
| 61 | + |
| 62 | + - name: Install pre-commit |
| 63 | + run: uv tool install pre-commit |
| 64 | + |
| 65 | + - name: Run pre-commit hooks |
| 66 | + env: |
| 67 | + SKIP: ruff,ty |
| 68 | + run: | |
| 69 | + # Run pre-commit hooks only on files in this project (skip ruff/ty, we run them separately) |
| 70 | + 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 |
| 71 | +
|
| 72 | + - name: Run ruff linter |
| 73 | + run: uv run ruff check . --select "I,E,F,Q,UP,FAST" --line-length 120 |
| 74 | + |
| 75 | + - name: Run type checker |
| 76 | + run: uv run ty check || true |
| 77 | + |
| 78 | + - name: Run pytest |
| 79 | + run: | |
| 80 | + # Check if tests directory or test files exist |
| 81 | + if [ -d "tests" ] || find . -name "test_*.py" -o -name "*_test.py" | grep -q .; then |
| 82 | + uv run pytest -v |
| 83 | + else |
| 84 | + echo "No tests found in ${{ matrix.project }}" |
| 85 | + fi |
0 commit comments