forked from kardianos/service
-
Notifications
You must be signed in to change notification settings - Fork 0
84 lines (70 loc) · 2.33 KB
/
unit-test.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# This workflow will install Go dependencies, run tests for 4 versions of Go
# For more information see: https://support.github.com/features/actions
name: Unit tests
on:
pull_request:
paths:
- ".github/workflows/*.yml"
- "**/*.go"
- "**/go.mod"
- "**/go.sum"
permissions:
contents: read
pull-requests: write
jobs:
go-test:
name: Run go unit tests
strategy:
matrix:
go-version: ["1.18", "1.19", "1.23"]
runs-on: ubuntu-latest
steps:
- name: "Install Go"
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- uses: actions/checkout@v3
- name: Install test dependencies
run: |
go get github.com/boumenot/gocover-cobertura
- name: Install project dependencies
run: go build
- name: Run test
run: |
# run test:
PKGS=$(go list ./... | grep -v /vendor/)
DEPS=$(go list ./... | grep -v vendor | grep -v test | xargs | sed 's/ /,/g')
go test ${PKGS} -v \
-coverprofile=coverage_${{ matrix.go-version }}.out \
-covermode=count \
-coverpkg ${DEPS} 2>&1
- name: Generate code coverage report
run: |
go run github.com/boumenot/gocover-cobertura < coverage_${{ matrix.go-version }}.out > coverage-unit_${{ matrix.go-version }}.xml
- name: compute valid coverage total
run: |
go tool cover -func=coverage_${{ matrix.go-version }}.out
- name: Code Coverage Report
uses: irongut/[email protected]
if: matrix.go-version == '1.19'
with:
# will generate code-coverage-results.md
filename: coverage-unit_*.xml
badge: true
fail_below_min: true
format: markdown
hide_branch_rate: false
hide_complexity: true
indicators: true
output: both
thresholds: "60 80"
- name: Add coverage comment to PR
uses: marocchino/sticky-pull-request-comment@v2
if: matrix.go-version == '1.19' && github.event_name == 'pull_request'
with:
path: code-coverage-results.md
- name: Upload coverage results
uses: actions/upload-artifact@v3
with:
name: go-coverage-results
path: coverage-unit_*.xml