Skip to content

Commit

Permalink
Validate code coverage in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
vasayxtx committed Oct 8, 2024
1 parent a953d47 commit 845089e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
27 changes: 17 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,20 @@ jobs:
run: go mod download

- name: Run tests with coverage
run: go test -race -cover -coverprofile="coverage.out" -covermode=atomic -v ./...

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: ./coverage.out

- name: Calculate coverage
run: go tool cover -func=coverage.out | grep total | awk '{print substr($3, 1, length($3)-1)}'
id: coverage
run: go test -race -cover -coverprofile="coverage.out" -covermode=atomic -v --coverpkg=./... ./...

- name: Exclude generated code and examples from coverage
if: matrix.os == 'ubuntu-latest'
run: grep -Ev '/pb/|/examples/' ./coverage.out > ./coverage_filtered.out && mv -f ./coverage_filtered.out ./coverage.out

- name: Check coverage
if: matrix.os == 'ubuntu-latest'
run: |
real_coverage=$(go tool cover -func=coverage.out | grep total | awk '{print substr($3, 1, length($3)-1)}')
min_coverage=$(cat min-coverage.txt)
if (( $(echo "$real_coverage < $min_coverage" | bc -l) )); then
echo "Coverage check failed: $real_coverage% is lower than the required $min_coverage%"
exit 1
else
echo "Coverage check passed: $real_coverage% meets the minimum requirement of $min_coverage%"
fi
2 changes: 1 addition & 1 deletion min-coverage.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
80
79

0 comments on commit 845089e

Please sign in to comment.