-
Notifications
You must be signed in to change notification settings - Fork 0
/
github-actions-go-coverage.yml
48 lines (42 loc) · 1.47 KB
/
github-actions-go-coverage.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
name: Go
on:
push:
branches: devel
pull_request:
branches: devel
env:
GOPRIVATE: "github.com/juanorganization"
defaults:
run:
working-directory: .
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Test
run: |
git config --global url."https://${{secrets.token_github}}@github.com/".insteadOf "https://github.com/"
git config -l
go env -w "GOPRIVATE=github.com/juanorganization/*"
go test -v ./... -coverprofile coverage.out -covermode count
go tool cover -func coverage.out
- name: Quality Gate - Test coverage shall be above threshold
env:
TESTCOVERAGE_THRESHOLD: 15
run: |
echo "Quality Gate: checking test coverage is above threshold ..."
echo "Threshold : $TESTCOVERAGE_THRESHOLD %"
totalCoverage=`go tool cover -func=coverage.out | grep total | grep -Eo '[0-9]+\.[0-9]+'`
echo "Current test coverage : $totalCoverage %"
if (( $(echo "$totalCoverage $TESTCOVERAGE_THRESHOLD" | awk '{print ($1 > $2)}') )); then
echo "OK"
else
echo "Current test coverage is below threshold. Please add more unit tests or adjust threshold to a lower value."
echo "Failed"
exit 1
fi