|
| 1 | +name: PR Checks |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize] |
| 6 | + branches: |
| 7 | + - main |
| 8 | + |
| 9 | +jobs: |
| 10 | + get-changed-files: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + outputs: |
| 13 | + tasks: ${{ steps.changed.outputs.tasks }} |
| 14 | + tests: ${{ steps.changed.outputs.tests }} |
| 15 | + steps: |
| 16 | + - name: Checkout code |
| 17 | + uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Get changed Python files |
| 20 | + id: changed |
| 21 | + run: | |
| 22 | + git fetch origin ${{ github.base_ref }} |
| 23 | +
|
| 24 | + files=$(git diff --name-only origin/${{ github.base_ref }} HEAD) |
| 25 | + echo "Changed files:" |
| 26 | + echo "$files" |
| 27 | +
|
| 28 | + tasks=$(echo "$files" | grep '06/tasks/.*\.py$' | paste -sd " ") |
| 29 | + echo "Changed tasks:" |
| 30 | + echo "$tasks" |
| 31 | + echo "tasks=$tasks" >> $GITHUB_OUTPUT |
| 32 | +
|
| 33 | + tests=$(echo "$files" | grep '06/tasks/.*\.py$' | sed 's|tasks/task|test|' | paste -sd " ") |
| 34 | + echo "Corresponding tests:" |
| 35 | + echo "$tests" |
| 36 | + echo "tests=$tests" >> $GITHUB_OUTPUT |
| 37 | +
|
| 38 | + autopep8: |
| 39 | + needs: get-changed-files |
| 40 | + runs-on: ubuntu-latest |
| 41 | + if: needs.get-changed-files.outputs.tasks != '' |
| 42 | + steps: |
| 43 | + - name: Checkout code |
| 44 | + uses: actions/checkout@v4 |
| 45 | + |
| 46 | + - name: Set up Python |
| 47 | + uses: actions/setup-python@v5 |
| 48 | + with: |
| 49 | + python-version: '3.13' |
| 50 | + |
| 51 | + - name: Install autopep8 |
| 52 | + run: | |
| 53 | + python -m pip install --upgrade pip |
| 54 | + pip install autopep8 |
| 55 | +
|
| 56 | + - name: Run autopep8 on changed files |
| 57 | + run: | |
| 58 | + autopep8 --max-line-length 120 --exit-code --diff ${{ needs.get-changed-files.outputs.tasks }} |
| 59 | +
|
| 60 | + pytest: |
| 61 | + needs: get-changed-files |
| 62 | + runs-on: ubuntu-latest |
| 63 | + if: needs.get-changed-files.outputs.tests != '' |
| 64 | + steps: |
| 65 | + - name: Checkout code |
| 66 | + uses: actions/checkout@v4 |
| 67 | + |
| 68 | + - name: Set up Python |
| 69 | + uses: actions/setup-python@v5 |
| 70 | + with: |
| 71 | + python-version: '3.13' |
| 72 | + |
| 73 | + - name: Install dependencies |
| 74 | + run: | |
| 75 | + python -m pip install --upgrade pip |
| 76 | + pip install pytest |
| 77 | +
|
| 78 | + - name: Run pytest for changed files |
| 79 | + run: | |
| 80 | + pytest ${{ needs.get-changed-files.outputs.tests }} |
0 commit comments