forked from open-algebra/Oasis
-
Notifications
You must be signed in to change notification settings - Fork 0
81 lines (70 loc) · 3.12 KB
/
code-coverage-comment.yml
File metadata and controls
81 lines (70 loc) · 3.12 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
69
70
71
72
73
74
75
76
77
78
79
80
81
# ##############################################################################
# OASIS: Open Algebra Software for Inferring Solutions
#
# code-coverage-comment.yml
# ##############################################################################
name: Code Coverage Comment
on:
workflow_run:
workflows: [ "Code Coverage" ]
types:
- completed
permissions:
contents: read
issues: write
pull-requests: write
jobs:
write-comment:
runs-on: ubuntu-latest
if: |
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
steps:
# Downloads the artifacts uploaded by the pull request workflow run.
- name: Download artifacts
uses: actions/github-script@v6
with:
script: |
let artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
let matchArtifact1 = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "pr-number"
})[0];
let download1 = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact1.id,
archive_format: 'zip',
});
let matchArtifact2 = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "build-test-cover"
})[0];
let download2 = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact2.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync('${{github.workspace}}/pr-number.zip', Buffer.from(download1.data));
fs.writeFileSync('${{github.workspace}}/build-test-cover.zip', Buffer.from(download2.data));
# Unzips the artifacts.
- name: Unzip artifacts
run: unzip \*.zip
# Writes a comment on the pull request.
- name: Comment on PR
uses: actions/github-script@v6
with:
script: |
let fs = require('fs');
let issue_number = Number(fs.readFileSync('./issue_number'));
let coverage_file = fs.readFileSync('./coverage/reports/index.txt');
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: '```\n' + coverage_file + '\n```'
});