-
Notifications
You must be signed in to change notification settings - Fork 0
68 lines (59 loc) · 1.93 KB
/
ci.yml
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
name: CI
on:
pull_request:
types: [opened, reopened, synchronize]
push:
branches:
- 'main'
jobs:
unit_tests:
name: "Unit tests"
runs-on: ubuntu-latest
outputs:
html-coverage-url: ${{ steps.upload-html.outputs.artifact-url }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: ^1.22
- name: Test
run: go test -cover -coverprofile=coverage.txt -mod=readonly ./...
- name: Archive code coverage results
uses: actions/upload-artifact@v4
with:
name: code-coverage
path: coverage.txt
- name: Convert the plaintext coverage report to HTML
run: go tool cover -html coverage.txt -o coverage.html
- name: Upload html coverage report
id: upload-html
uses: actions/upload-artifact@v4
with:
name: code-coverage-html
path: coverage.html
code_coverage:
name: "Code coverage report"
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
needs: unit_tests
permissions:
contents: read # to download code coverage results from unit_tests job
pull-requests: write # write permission needed to comment on PR
steps:
- id: report-step
uses: fgrosse/go-coverage-report@671cf6b6dc4d7a6d8196f9259ce5d674b38782bb
with:
skip-comment: true
- name: Leave a comment with a link
uses: actions/github-script@v6
with:
script: |
const report = `${{ steps.report-step.outputs.coverage_report }}`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `[Coverage Report](${{ needs.unit_tests.outputs.html-coverage-url }})\n${report}`
})