From 0c06c2d699646b2e1cbe800824ae0012134bcf81 Mon Sep 17 00:00:00 2001 From: avkr003 Date: Sat, 5 Oct 2024 18:14:47 +0530 Subject: [PATCH] code coverage ci --- .github/workflows/coverage.yml | 43 ++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/coverage.yml diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 000000000..79c8be97c --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,43 @@ +name: Code Coverage Check + +on: + push: + branches: [ avkr003/cc ] + pull_request: + branches: [ avkr003/cc ] + +jobs: + test-coverage: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: '1.21' # Adjust this to match your project's Go version + + - name: Install dependencies + run: go mod download + + - name: Run tests with coverage + run: | + go test -v -coverprofile=coverage.out ./... + go tool cover -func=coverage.out + + - name: Check keeper package coverage + run: | + modules=$(find . -type d -name "x" -not -path "*/vendor/*") + for module in $modules; do + keeper_coverage=$(go tool cover -func=coverage.out | grep "${module}/keeper" | awk '{print $3}' | sed 's/%//') + if (( $(echo "$keeper_coverage < 90" | bc -l) )); then + echo "Coverage for ${module}/keeper is below 90%: ${keeper_coverage}%" + exit 1 + fi + done + + - name: Upload coverage report + uses: actions/upload-artifact@v3 + with: + name: coverage-report + path: coverage.out \ No newline at end of file