-
-
Notifications
You must be signed in to change notification settings - Fork 148
58 lines (54 loc) · 1.78 KB
/
coverage-comment.yml
File metadata and controls
58 lines (54 loc) · 1.78 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
name: Post Coverage Comment
on:
workflow_run:
workflows: ["Build and Deploy Snapshot"]
types: [completed]
permissions:
pull-requests: write
jobs:
post-comment:
runs-on: ubuntu-24.04
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
steps:
- name: Download PR comment artifact
uses: dawidd6/action-download-artifact@v20
with:
workflow: main.yml
run_id: ${{ github.event.workflow_run.id }}
name: pr-coverage-comment
path: pr-coverage-comment/
- name: Post or update PR comment
uses: actions/github-script@v9
with:
script: |
const fs = require('fs');
const prNumber = parseInt(
fs.readFileSync('pr-coverage-comment/pr-number.txt', 'utf8').trim()
);
const commentBody = fs.readFileSync(
'pr-coverage-comment/comment-body.txt', 'utf8'
).trim();
const marker = '## :test_tube: Code Coverage Report';
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
const existing = comments.find(c => c.body.startsWith(marker));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body: commentBody,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: commentBody,
});
}