|
1 | 1 | name: lint_pull_request
|
2 | 2 | on: [pull_request, push]
|
3 | 3 | jobs:
|
4 |
| - lint_pull_request: |
| 4 | + check_changes: |
5 | 5 | runs-on: ubuntu-24.04
|
| 6 | + outputs: |
| 7 | + has_python_changes: ${{ steps.changed-files.outputs.has_python_changes }} |
| 8 | + files: ${{ steps.changed-files.outputs.files }} |
6 | 9 | steps:
|
7 | 10 | - uses: actions/checkout@v3
|
8 | 11 | with:
|
@@ -30,48 +33,89 @@ jobs:
|
30 | 33 | - name: PR information
|
31 | 34 | if: ${{ github.event_name == 'pull_request' && steps.changed-files.outputs.has_python_changes == 'false' }}
|
32 | 35 | run: echo "This PR contains no Python changes, but still requires manual approval."
|
| 36 | + |
| 37 | + lint: |
| 38 | + needs: check_changes |
| 39 | + if: ${{ needs.check_changes.outputs.has_python_changes == 'true' }} |
| 40 | + runs-on: ubuntu-24.04 |
| 41 | + strategy: |
| 42 | + fail-fast: false |
| 43 | + matrix: |
| 44 | + tool: [flake8, format, mypy, pytest, pyupgrade, tox] |
| 45 | + steps: |
| 46 | + - uses: actions/checkout@v3 |
| 47 | + with: |
| 48 | + fetch-depth: 0 |
33 | 49 |
|
34 | 50 | - uses: actions/setup-python@v4
|
35 |
| - if: ${{ steps.changed-files.outputs.has_python_changes == 'true' }} |
36 | 51 | with:
|
37 | 52 | python-version: 3.12
|
38 | 53 |
|
| 54 | + - uses: actions/cache@v3 |
| 55 | + with: |
| 56 | + path: ~/.cache/pip |
| 57 | + key: ${{ runner.os }}-pip-${{ hashFiles('requirements-dev.txt') }} |
| 58 | + restore-keys: | |
| 59 | + ${{ runner.os }}-pip- |
| 60 | + |
39 | 61 | - name: Install dependencies
|
40 |
| - if: ${{ steps.changed-files.outputs.has_python_changes == 'true' }} |
41 | 62 | run: |
|
42 | 63 | python -m pip install --upgrade pip
|
43 | 64 | pip install -r requirements-dev.txt
|
44 |
| - |
| 65 | + |
| 66 | + # Flake8 linting |
45 | 67 | - name: Lint with flake8
|
46 |
| - if: ${{ steps.changed-files.outputs.has_python_changes == 'true' }} |
| 68 | + if: ${{ matrix.tool == 'flake8' }} |
| 69 | + id: flake8 |
47 | 70 | run: |
|
48 |
| - echo "Linting files: ${{ steps.changed-files.outputs.files }}" |
49 |
| - flake8 ${{ steps.changed-files.outputs.files }} --count --show-source --statistics |
50 |
| - |
51 |
| - - name: Format check with isort and black |
52 |
| - if: ${{ steps.changed-files.outputs.has_python_changes == 'true' }} |
| 71 | + echo "Linting files: ${{ needs.check_changes.outputs.files }}" |
| 72 | + flake8 ${{ needs.check_changes.outputs.files }} --count --show-source --statistics |
| 73 | + |
| 74 | + # Format checking with isort and black |
| 75 | + - name: Format check |
| 76 | + if: ${{ matrix.tool == 'format' }} |
| 77 | + id: format |
53 | 78 | run: |
|
54 |
| - echo "Checking format with isort for: ${{ steps.changed-files.outputs.files }}" |
55 |
| - isort --profile black --check ${{ steps.changed-files.outputs.files }} |
56 |
| - echo "Checking format with black for: ${{ steps.changed-files.outputs.files }}" |
57 |
| - black --check ${{ steps.changed-files.outputs.files }} |
58 |
| - |
| 79 | + echo "Checking format with isort for: ${{ needs.check_changes.outputs.files }}" |
| 80 | + isort --profile black --check ${{ needs.check_changes.outputs.files }} |
| 81 | + echo "Checking format with black for: ${{ needs.check_changes.outputs.files }}" |
| 82 | + black --check ${{ needs.check_changes.outputs.files }} |
| 83 | + |
| 84 | + # Type checking with mypy |
59 | 85 | - name: Type check with mypy
|
60 |
| - if: ${{ steps.changed-files.outputs.has_python_changes == 'true' }} |
| 86 | + if: ${{ matrix.tool == 'mypy' }} |
| 87 | + id: mypy |
61 | 88 | run: |
|
62 |
| - echo "Type checking: ${{ steps.changed-files.outputs.files }}" |
63 |
| - mypy --ignore-missing-imports ${{ steps.changed-files.outputs.files }} |
64 |
| - |
| 89 | + echo "Type checking: ${{ needs.check_changes.outputs.files }}" |
| 90 | + mypy --ignore-missing-imports ${{ needs.check_changes.outputs.files }} |
| 91 | + |
| 92 | + # Run tests with pytest |
65 | 93 | - name: Run tests with pytest
|
66 |
| - if: ${{ steps.changed-files.outputs.has_python_changes == 'true' }} |
| 94 | + if: ${{ matrix.tool == 'pytest' }} |
| 95 | + id: pytest |
67 | 96 | run: |
|
68 | 97 | pytest ./patterns
|
69 | 98 | pytest --doctest-modules ./patterns || true
|
70 |
| - |
| 99 | + |
| 100 | + # Check Python version compatibility |
71 | 101 | - name: Check Python version compatibility
|
72 |
| - if: ${{ steps.changed-files.outputs.has_python_changes == 'true' }} |
73 |
| - run: pyupgrade --py312-plus ${{ steps.changed-files.outputs.files }} |
74 |
| - |
| 102 | + if: ${{ matrix.tool == 'pyupgrade' }} |
| 103 | + id: pyupgrade |
| 104 | + run: pyupgrade --py312-plus ${{ needs.check_changes.outputs.files }} |
| 105 | + |
| 106 | + # Run tox |
75 | 107 | - name: Run tox
|
76 |
| - if: ${{ steps.changed-files.outputs.has_python_changes == 'true' }} |
| 108 | + if: ${{ matrix.tool == 'tox' }} |
| 109 | + id: tox |
77 | 110 | run: tox
|
| 111 | + |
| 112 | + summary: |
| 113 | + needs: [check_changes, lint] |
| 114 | + if: ${{ always() && needs.check_changes.outputs.has_python_changes == 'true' }} |
| 115 | + runs-on: ubuntu-24.04 |
| 116 | + steps: |
| 117 | + - name: Summarize results |
| 118 | + run: | |
| 119 | + echo "## Pull Request Lint Results" >> $GITHUB_STEP_SUMMARY |
| 120 | + echo "Linting has completed for all Python files changed in this PR." >> $GITHUB_STEP_SUMMARY |
| 121 | + echo "See individual job logs for detailed results." >> $GITHUB_STEP_SUMMARY |
0 commit comments