|
| 1 | +# This needs to be in a separate workflow because it requires higher permissions than the calling workflow |
1 | 2 | name: Report Pre-commit Check Status |
2 | 3 |
|
3 | 4 | on: |
4 | | - pull_request_target: |
5 | | - types: [opened, reopened, synchronize, labeled, unlabeled] |
| 5 | + workflow_run: |
| 6 | + workflows: [Pre-commit hooks] |
| 7 | + types: |
| 8 | + - completed |
6 | 9 |
|
7 | 10 | permissions: |
8 | 11 | statuses: write |
9 | 12 |
|
10 | 13 | jobs: |
11 | | - report-run: |
12 | | - name: Check if the PR has run the pre-commit checks |
| 14 | + report-success: |
| 15 | + name: Report pre-commit success |
| 16 | + if: github.event.workflow_run.conclusion == 'success' |
13 | 17 | runs-on: ubuntu-latest |
14 | 18 | steps: |
15 | | - - name: Report pending |
16 | | - uses: conda/actions/set-commit-status@v24.2.0 |
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 |
| 19 | + - name: Report success |
| 20 | + uses: actions/github-script@v7 |
27 | 21 | with: |
28 | | - timeout: 10 |
29 | | - interval: 30 |
30 | | - workflow: pre-commit.yml |
31 | | - sha: ${{ github.event.pull_request.head.sha || github.sha }} |
| 22 | + script: | |
| 23 | + const owner = '${{ github.repository_owner }}'; |
| 24 | + const repo = '${{ github.repository }}'.split('/')[1]; |
| 25 | + const sha = '${{ github.event.workflow_run.head_sha }}'; |
| 26 | + core.debug(`owner: ${owner}`); |
| 27 | + core.debug(`repo: ${repo}`); |
| 28 | + core.debug(`sha: ${sha}`); |
| 29 | + const { context: name, state } = (await github.rest.repos.createCommitStatus({ |
| 30 | + context: 'Pre-commit checks', |
| 31 | + description: 'Pre-commit checks successful', |
| 32 | + owner: owner, |
| 33 | + repo: repo, |
| 34 | + sha: sha, |
| 35 | + state: 'success', |
| 36 | + target_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}' |
| 37 | + })).data; |
| 38 | + core.info(`${name} is ${state}`); |
32 | 39 |
|
33 | | - - name: Report success |
34 | | - uses: conda/actions/set-commit-status@v24.2.0 |
35 | | - if: | |
36 | | - contains(github.event.pull_request.labels.*.name, 'Status: Pending Merge') && |
37 | | - steps.wait-on-workflow.outputs.conclusion == 'success' |
| 40 | + report-pending: |
| 41 | + name: Report pre-commit pending |
| 42 | + if: github.event.workflow_run.conclusion != 'success' |
| 43 | + runs-on: ubuntu-latest |
| 44 | + steps: |
| 45 | + - name: Report pending |
| 46 | + uses: actions/github-script@v7 |
38 | 47 | with: |
39 | | - context: "Pre-commit checks" |
40 | | - state: success |
41 | | - description: All pre-commit checks passed |
| 48 | + script: | |
| 49 | + const owner = '${{ github.repository_owner }}'; |
| 50 | + const repo = '${{ github.repository }}'.split('/')[1]; |
| 51 | + const sha = '${{ github.event.workflow_run.head_sha }}'; |
| 52 | + core.debug(`owner: ${owner}`); |
| 53 | + core.debug(`repo: ${repo}`); |
| 54 | + core.debug(`sha: ${sha}`); |
| 55 | + const { context: name, state } = (await github.rest.repos.createCommitStatus({ |
| 56 | + context: 'Pre-commit checks', |
| 57 | + description: 'The pre-commit checks need to be successful before merging', |
| 58 | + owner: owner, |
| 59 | + repo: repo, |
| 60 | + sha: sha, |
| 61 | + state: 'pending', |
| 62 | + target_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}' |
| 63 | + })).data; |
| 64 | + core.info(`${name} is ${state}`); |
0 commit comments