diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4c784ee..d1aeebb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,22 +37,10 @@ jobs: - name: Build run: go build -v ./... - - name: Test with coverage - run: go test -v -race -coverprofile=coverage.out -covermode=atomic ./... - - - name: Calculate coverage + - name: Test with coverage and enforce threshold run: | - TOTAL=$(go test -cover ./... 2>&1 | awk '/^ok /{for(i=1;i<=NF;i++) if($i~/%$/) print $i}' | head -1 | tr -d '%') - echo "Coverage: ${TOTAL}" - if [ -z "$TOTAL" ]; then - echo "No coverage data found" - exit 1 - fi - if (( $(echo "$TOTAL < 80" | bc -l) )); then - echo "Coverage ${TOTAL}% is below 80% threshold" - exit 1 - fi - echo "Coverage ${TOTAL}% meets 80% threshold" + go test -v -race -coverprofile=coverage.out -covermode=atomic ./... 2>&1 + go test -cover ./... 2>&1 | awk '/^ok/ {split($NF,a,"%"); if (a[1]+0 < 80) {print "Coverage " a[1] "% is below 80% threshold"; exit 1} else print "Coverage " a[1] "% meets 80% threshold"}' - name: Upload coverage report uses: codecov/codecov-action@v4