Skip to content

Commit e7b67c3

Browse files
committed
fix: pre-commit CICD 수정
1 parent b1eabad commit e7b67c3

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

.github/workflows/pre-commit.yml

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Pre-commit Black Check
1+
name: Pre-commit Auto-fix and Comment
22

33
on:
44
push:
@@ -10,12 +10,14 @@ on:
1010

1111
jobs:
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
@@ -25,5 +27,32 @@ jobs:
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

Comments
 (0)