Skip to content

Commit 2a7332c

Browse files
committed
ci(pre-commit): Enforce that the pre-commit checks are run before merge
1 parent a45b5af commit 2a7332c

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

.github/workflows/pre-commit.yml

+40-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ name: Pre-commit check
22

33
on:
44
pull_request:
5-
types: [opened, reopened, synchronize, labeled]
5+
types: [opened, reopened, synchronize, labeled, unlabeled]
6+
7+
permissions:
8+
statuses: write
69

710
jobs:
811
lint:
@@ -60,3 +63,39 @@ jobs:
6063
if: always()
6164
with:
6265
msg: "ci(pre-commit): Apply automatic fixes"
66+
67+
report-run:
68+
name: Check if the PR has run the pre-commit checks
69+
needs: lint
70+
if: always()
71+
runs-on: ubuntu-latest
72+
steps:
73+
- name: Report success
74+
if: |
75+
contains(github.event.pull_request.labels.*.name, 'Status: Pending Merge') &&
76+
needs.lint.result == 'success'
77+
uses: actions/github-script@v7
78+
with:
79+
script: |
80+
github.rest.repos.createCommitStatus({
81+
owner: context.repo.owner,
82+
repo: context.repo.repo,
83+
sha: ${{ github.event.pull_request.head.sha }},
84+
state: 'success',
85+
context: 'pre-commit-result',
86+
description: 'All pre-commit checks passed',
87+
});
88+
89+
- name: Report pending
90+
env:
91+
GH_TOKEN: ${{ github.token }}
92+
if: |
93+
!contains(github.event.pull_request.labels.*.name, 'Status: Pending Merge') ||
94+
needs.lint.result == 'failure'
95+
run: |
96+
gh api \
97+
--method POST \
98+
-H "Accept: application/vnd.github+json" \
99+
-H "X-GitHub-Api-Version: 2022-11-28" \
100+
/repos/${{ github.repository }}/statuses/${{ github.sha }} \
101+
-f state=pending -f context=pre-commit-result -f description="Pre-commit checks need to pass before merging"

0 commit comments

Comments
 (0)