Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate code coverage in CI #13

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ permissions:
contents: read
jobs:
lint:
name: Lint
strategy:
matrix:
go: [ '1.20' ]
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/sec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ permissions:
pull-requests: write

jobs:
TruffleHog:
truffle_hog:
name: TruffleHog
runs-on: ubuntu-latest
defaults:
run:
Expand Down
21 changes: 12 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ permissions:

jobs:
test_and_lint:
name: Test, Lint, and Coverage
name: Test
strategy:
matrix:
go: [ '1.20' ]
Expand All @@ -37,11 +37,14 @@ jobs:
- 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
- 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
Loading