Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 256936e

Browse files
Merge pull request #11776 from lucasssvaz/ci/pre-commit-tag
ci(pre-commit): Add label if manual fixes are required
2 parents 6dca3d8 + 134c632 commit 256936e

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

‎.github/workflows/pre-commit.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ concurrency:
1313
cancel-in-progress: true
1414

1515
permissions:
16-
contents: write
17-
pull-requests: read
16+
contents: read
17+
pull-requests: write
1818

1919
jobs:
2020
lint:
@@ -34,6 +34,7 @@ jobs:
3434
- name: Remove Label
3535
if: contains(github.event.pull_request.labels.*.name, 'Re-trigger Pre-commit Hooks')
3636
run: gh pr edit ${{ github.event.number }} --remove-label 'Re-trigger Pre-commit Hooks'
37+
continue-on-error: true
3738
env:
3839
GH_TOKEN: ${{ github.token }}
3940

@@ -65,6 +66,7 @@ jobs:
6566
uses: tj-actions/changed-files@2f7c5bfce28377bc069a65ba478de0a74aa0ca32 # v46.0.1
6667

6768
- name: Run pre-commit hooks in changed files
69+
id: pre-commit
6870
run: pre-commit run --color=always --show-diff-on-failure --files ${{ steps.changed-files.outputs.all_changed_files }}
6971

7072
- name: Save pre-commit cache
@@ -82,3 +84,20 @@ jobs:
8284
if: ${{ always() && github.event_name == 'pull_request' }}
8385
with:
8486
msg: "ci(pre-commit): Apply automatic fixes"
87+
88+
- name: Add label if no commits are pending
89+
if: ${{ failure() && steps.pre-commit.outcome == 'failure' && steps.pre-commit.outputs.pending_commit == '0' && github.event_name == 'pull_request' }}
90+
continue-on-error: true
91+
run: |
92+
gh pr edit ${{ github.event.number }} --add-label 'Status: Pre-commit fixes required ⚠️'
93+
env:
94+
GH_TOKEN: ${{ github.token }}
95+
96+
- name: Remove label if everything was fixed
97+
if: ${{ success() && github.event_name == 'pull_request' }}
98+
continue-on-error: true
99+
run: |
100+
gh pr edit ${{ github.event.number }} --remove-label 'Status: Pre-commit fixes required ⚠️'
101+
env:
102+
GH_TOKEN: ${{ github.token }}
103+

‎.pre-commit-config.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,20 @@ repos:
108108
- id: vale
109109
language_version: "1.23.2"
110110
types_or: [markdown, rst]
111+
112+
# Always leave this last to ensure that all hooks have already run
113+
- repo: local
114+
hooks:
115+
- id: git-diff
116+
name: git diff
117+
entry: |
118+
bash -c '
119+
if [ "$CI" = "true" ]; then
120+
if git diff --exit-code; then
121+
echo "pending_commit=0" >> $GITHUB_OUTPUT
122+
else
123+
echo "pending_commit=1" >> $GITHUB_OUTPUT
124+
fi
125+
fi
126+
'
127+
language: system

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /