Skip to content

Commit 936146c

Browse files
committed
ci(pre-commit): Fix PR checks and cache
1 parent 4070a87 commit 936146c

File tree

2 files changed

+62
-30
lines changed

2 files changed

+62
-30
lines changed
+50-28
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,63 @@
11
name: Report Pre-commit Check Status
22

33
on:
4-
pull_request_target:
5-
types: [opened, reopened, synchronize, labeled, unlabeled]
4+
workflow_run:
5+
workflows: [Pre-commit hooks]
6+
types:
7+
- completed
68

79
permissions:
810
statuses: write
911

1012
jobs:
11-
report-run:
12-
name: Check if the PR has run the pre-commit checks
13+
report-success:
14+
name: Report pre-commit success
15+
if: github.event.workflow_run.conclusion == 'success'
1316
runs-on: ubuntu-latest
1417
steps:
15-
- name: Report pending
16-
uses: conda/actions/[email protected]
17-
with:
18-
context: "Pre-commit checks"
19-
state: pending
20-
description: The pre-commit checks need to be successful before merging
21-
22-
- name: Wait for pre-commit checks to complete
23-
uses: lucasssvaz/wait-on-workflow@v1
24-
if: |
25-
contains(github.event.pull_request.labels.*.name, 'Status: Pending Merge')
26-
id: wait-on-workflow
18+
- name: Report success
19+
uses: actions/github-script@v7
2720
with:
28-
timeout: 10
29-
interval: 30
30-
workflow: pre-commit.yml
31-
sha: ${{ github.event.pull_request.head.sha || github.sha }}
21+
script: |
22+
const owner = '${{ github.repository_owner }}';
23+
const repo = '${{ github.repository }}'.split('/')[1];
24+
const sha = '${{ github.event.workflow_run.head_sha }}';
25+
core.debug(`owner: ${owner}`);
26+
core.debug(`repo: ${repo}`);
27+
core.debug(`sha: ${sha}`);
28+
const { context: name, state } = (await github.rest.repos.createCommitStatus({
29+
context: 'Pre-commit checks',
30+
description: 'Pre-commit checks successful',
31+
owner: owner,
32+
repo: repo,
33+
sha: sha,
34+
state: 'success',
35+
target_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}'
36+
})).data;
37+
core.info(`${name} is ${state}`);
3238
33-
- name: Report success
34-
uses: conda/actions/[email protected]
35-
if: |
36-
contains(github.event.pull_request.labels.*.name, 'Status: Pending Merge') &&
37-
steps.wait-on-workflow.outputs.conclusion == 'success'
39+
report-pending:
40+
name: Report pre-commit pending
41+
if: github.event.workflow_run.conclusion != 'success'
42+
runs-on: ubuntu-latest
43+
steps:
44+
- name: Report pending
45+
uses: actions/github-script@v7
3846
with:
39-
context: "Pre-commit checks"
40-
state: success
41-
description: All pre-commit checks passed
47+
script: |
48+
const owner = '${{ github.repository_owner }}';
49+
const repo = '${{ github.repository }}'.split('/')[1];
50+
const sha = '${{ github.event.workflow_run.head_sha }}';
51+
core.debug(`owner: ${owner}`);
52+
core.debug(`repo: ${repo}`);
53+
core.debug(`sha: ${sha}`);
54+
const { context: name, state } = (await github.rest.repos.createCommitStatus({
55+
context: 'Pre-commit checks',
56+
description: 'The pre-commit checks need to be successful before merging',
57+
owner: owner,
58+
repo: repo,
59+
sha: sha,
60+
state: 'pending',
61+
target_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}'
62+
})).data;
63+
core.info(`${name} is ${state}`);

.github/workflows/pre-commit.yml

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
name: Pre-commit hooks
22

33
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- master
48
pull_request:
59
types: [opened, reopened, synchronize, labeled, unlabeled]
610

11+
concurrency:
12+
group: pre-commit-${{github.event.pull_request.number || github.ref}}
13+
cancel-in-progress: true
14+
715
jobs:
816
lint:
917
if: |
10-
contains(github.event.pull_request.labels.*.name, 'Status: Pending Merge')
18+
contains(github.event.pull_request.labels.*.name, 'Status: Pending Merge') ||
19+
github.event_name != 'pull_request'
1120
name: Check if fixes are needed
1221
runs-on: ubuntu-latest
1322
steps:
@@ -57,6 +66,7 @@ jobs:
5766

5867
- name: Push changes using pre-commit-ci-lite
5968
uses: pre-commit-ci/[email protected]
60-
if: always()
69+
# Only push changes in PRs
70+
if: ${{ always() && github.event_name == 'pull_request' }}
6171
with:
6272
msg: "ci(pre-commit): Apply automatic fixes"

0 commit comments

Comments
 (0)