1- name : Pre-commit Black Check
1+ name : Pre-commit Auto-fix and Comment
22
33on :
44 push :
1010
1111jobs :
1212 pre-commit :
13- name : Run Pre-commit Hooks
13+ name : Run Pre-commit Hooks, Auto-fix, and Comment
1414 runs-on : ubuntu-latest
1515
1616 steps :
1717 - name : Checkout repository
1818 uses : actions/checkout@v4
19+ with :
20+ token : ${{ secrets.GITHUB_TOKEN }}
1921
2022 - name : Set up Python
2123 uses : actions/setup-python@v4
2527 - name : Install pre-commit
2628 run : pip install pre-commit
2729
28- - name : Run pre-commit
29- run : pre-commit run --all-files --verbose
30+ - name : Run pre-commit and fix files
31+ id : precommit_run
32+ run : pre-commit run --all-files --verbose --hook-stage manual
33+
34+ - name : Commit and push changes if any
35+ id : commit_push
36+ run : |
37+ git config user.name "github-actions[bot]"
38+ 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)"
44+ git push
45+ echo "no_changes=false" >> $GITHUB_ENV
46+ fi
47+
48+ - name : Comment on PR if changes were pushed
49+ if : env.no_changes == 'false' && github.event_name == 'pull_request'
50+ uses : actions/github-script@v7
51+ with :
52+ script : |
53+ github.rest.issues.createComment({
54+ issue_number: context.issue.number,
55+ owner: context.repo.owner,
56+ repo: context.repo.repo,
57+ body: "✅ Pre-commit hooks automatically fixed some issues (black, isort) and changes were pushed!"
58+ })
0 commit comments