Skip to content

Commit 996f2c8

Browse files
authoredDec 7, 2023
Post coverage reports on PR runs (#1273)
* Post coverage reports on PR runs follows usage in https://github.com/Nef10/SwiftBeanCountModel/tree/main/.github/workflows and uses https://github.com/Nef10/lcov-reporter-action Change-Id: If99e81f21a1b4c2bb803f2ba948175a683387495 * Use current upload artifacts job
1 parent 80963ba commit 996f2c8

File tree

2 files changed

+64
-5
lines changed

2 files changed

+64
-5
lines changed
 

‎.github/workflows/report-coverage.yml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Comment on the pull request
2+
3+
# see https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
4+
# read-write repo token
5+
# access to secrets
6+
on:
7+
workflow_run:
8+
workflows: ["Test"]
9+
types:
10+
- completed
11+
12+
jobs:
13+
upload:
14+
runs-on: ubuntu-latest
15+
if: >
16+
github.event.workflow_run.event == 'pull_request' &&
17+
github.event.workflow_run.conclusion == 'success'
18+
steps:
19+
- name: 'Download artifact'
20+
uses: actions/github-script@v3.1.0
21+
with:
22+
script: |
23+
var artifacts = await github.actions.listWorkflowRunArtifacts({
24+
owner: context.repo.owner,
25+
repo: context.repo.repo,
26+
run_id: ${{github.event.workflow_run.id }},
27+
});
28+
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
29+
return artifact.name == "coverage"
30+
})[0];
31+
var download = await github.actions.downloadArtifact({
32+
owner: context.repo.owner,
33+
repo: context.repo.repo,
34+
artifact_id: matchArtifact.id,
35+
archive_format: 'zip',
36+
});
37+
var fs = require('fs');
38+
fs.writeFileSync('${{github.workspace}}/coverage.zip', Buffer.from(download.data));
39+
- run: unzip pr.zip
40+
- name: 'get PR number'
41+
run: echo "pr_number=$(cat ./PR)">> $GITHUB_ENV
42+
43+
- name: report coverage
44+
uses: Nef10/lcov-reporter-action@v0.4.0
45+
with:
46+
lcov-file: lcov.info
47+
pr-number: ${{ env.pr_number }}
48+
github-token: ${{ secrets.GITHUB_TOKEN }}
49+
output-file: comment.html
50+
- name: Post code coverage report
51+
uses: marocchino/sticky-pull-request-comment@v2.8.0
52+
with:
53+
path: comment.html
54+
number: ${{ env.pr_number }}

‎.github/workflows/test.yml

+10-5
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,18 @@ jobs:
8282

8383
- name: Test
8484
run: |
85-
npm run test
85+
npm run -- test --code-coverage
8686
npm run build
87-
88-
- name: Coveralls
89-
uses: coverallsapp/github-action@master
87+
# save pr number for later use
88+
# (see https://securitylab.github.com/research/github-actions-preventing-pwn-requests/)
89+
- name: Save PR number
90+
run: |
91+
echo ${{ github.event.number }} > ./coverage/PR
92+
- uses: actions/upload-artifact@v3
9093
with:
91-
github-token: ${{ secrets.GITHUB_TOKEN }}
94+
name: coverage
95+
path: coverage/
96+
9297

9398
e2etests:
9499
name: Run E2E Tests

0 commit comments

Comments
 (0)
Please sign in to comment.