Skip to content

Commit e75bd5c

Browse files
committed
Add coverage reports to CI
1 parent edcbd62 commit e75bd5c

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

.github/workflows/unit-tests.yml

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ on:
88
- main
99
- v2*
1010
pull_request:
11+
types: [opened, reopened, synchronize]
1112
permissions:
1213
contents: read
14+
# Needed to leave comments
15+
pull-requests: write
1316
jobs:
1417
build:
1518
runs-on: ubuntu-latest
@@ -18,4 +21,42 @@ jobs:
1821
- uses: actions/setup-go@v5
1922
with:
2023
go-version: 1.21.8
21-
- run: go test ./...
24+
- run: go test ./... -coverprofile=./cover.out -coverpkg=./...
25+
# upload the plaintext coverage report
26+
- name: Upload txt coverage report
27+
uses: actions/upload-artifact@v4
28+
with:
29+
name: code-coverage
30+
path: ./cover.out
31+
# convert the plaintext coverage report to html
32+
- run: go tool cover -html cover.out -o cover.html
33+
# upload the html coverage report
34+
- name: Upload html coverage report
35+
uses: actions/upload-artifact@v4
36+
with:
37+
name: code-coverage-html
38+
path: ./cover.html
39+
id: html-upload-step
40+
outputs:
41+
artifact-url: ${{ steps.html-upload-step.outputs.artifact-url }}
42+
43+
coverage:
44+
name: "Analyze coverage report"
45+
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'rocket-pool/smartnode'
46+
runs-on: ubuntu-latest
47+
needs: build # only run if the previous job finished successfully
48+
steps:
49+
- name: Leave a comment with a link
50+
uses: actions/github-script@v6
51+
with:
52+
script: |
53+
github.rest.issues.createComment({
54+
issue_number: context.issue.number,
55+
owner: context.repo.owner,
56+
repo: context.repo.repo,
57+
body: '[Coverage Report](${{ needs.build.outputs.artifact-url }})'
58+
})
59+
- uses: fgrosse/go-coverage-report@ff33f0f3f96d20ecb97198100852d2af288094ff
60+
with:
61+
coverage-artifact-name: "code-coverage"
62+
coverage-file-name: "cover.out"

0 commit comments

Comments
 (0)