Skip to content

Commit

Permalink
Merge pull request #3 from vasayxtx/polish-github-workflows
Browse files Browse the repository at this point in the history
Validate code coverage in CI
  • Loading branch information
vasayxtx authored Oct 8, 2024
2 parents 24d0ff3 + fb82a6c commit 5a84a73
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
name: Lint

on:
push:
branches:
- main
pull_request:
branches:
- main

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
26 changes: 14 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ permissions:
contents: read

jobs:
test_and_lint:
name: Test, Lint, and Coverage
test:
name: Test
strategy:
matrix:
go: [ '1.20' ]
Expand All @@ -35,13 +35,15 @@ 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: Check coverage
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

0 comments on commit 5a84a73

Please sign in to comment.