File tree Expand file tree Collapse file tree 2 files changed +26
-6
lines changed Expand file tree Collapse file tree 2 files changed +26
-6
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ permissions:
1111 pull-requests : read
1212
1313jobs :
14- lint :
14+ build :
1515 name : build
1616 runs-on : ubuntu-latest
1717 steps :
2424 - name : build
2525 run : make build
2626 - name : test
27- run : make test-cov
27+ run : make test-cov
28+ - name : test coverage check
29+ env :
30+ TESTCOVERAGE_THRESHOLD : 26
31+ run : |
32+ echo "Quality Gate: checking test coverage is above threshold ..."
33+ echo "Threshold : $TESTCOVERAGE_THRESHOLD %"
34+ totalCoverage=`go tool cover -func=coverage.out | grep total | grep -Eo '[0-9]+\.[0-9]+'`
35+ echo "Current test coverage : $totalCoverage %"
36+ if (( $(echo "$totalCoverage $TESTCOVERAGE_THRESHOLD" | awk '{print ($1 >= $2)}') )); then
37+ echo "OK"
38+ else
39+ echo "Current test coverage is below threshold. Please add more unit tests or adjust threshold to a lower value."
40+ echo "Failed"
41+ exit 1
42+ fi
Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ BUILD_WIN=@env GOOS=windows GOARCH=amd64 go build -o $(PACKNAME).exe
44BUILD_LINUX =@env GOOS=linux GOARCH=amd64 go build -o $(PACKNAME )
55BUILD_MAC =@env GOOS=darwin GOARCH=amd64 go build -o $(PACKNAME ) -darwin
66
7+ COVERAGE = $(shell go tool cover -func=coverage.out | grep total | grep -Eo '[0-9]+\.[0-9]+')
8+
79release : package release bin
810release-candidate : package release-candidate
911binary : package build
@@ -35,21 +37,24 @@ build:
3537package : tidy test
3638 @echo " > Packaging static files..."
3739
38- test :
40+ vet :
3941 @echo " > Validating code ..."
4042 @go vet ./...
43+
44+ test : vet
4145 @go clean -testcache
4246 @go test ./...
4347
4448tidy :
4549 @echo " > Tidying go.mod ..."
4650 @go mod tidy
4751
48- test-cov :
52+ test-cov : vet
4953 @echo " Running tests and generating coverage output ..."
5054 @go test ./... -coverprofile coverage.out -covermode count
51- @sleep 2 # Sleeping to allow for coverage.out file to get generated
52- @echo " Current test coverage : $( shell go tool cover -func=coverage.out | grep total | grep -Eo ' [0-9]+\.[0-9]+' ) %"
55+
56+ print-cov :
57+ @echo " Current test coverage : $( COVERAGE) %"
5358
5459release-candidate : tidy test
5560 @echo " > Building release candidate for Linux..."
You can’t perform that action at this time.
0 commit comments