Configured Quality Gate

This commit is contained in:
Mario
2022-05-14 17:34:08 +02:00
parent 66db128054
commit 944767e1cb

View File

@ -21,11 +21,32 @@ jobs:
- name: Dependences - name: Dependences
run: go mod download run: go mod download
- name: Vet
run: |
go vet ./...
- name: Build - name: Build
run: go build -v ./... run: go build -v ./...
- name: Run coverage - name: Unit tests
run: go test -race -coverprofile=coverage.out -covermode=atomic run: |
go test ./... -coverprofile coverage.tmp.out -covermode count
go tool cover -func coverage.tmp.out
- name: Upload coverage to Codecov - name: Quality Gate - Test coverage shall be above threshold
uses: codecov/codecov-action@v2 env:
TESTCOVERAGE_THRESHOLD: 70
run: |
echo "Quality Gate: checking test coverage is above threshold ..."
echo "Threshold : $TESTCOVERAGE_THRESHOLD %"
# Excluded the concrete strategy
cat coverage.tmp.out | grep -v "secureShellStrategy.go" | grep -v "hypertextTransferProtocolStrategy.go" > coverage.out
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