From c3230d5430d1b52f45e9376ca513273018e72357 Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Fri, 6 Jan 2023 21:38:48 +0300 Subject: [PATCH] CI coverage --- .github/workflows/ci.yml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..668c61b0 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,36 @@ +on: + pull_request: + branches: + - master + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v2 + with: + go-version: '^1.19.0' + + - name: Vet + run: | + go vet ./... + - name: Unit tests + run: | + sudo go test ./... -coverprofile coverage.out -covermode count + sudo go tool cover -func coverage.out + - name: Quality Gate - Test coverage shall be above threshold + env: + TESTCOVERAGE_THRESHOLD: 0 + 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