From 71a205ae448225d5f5e58db02c8551a9150e11f1 Mon Sep 17 00:00:00 2001 From: oleksandrkhmil Date: Wed, 2 Oct 2024 19:04:02 +0300 Subject: [PATCH] add test coverage --- .github/workflows/ci.yml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index beacbac..f455620 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,6 +18,10 @@ jobs: with: go-version-file: go.mod cache-dependency-path: "**/go.sum" + - name: Setup Swagger + run: > + go install -v github.com/swaggo/swag/cmd/swag@v1.8.10 + swag init -g cmd/main.go - uses: golangci/golangci-lint-action@v6 with: version: v1.60 @@ -32,6 +36,10 @@ jobs: with: go-version-file: go.mod cache-dependency-path: "**/go.sum" + - name: Setup Swagger + run: > + go install -v github.com/swaggo/swag/cmd/swag@v1.8.10 + swag init -g cmd/main.go - name: Run tests run: make test @@ -58,5 +66,31 @@ jobs: with: go-version-file: go.mod cache-dependency-path: "**/go.sum" + - id: govulncheck uses: golang/govulncheck-action@v1 + + test-coverage: + name: Test Coverage + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + cache-dependency-path: "**/go.sum" + - name: Generate coverage report + run: go test -coverprofile=coverage.out ./... + - name: Check coverage + id: coverage + run: | + coverage=$(go tool cover -func=coverage.out | grep total | awk ‘{print substr($3, 1, length($3)-1)}’) + echo “total_coverage=$coverage” >> $GITHUB_OUPUT + echo “Coverage: $coverage%” + - name: Fail if coverage is below threshold + run: | + if (( $(echo “$total_coverage < 50” | bc -l) )); then + echo “Coverage ($total_coverage%) is below the threshold (50%)” + exit 1 + fi