Skip to content

Commit bbfbd46

Browse files
added functionally for auto formatter with git actions
1 parent be083e8 commit bbfbd46

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Check Python Code Formatting
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
jobs:
9+
format-check:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
with:
16+
persist-credentials: false
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: "3.12.x"
22+
23+
- name: Install Black
24+
run: pip install black
25+
26+
- name: Run Black
27+
run: black .
28+
29+
- name: Commit changes if formatting is needed
30+
run: |
31+
git config --local user.name "github-actions[bot]"
32+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
33+
git add .
34+
git diff --cached --exit-code || git commit -m "Auto-format code with Black"
35+
36+
- name: Push changes back to the pull request branch
37+
uses: gr2m/create-or-update-pull-request-action@v1
38+
env:
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)