@@ -2,19 +2,19 @@ name: Pre-commit Auto-fix and Comment
22
33on :
44 push :
5- branches :
6- - master
5+ branches : [ master ]
76 pull_request :
8- branches :
9- - master
7+ branches : [ master ]
108
119jobs :
1210 pre-commit :
13- name : Run Pre-commit Hooks, Auto-fix, and Comment
1411 runs-on : ubuntu-latest
12+ permissions :
13+ contents : write
14+ pull-requests : write
1515
1616 steps :
17- - name : Checkout repository
17+ - name : Checkout
1818 uses : actions/checkout@v4
1919 with :
2020 token : ${{ secrets.GITHUB_TOKEN }}
@@ -25,34 +25,34 @@ jobs:
2525 python-version : " 3.x"
2626
2727 - name : Install pre-commit
28- run : pip install pre-commit
28+ run : python -m pip install --upgrade pre-commit
2929
30- - name : Run pre-commit and fix files
30+ - name : Run pre-commit (auto- fix)
3131 id : precommit_run
32- run : pre-commit run --all-files --verbose --hook-stage manual
32+ continue-on-error : true
33+ run : |
34+ pre-commit run --all-files --verbose --hook-stage manual
3335
34- - name : Commit and push changes if any
36+ - name : Commit & push if changed
3537 id : commit_push
3638 run : |
37- git config user.name "github-actions[bot]"
39+ git config user.name "github-actions[bot]"
3840 git config user.email "github-actions[bot]@users.noreply.github.com"
39- git add .
40- if git diff-index --quiet HEAD; then
41- echo "no_changes=true" >> $GITHUB_ENV
42- else
43- git commit -m "style: Apply pre-commit fixes (black, isort)"
41+ if ! git diff --quiet; then
42+ git add -u
43+ git commit -m "style: apply pre-commit fixes (black, isort)" || true
4444 git push
45- echo "no_changes=false " >> $GITHUB_ENV
45+ echo "FIXES_PUSHED=true " >> $GITHUB_ENV
4646 fi
4747
48- - name : Comment on PR if changes were pushed
49- if : env.no_changes == 'false ' && github.event_name == 'pull_request'
48+ - name : Comment on PR
49+ if : env.FIXES_PUSHED == 'true ' && github.event_name == 'pull_request'
5050 uses : actions/github-script@v7
5151 with :
5252 script : |
5353 github.rest.issues.createComment({
54- issue_number: context.issue.number,
5554 owner: context.repo.owner,
5655 repo: context.repo.repo,
57- body: "✅ Pre-commit hooks automatically fixed some issues (black, isort) and changes were pushed!"
58- })
56+ issue_number: context.issue.number,
57+ body: "✅ Pre-commit hooks fixed formatting (black, isort) and the bot pushed the changes."
58+ })
0 commit comments