Skip to content

Commit 333bde6

Browse files
authored
Apply lint to contributor PR on demand (#1280)
* Apply lint to contributor PR on demand * Update ruff_linter.yml * Update ruff_linter.yml * Update ruff_linter.yml
1 parent c546c5c commit 333bde6

File tree

1 file changed

+57
-7
lines changed

1 file changed

+57
-7
lines changed

.github/workflows/ruff_linter.yml

+57-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
name: Code Analysis with Ruff
22

33
on:
4+
workflow_dispatch:
5+
inputs:
6+
pr_url:
7+
description: 'URL of the PR to fix'
8+
required: true
9+
type: string
410
push:
511
branches:
612
- main
@@ -13,30 +19,74 @@ on:
1319
jobs:
1420
build:
1521
runs-on: ubuntu-latest
22+
permissions:
23+
contents: write
24+
pull-requests: write
25+
1626
strategy:
1727
matrix:
1828
python-version: ["3.9"]
1929
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+
2037
- 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+
2155
- name: Set up Python ${{ matrix.python-version }}
2256
uses: actions/setup-python@v3
2357
with:
2458
python-version: ${{ matrix.python-version }}
59+
2560
- name: Install dependencies
2661
run: |
2762
python -m pip install --upgrade pip
2863
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'
3067
run: |
3168
ruff check .
32-
- name: Check *all* Python files for F821, F823, and W191
33-
run: |
3469
# --isolated is used to skip the allowlist at all so this applies to all files
3570
# please be careful when using this large changes means everyone needs to rebase
3671
ruff check --isolated --select F821,F823,W191
37-
- name: Check the allow-listed files for F,I
38-
run: |
3972
ruff check --select F,I
40-
- name: Check the allow-listed files for well formatted code
41-
run: |
4273
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

Comments
 (0)