Skip to content

Commit

Permalink
add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksandrkhmil committed Oct 2, 2024
1 parent 8c52af8 commit 71a205a
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
swag init -g cmd/main.go
- uses: golangci/golangci-lint-action@v6
with:
version: v1.60
Expand All @@ -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/[email protected]
swag init -g cmd/main.go
- name: Run tests
run: make test

Expand All @@ -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

0 comments on commit 71a205a

Please sign in to comment.