Skip to content

Commit 6faed74

Browse files
committed
Update black gh action to only create PR if black finds an issue
1 parent 1a4b36f commit 6faed74

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

.github/workflows/black.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
steps:
1313
- uses: actions/checkout@v4
1414
with:
15-
ref: ${{ github.head_ref }}
15+
fetch-depth: 0
1616

1717
- name: Set up Python
1818
uses: actions/setup-python@v4
@@ -23,9 +23,18 @@ jobs:
2323
run: pip install black
2424

2525
- name: Run Black
26+
id: black
27+
continue-on-error: true
28+
run: |
29+
black --check bbox_visualizer/bbox_visualizer.py tests/test_bbox_visualizer.py
30+
echo "has_changes=$?" >> $GITHUB_OUTPUT
31+
32+
- name: Format with Black if needed
33+
if: steps.black.outputs.has_changes == '1'
2634
run: black bbox_visualizer/bbox_visualizer.py tests/test_bbox_visualizer.py
2735

2836
- name: Create Pull Request
37+
if: steps.black.outputs.has_changes == '1'
2938
uses: peter-evans/create-pull-request@v5
3039
with:
3140
commit-message: "style: format code with Black"
@@ -35,4 +44,6 @@ jobs:
3544
3645
This PR was automatically created by the Black formatting GitHub Action.
3746
branch: format-code-with-black
38-
delete-branch: true
47+
base: main
48+
delete-branch: true
49+
token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)