From 3a9c974d2192d0c71741d192e1a63c18e493933c Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 22 May 2026 07:59:07 +0530 Subject: [PATCH] ci(coverage): gate PRs on 100% patch coverage + 95% project floor Adds diff-cover patch-coverage enforcement to the coverage workflow: every changed line in a PR must be covered by a test (--fail-under=100), and total project coverage must stay >=95%. Go coverage is converted to Cobertura via gocover-cobertura so diff-cover can read it. fetch-depth: 0 lets diff-cover resolve origin/; gated to pull_request events. New org mandate. Co-Authored-By: Claude Opus 4.7 (1M context) --- .github/workflows/coverage.yml | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 63df648..f15c612 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -17,6 +17,8 @@ jobs: - uses: actions/checkout@v4 with: path: sdk-go + # Full history so diff-cover can resolve origin/. + fetch-depth: 0 - uses: actions/checkout@v4 with: repository: InstaNode-dev/common @@ -39,3 +41,38 @@ jobs: files: sdk-go/coverage.out flags: sdk-go fail_ci_if_error: false + + # ------------------------------------------------------------------ + # Org patch-coverage mandate: every changed line in a PR diff must be + # covered by a test (100%), and the project floor stays >=95%. + # Tool: diff-cover (https://github.com/Bachmann1234/diff-cover). + # ------------------------------------------------------------------ + - uses: actions/setup-python@v5 + if: github.event_name == 'pull_request' + with: + python-version: '3.12' + - name: Install diff-cover + cobertura converter + if: github.event_name == 'pull_request' + run: | + pip install diff-cover + go install github.com/boumenot/gocover-cobertura@latest + - name: Convert coverage to Cobertura + if: github.event_name == 'pull_request' + working-directory: sdk-go + run: $(go env GOPATH)/bin/gocover-cobertura < coverage.out > coverage.xml + - name: Patch coverage gate (100% of changed lines) + if: github.event_name == 'pull_request' + working-directory: sdk-go + run: | + git fetch origin "${{ github.base_ref }}" --depth=1 || true + diff-cover coverage.xml \ + --compare-branch="origin/${{ github.base_ref }}" \ + --fail-under=100 + - name: Project coverage floor (>=95% total) + if: github.event_name == 'pull_request' + working-directory: sdk-go + run: | + total=$(go tool cover -func=coverage.out | tail -1 | awk '{print $3}' | tr -d '%') + echo "Total project coverage: ${total}%" + awk -v t="$total" 'BEGIN { exit (t+0 >= 95) ? 0 : 1 }' \ + || { echo "::error::Project coverage ${total}% is below the 95% floor"; exit 1; }