|
1 | 1 | name: Code Analysis with Ruff
|
2 | 2 |
|
3 | 3 | on:
|
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + pr_url: |
| 7 | + description: 'URL of the PR to fix' |
| 8 | + required: true |
| 9 | + type: string |
4 | 10 | push:
|
5 | 11 | branches:
|
6 | 12 | - main
|
|
13 | 19 | jobs:
|
14 | 20 | build:
|
15 | 21 | runs-on: ubuntu-latest
|
| 22 | + permissions: |
| 23 | + contents: write |
| 24 | + pull-requests: write |
| 25 | + |
16 | 26 | strategy:
|
17 | 27 | matrix:
|
18 | 28 | python-version: ["3.9"]
|
19 | 29 | steps:
|
| 30 | + - name: Extract PR info |
| 31 | + if: github.event_name == 'workflow_dispatch' |
| 32 | + run: | |
| 33 | + PR_URL=${{ github.event.inputs.pr_url }} |
| 34 | + PR_NUMBER=$(echo $PR_URL | grep -oE '[0-9]+$') |
| 35 | + echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV |
| 36 | + |
20 | 37 | - uses: actions/checkout@v3
|
| 38 | + if: github.event_name == 'workflow_dispatch' |
| 39 | + with: |
| 40 | + fetch-depth: 0 |
| 41 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 42 | + |
| 43 | + - name: Checkout PR branch |
| 44 | + if: github.event_name == 'workflow_dispatch' |
| 45 | + run: | |
| 46 | + gh pr checkout ${{ env.PR_NUMBER }} |
| 47 | + env: |
| 48 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 49 | + |
| 50 | + - uses: actions/checkout@v3 |
| 51 | + if: github.event_name != 'workflow_dispatch' |
| 52 | + with: |
| 53 | + fetch-depth: 0 |
| 54 | + |
21 | 55 | - name: Set up Python ${{ matrix.python-version }}
|
22 | 56 | uses: actions/setup-python@v3
|
23 | 57 | with:
|
24 | 58 | python-version: ${{ matrix.python-version }}
|
| 59 | + |
25 | 60 | - name: Install dependencies
|
26 | 61 | run: |
|
27 | 62 | python -m pip install --upgrade pip
|
28 | 63 | pip install ruff==0.6.8
|
29 |
| - - name: Analyzing the code with ruff |
| 64 | + |
| 65 | + - name: Regular lint check |
| 66 | + if: github.event_name != 'workflow_dispatch' |
30 | 67 | run: |
|
31 | 68 | ruff check .
|
32 |
| - - name: Check *all* Python files for F821, F823, and W191 |
33 |
| - run: | |
34 | 69 | # --isolated is used to skip the allowlist at all so this applies to all files
|
35 | 70 | # please be careful when using this large changes means everyone needs to rebase
|
36 | 71 | ruff check --isolated --select F821,F823,W191
|
37 |
| - - name: Check the allow-listed files for F,I |
38 |
| - run: | |
39 | 72 | ruff check --select F,I
|
40 |
| - - name: Check the allow-listed files for well formatted code |
41 |
| - run: | |
42 | 73 | ruff format --check
|
| 74 | +
|
| 75 | + - name: Apply fixes to PR |
| 76 | + if: github.event_name == 'workflow_dispatch' |
| 77 | + run: | |
| 78 | + git config --global user.name 'github-actions[bot]' |
| 79 | + git config --global user.email 'github-actions[bot]@users.noreply.github.com' |
| 80 | + |
| 81 | + # Apply fixes |
| 82 | + ruff check --select F,I --fix |
| 83 | + ruff format . |
| 84 | + |
| 85 | + # Commit and push if there are changes |
| 86 | + if [[ -n "$(git status --porcelain)" ]]; then |
| 87 | + git add . |
| 88 | + git commit -m "Apply automatic Ruff fixes" |
| 89 | + git push |
| 90 | + else |
| 91 | + echo "No fixes needed!" |
| 92 | + fi |
0 commit comments