Skip to content
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
26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,35 @@ jobs:
go tool cover -func=coverage-integration.out | grep total | awk '{print "Integration test coverage: " $3}'
fi

- name: Check coverage threshold
if: matrix.go-version == '1.25'
run: |
if [ ! -f coverage.out ]; then
echo "::error::Coverage file not found"
exit 1
fi

COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | sed 's/%//')

if [ -z "$COVERAGE" ]; then
echo "::error::Failed to extract coverage percentage"
exit 1
fi

THRESHOLD=80
echo "Current coverage: ${COVERAGE}%"
echo "Minimum threshold: ${THRESHOLD}%"

if (( $(echo "$COVERAGE < $THRESHOLD" | bc -l) )); then
echo "::error::Coverage ${COVERAGE}% is below minimum threshold of ${THRESHOLD}%"
exit 1
fi
echo "Coverage check passed!"

- name: Upload coverage to Codecov
if: matrix.go-version == '1.25'
uses: codecov/codecov-action@v4
continue-on-error: true # Codecov is informational; inline check above is the hard gate
with:
files: ./coverage.out,./coverage-integration.out
flags: unittests
Expand Down
18 changes: 17 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
check-prerequisites check-docker check-kubectl \
build test test-integration test-e2e test-all \
lint fmt clean install-deps \
docker-build docker-push
docker-build docker-push \
coverage-check

# ================================================================================================
# Project Configuration
Expand Down Expand Up @@ -232,6 +233,20 @@ test-all:
@go tool cover -func=coverage/coverage.out | grep total | awk '{print "Total coverage: " $$3}'
@$(call print_success,"All tests passed - coverage report: coverage/coverage.html")

# Check coverage meets minimum threshold (80%)
COVERAGE_THRESHOLD := 80
coverage-check:
@$(call print_status,"Checking coverage threshold (minimum $(COVERAGE_THRESHOLD)%)...")
@mkdir -p coverage
@go test ./... -covermode=atomic -coverprofile=coverage/coverage.out -short > /dev/null 2>&1
@COVERAGE=$$(go tool cover -func=coverage/coverage.out | grep total | awk '{print $$3}' | sed 's/%//'); \
echo "Current coverage: $${COVERAGE}%"; \
if [ $$(echo "$${COVERAGE} < $(COVERAGE_THRESHOLD)" | bc -l) -eq 1 ]; then \
$(call print_error,"Coverage $${COVERAGE}% is below minimum threshold of $(COVERAGE_THRESHOLD)%"); \
exit 1; \
fi
@$(call print_success,"Coverage check passed (>= $(COVERAGE_THRESHOLD)%)")

# Lint code with golangci-lint
lint:
@$(call print_status,"Running golangci-lint...")
Expand Down Expand Up @@ -546,6 +561,7 @@ help:
@echo " make test-integration Run integration tests"
@echo " make test-e2e Run end-to-end tests"
@echo " make test-all Run all tests with coverage report"
@echo " make coverage-check Verify coverage >= 80% threshold"
@echo " make lint Run golangci-lint"
@echo " make fmt Format code with gofmt and goimports"
@echo ""
Expand Down
Loading
Loading