-
Notifications
You must be signed in to change notification settings - Fork 807
83 lines (70 loc) · 2.18 KB
/
code-coverage.yaml
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
82
83
name: Code Coverage
on: [pull_request]
jobs:
report-base:
name: Generate base report
runs-on: ubuntu-latest
steps:
- name: Checkout Base
uses: actions/checkout@v3
with:
ref: master
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '^1.20.2'
- name: Generate report
run: |
go test -coverprofile cover-base.out ./cmd/... ./pkg/...
- name: Upload report
uses: actions/upload-artifact@v3
with:
name: cover-base
path: cover-base.out
report-pr:
name: Generate PR report
runs-on: ubuntu-latest
steps:
- name: Checkout PR
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '^1.20.2'
- name: Generate reports
run: |
go test -coverprofile cover-pr.out ./cmd/... ./pkg/...
- name: Upload report
uses: actions/upload-artifact@v3
with:
name: cover-pr
path: cover-pr.out
code-coverage:
name: Output code coverage
runs-on: ubuntu-latest
needs: [report-base, report-pr]
steps:
- name: Download reports
uses: actions/download-artifact@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '^1.20.2'
- name: Install copherage Tool
run: go install k8s.io/test-infra/robots/coverage@latest
- name: Generate Comment
id: generate-comment
run: |
echo 'comment<<EOF' >> $GITHUB_OUTPUT
echo '<!-- pr-coverage -->' >> $GITHUB_OUTPUT
echo '## Code Coverage Diff' >> $GITHUB_OUTPUT
coverage diff cover-base/cover-base.out cover-pr/cover-pr.out | sed -e '1,5d' >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
- name: Create or Update Comment
uses: edumserrano/find-create-or-update-comment@v1
with:
issue-number: ${{ github.event.pull_request.number }}
body-includes: '<!-- pr-coverage -->'
comment-author: 'github-actions[bot]'
body: ${{ steps.generate-comment.outputs.comment }}
edit-mode: replace