34
34
runs-on : ${{ matrix.os }}
35
35
steps :
36
36
- uses : GitHubSecurityLab/actions-permissions/monitor@v1
37
- if : ${{ matrix.os== 'ubuntu-latest' }}
37
+ if : matrix.os == 'ubuntu-latest'
38
38
with :
39
39
config : ${{ vars.PERMISSIONS_CONFIG }}
40
40
- name : Checkout repository
@@ -45,108 +45,40 @@ jobs:
45
45
uses : actions/setup-go@v5
46
46
with :
47
47
go-version-file : ' go.mod'
48
- - run : go install gotest.tools/gotestsum@latest
48
+ - run : |
49
+ go install gotest.tools/gotestsum@v1.12.3
50
+ go install github.com/mattn/goveralls@v0.0.12
49
51
- run : make unit-test
52
+ - name : Send coverage
53
+ env :
54
+ COVERALLS_TOKEN : ${{ secrets.COVERALLS_REPO_TOKEN }}
55
+ run : goveralls -parallel -coverprofile="$COVERAGE" -ignore=test/* -service=github
50
56
- name : Test Summary
51
57
id : test_summary
52
58
uses : test-summary/action@31493c76ec9e7aa675f1585d3ed6f1da69269a86
53
59
with :
54
60
paths : unit-tests.xml
55
61
if : always() && matrix.os == 'ubuntu-latest'
56
- - name : Upload coverage file
57
- if : matrix.os == 'ubuntu-latest' && github.event_name == 'pull_request'
58
- uses : actions/upload-artifact@v4
59
- with :
60
- name : coverage-file
61
- path : coverage.out
62
62
63
- code-coverage :
64
- permissions :
65
- pull-requests : write # Required to comment on PRs
66
- needs : unit-tests
67
- if : github.event_name == 'pull_request'
63
+ coverage :
68
64
runs-on : ubuntu-latest
65
+ needs : [unit-tests, e2e-tests]
69
66
steps :
70
67
- uses : GitHubSecurityLab/actions-permissions/monitor@v1
71
68
with :
72
69
config : ${{ vars.PERMISSIONS_CONFIG }}
73
70
- name : Checkout repository
74
71
uses : actions/checkout@v4
75
- with :
76
- fetch-depth : 0
77
- - name : Get merge base
78
- id : merge_base
79
- run : |
80
- MERGE_BASE=$(git merge-base "${{ github.event.pull_request.head.sha }}" "${{ github.event.pull_request.base.sha }}")
81
- echo "merge_base=$MERGE_BASE" >> "$GITHUB_OUTPUT"
82
- echo "Checking coverage against: $MERGE_BASE"
83
72
- name : Install Go
84
73
uses : actions/setup-go@v5
85
74
with :
86
75
go-version-file : ' go.mod'
87
- - name : Download coverage file
88
- uses : actions/download-artifact@v4
89
- with :
90
- name : coverage-file
91
- - name : Check coverage cache
92
- id : cache-coverage
93
- uses : actions/cache@v4
94
- with :
95
- path : coverage.base.out
96
- key : coverage-${{ steps.merge_base.outputs.merge_base }}
97
- - name : Generate base coverage
98
- if : steps.cache-coverage.outputs.cache-hit != 'true'
99
- run : |
100
- # Get coverage from base branch
101
- git checkout ${{ steps.merge_base.outputs.merge_base }}
102
- COVERAGE=coverage.base.out make unit-test
103
- - name : Save coverage to cache
104
- if : steps.cache-coverage.outputs.cache-hit != 'true'
105
- uses : actions/cache/save@v4
106
- with :
107
- path : coverage.base.out
108
- key : coverage-${{ steps.merge_base.outputs.merge_base }}
109
- - name : Compare coverage
110
- id : compare
76
+ - name : Install goveralls
77
+ run : go install github.com/mattn/goveralls@v0.0.12
78
+ - name : Send coverage
111
79
env :
112
- BASE_REF : ${{ github.base_ref }}
113
- HEAD_REF : ${{ github.head_ref }}
114
- run : |
115
- # use go tool cover to calculate coverage percentage
116
- base_coverage=$(go tool cover -func=coverage.base.out | grep total: | awk '{print $3}' | sed 's/%//')
117
- pr_coverage=$(go tool cover -func=coverage.out | grep total: | awk '{print $3}' | sed 's/%//')
118
-
119
- # Calculate difference
120
- diff=$(echo "$pr_coverage - $base_coverage" | bc)
121
- echo "diff=$diff" >> "$GITHUB_OUTPUT"
122
-
123
- # Create comment content
124
- if (( $(echo "$diff >= 0" | bc -l) )); then
125
- trend="📈"
126
- else
127
- trend="📉"
128
- fi
129
-
130
- {
131
- echo "Coverage Report $trend"
132
- echo "| Branch | Commit | Coverage |"
133
- echo "|--------|--------|----------|"
134
- echo "| ${BASE_REF} | ${{ steps.merge_base.outputs.merge_base }} | ${base_coverage}% |"
135
- echo "| ${HEAD_REF} | ${{ github.event.pull_request.head.sha }} | ${pr_coverage}% |"
136
- echo "| | Difference | ${diff}% |"
137
- } > comment.md
138
- cat "comment.md" >> "$GITHUB_STEP_SUMMARY"
139
- - name : Comment PR
140
- uses : marocchino/sticky-pull-request-comment@d2ad0de260ae8b0235ce059e63f2949ba9e05943
141
- if : github.event.pull_request.head.repo.full_name == github.repository
142
- with :
143
- recreate : true
144
- path : comment.md
145
- - name : Check coverage threshold
146
- run : |
147
- if (( $(echo "${{ steps.compare.outputs.diff }} < 0" | bc -l) )); then
148
- echo "Error: Coverage difference (${{ steps.compare.outputs.diff }}%) is negative"
149
- fi
80
+ COVERALLS_TOKEN : ${{ secrets.COVERALLS_REPO_TOKEN }}
81
+ run : goveralls -parallel-finish -ignore=test/* -service=github
150
82
151
83
libraryOwners :
152
84
runs-on : ubuntu-latest
@@ -390,7 +322,9 @@ jobs:
390
322
uses : actions/setup-go@v5
391
323
with :
392
324
go-version-file : ' go.mod'
393
- - run : go install gotest.tools/gotestsum@latest
325
+ - run : |
326
+ go install gotest.tools/gotestsum@v1.12.3
327
+ go install github.com/mattn/goveralls@v0.0.12
394
328
- name : set Apix Bot token
395
329
id : app-token
396
330
uses : mongodb/apix-action/token@3024080388613583e3bd119bfb1ab4b4dbf43c42
@@ -401,6 +335,12 @@ jobs:
401
335
env :
402
336
GH_TOKEN : ${{ steps.app-token.outputs.token }}
403
337
TEST_CMD : gotestsum --junitfile e2e-tests.xml --format standard-verbose --
338
+ COVERAGE : coverage.out
339
+ - name : Send coverage
340
+ env :
341
+ COVERALLS_TOKEN : ${{ secrets.COVERALLS_REPO_TOKEN }}
342
+ COVERAGE : coverage.out
343
+ run : goveralls -parallel -coverprofile="$COVERAGE" -ignore=test/* -service=github
404
344
- name : Test Summary
405
345
if : always()
406
346
uses : test-summary/action@31493c76ec9e7aa675f1585d3ed6f1da69269a86
0 commit comments