Skip to content

Commit 4104c56

Browse files
committed
Merge branch 'fix/pre-commit-fork'
2 parents 0dbaa3f + 9e9b0f8 commit 4104c56

File tree

2 files changed

+83
-20
lines changed

2 files changed

+83
-20
lines changed

.github/workflows/pre-commit-status.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99

1010
permissions:
1111
statuses: write
12+
pull-requests: write
1213

1314
jobs:
1415
report-success:
@@ -62,3 +63,71 @@ jobs:
6263
target_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}'
6364
})).data;
6465
core.info(`${name} is ${state}`);
66+
67+
manage-labels:
68+
name: Manage PR labels
69+
if: github.event.workflow_run.event == 'pull_request'
70+
runs-on: ubuntu-latest
71+
steps:
72+
- name: Download and Extract Artifacts
73+
uses: dawidd6/action-download-artifact@07ab29fd4a977ae4d2b275087cf67563dfdf0295 # v9
74+
continue-on-error: true
75+
with:
76+
run_id: ${{ github.event.workflow_run.id }}
77+
name: pr-artifacts
78+
path: ./pr-artifacts
79+
80+
- name: Get PR information
81+
id: pr-info
82+
run: |
83+
if [ -f "./pr-artifacts/pr_number.txt" ]; then
84+
pr_number=$(cat ./pr-artifacts/pr_number.txt | tr -cd '[:digit:]')
85+
pre_commit_outcome=$(cat ./pr-artifacts/pre_commit_outcome.txt | tr -cd '[:alpha:]_')
86+
pending_commit=$(cat ./pr-artifacts/pending_commit.txt | tr -cd '[:digit:]')
87+
has_retrigger_label=$(cat ./pr-artifacts/has_retrigger_label.txt | tr -cd '[:alpha:]')
88+
89+
echo "pr_number=$pr_number" >> $GITHUB_OUTPUT
90+
echo "pre_commit_outcome=$pre_commit_outcome" >> $GITHUB_OUTPUT
91+
echo "pending_commit=$pending_commit" >> $GITHUB_OUTPUT
92+
echo "has_retrigger_label=$has_retrigger_label" >> $GITHUB_OUTPUT
93+
echo "artifacts_found=true" >> $GITHUB_OUTPUT
94+
95+
echo "PR number: $pr_number"
96+
echo "Pre-commit outcome: $pre_commit_outcome"
97+
echo "Pending commit: $pending_commit"
98+
echo "Has retrigger label: $has_retrigger_label"
99+
else
100+
echo "No PR artifacts found"
101+
echo "artifacts_found=false" >> $GITHUB_OUTPUT
102+
fi
103+
104+
- name: Remove re-trigger label if it was present
105+
if: |
106+
steps.pr-info.outputs.artifacts_found == 'true' &&
107+
steps.pr-info.outputs.has_retrigger_label == 'true'
108+
continue-on-error: true
109+
run: |
110+
gh pr edit ${{ steps.pr-info.outputs.pr_number }} --repo ${{ github.repository }} --remove-label 'Re-trigger Pre-commit Hooks'
111+
env:
112+
GH_TOKEN: ${{ github.token }}
113+
114+
- name: Add label if pre-commit fixes are required
115+
if: |
116+
steps.pr-info.outputs.artifacts_found == 'true' &&
117+
steps.pr-info.outputs.pre_commit_outcome == 'failure' &&
118+
steps.pr-info.outputs.pending_commit == '0'
119+
continue-on-error: true
120+
run: |
121+
gh pr edit ${{ steps.pr-info.outputs.pr_number }} --repo ${{ github.repository }} --add-label 'Status: Pre-commit fixes required ⚠️'
122+
env:
123+
GH_TOKEN: ${{ github.token }}
124+
125+
- name: Remove label if pre-commit was successful
126+
if: |
127+
steps.pr-info.outputs.artifacts_found == 'true' &&
128+
steps.pr-info.outputs.pre_commit_outcome == 'success'
129+
continue-on-error: true
130+
run: |
131+
gh pr edit ${{ steps.pr-info.outputs.pr_number }} --repo ${{ github.repository }} --remove-label 'Status: Pre-commit fixes required ⚠️'
132+
env:
133+
GH_TOKEN: ${{ github.token }}

.github/workflows/pre-commit.yml

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,6 @@ jobs:
3131
with:
3232
fetch-depth: 2
3333

34-
- name: Remove Label
35-
if: contains(github.event.pull_request.labels.*.name, 'Re-trigger Pre-commit Hooks')
36-
run: gh pr edit ${{ github.event.number }} --remove-label 'Re-trigger Pre-commit Hooks'
37-
continue-on-error: true
38-
env:
39-
GH_TOKEN: ${{ github.token }}
40-
4134
- name: Set up Python 3
4235
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.0.4
4336
with:
@@ -85,19 +78,20 @@ jobs:
8578
with:
8679
msg: "ci(pre-commit): Apply automatic fixes"
8780

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
81+
- name: Save workflow information for labeling
82+
if: ${{ always() && github.event_name == 'pull_request' }}
9183
run: |
92-
gh pr edit ${{ github.event.number }} --add-label 'Status: Pre-commit fixes required ⚠️'
93-
env:
94-
GH_TOKEN: ${{ github.token }}
84+
mkdir -p ./pr-artifacts
85+
echo "${{ github.event.number }}" > ./pr-artifacts/pr_number.txt
86+
echo "${{ steps.pre-commit.outcome }}" > ./pr-artifacts/pre_commit_outcome.txt
87+
echo "${{ steps.pre-commit.outputs.pending_commit }}" > ./pr-artifacts/pending_commit.txt
88+
echo "${{ contains(github.event.pull_request.labels.*.name, 'Re-trigger Pre-commit Hooks') }}" > ./pr-artifacts/has_retrigger_label.txt
9589
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 }}
90+
- name: Upload PR artifacts
91+
if: ${{ always() && github.event_name == 'pull_request' }}
92+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
93+
with:
94+
name: pr-artifacts
95+
path: ./pr-artifacts/
96+
retention-days: 1
10397

0 commit comments

Comments
 (0)