-
Notifications
You must be signed in to change notification settings - Fork 4
54 lines (45 loc) · 1.53 KB
/
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
name: Test
on:
push:
branches:
- main
pull_request:
branches:
- main
permissions:
contents: read
jobs:
test:
name: Test
strategy:
matrix:
go: [ '1.20' ]
os: [ ubuntu-latest, macos-latest, windows-latest ]
fail-fast: true
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Go ${{ matrix.go }}
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
cache: false
- name: Install dependencies
run: go mod download
- name: Run tests with coverage
run: go test -race -cover -coverprofile="coverage.out" -covermode=atomic -v --coverpkg=./... ./...
- name: Exclude generated code and examples from coverage
if: matrix.os == 'ubuntu-latest'
run: grep -Ev '/pb/|/examples/' ./coverage.out > ./coverage_filtered.out && mv -f ./coverage_filtered.out ./coverage.out
- name: Check coverage
if: matrix.os == 'ubuntu-latest'
run: |
real_coverage=$(go tool cover -func=coverage.out | grep total | awk '{print substr($3, 1, length($3)-1)}')
min_coverage=$(cat min-coverage.txt)
if (( $(echo "$real_coverage < $min_coverage" | bc -l) )); then
echo "Coverage check failed: $real_coverage% is lower than the required $min_coverage%"
exit 1
else
echo "Coverage check passed: $real_coverage% meets the minimum requirement of $min_coverage%"
fi