-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcommit-check-workflow-b.yml
More file actions
68 lines (60 loc) · 2.26 KB
/
Copy pathcommit-check-workflow-b.yml
File metadata and controls
68 lines (60 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Workflow B: Post PR comment after commit checks complete.
#
# This workflow is triggered by the workflow_run event from Workflow A.
# It runs in the base repository's context with full write permissions,
# making it safe for fork PRs (no checkout of fork code).
#
# Prerequisites:
# - Workflow A (commit-check.yml) must exist and upload an artifact named
# commit-check-result-<PR-number> containing result.txt
#
# See https://github.com/commit-check/commit-check-action#fork-pr-comments
name: Commit Check Comment
on:
workflow_run:
workflows: ["Commit Check"] # must match Workflow A's name exactly
types: [completed]
jobs:
comment:
runs-on: ubuntu-latest
permissions:
pull-requests: write
actions: read # needed to download artifacts
steps:
- uses: actions/download-artifact@v4
with:
name: commit-check-result-${{ github.event.workflow_run.pull_requests[0].number }}
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ github.token }}
- name: Read result and post PR comment
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const prNumber = ${{ github.event.workflow_run.pull_requests[0].number }};
const resultText = fs.readFileSync('result.txt', 'utf8').trim();
const successTitle = '# Commit-Check ✔️';
const failureTitle = '# Commit-Check ❌';
const body = resultText
? `${failureTitle}\n\`\`\`\n${resultText}\n\`\`\``
: successTitle;
const { data: comments } = await github.rest.issues.listComments({
...context.repo,
issue_number: prNumber,
});
const existing = comments.find(c =>
c.body.startsWith(successTitle) || c.body.startsWith(failureTitle)
);
if (existing) {
await github.rest.issues.updateComment({
...context.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
...context.repo,
issue_number: prNumber,
body,
});
}