|
17 | 17 | - uses: actions/checkout@v4 |
18 | 18 | with: |
19 | 19 | path: common |
| 20 | + # Full history so diff-cover can resolve origin/<base_ref> for the |
| 21 | + # patch-coverage gate below (shallow clones lack the base commit). |
| 22 | + fetch-depth: 0 |
20 | 23 | - uses: actions/checkout@v4 |
21 | 24 | with: |
22 | 25 | repository: InstaNode-dev/proto |
|
34 | 37 | files: common/coverage.out |
35 | 38 | flags: common |
36 | 39 | fail_ci_if_error: false |
| 40 | + |
| 41 | + # ------------------------------------------------------------------ |
| 42 | + # Org patch-coverage mandate: every changed line in a PR diff must be |
| 43 | + # covered by a test (100%), and the project floor stays >=95%. |
| 44 | + # Tool: diff-cover (https://github.com/Bachmann1234/diff-cover) reads a |
| 45 | + # Cobertura report + the git diff vs the base branch. |
| 46 | + # ------------------------------------------------------------------ |
| 47 | + - uses: actions/setup-python@v5 |
| 48 | + if: github.event_name == 'pull_request' |
| 49 | + with: |
| 50 | + python-version: '3.12' |
| 51 | + - name: Install diff-cover + cobertura converter |
| 52 | + if: github.event_name == 'pull_request' |
| 53 | + run: | |
| 54 | + pip install diff-cover |
| 55 | + go install github.com/boumenot/gocover-cobertura@latest |
| 56 | + - name: Convert coverage to Cobertura |
| 57 | + if: github.event_name == 'pull_request' |
| 58 | + working-directory: common |
| 59 | + run: $(go env GOPATH)/bin/gocover-cobertura < coverage.out > coverage.xml |
| 60 | + - name: Patch coverage gate (100% of changed lines) |
| 61 | + if: github.event_name == 'pull_request' |
| 62 | + working-directory: common |
| 63 | + run: | |
| 64 | + git fetch origin "${{ github.base_ref }}" --depth=1 || true |
| 65 | + diff-cover coverage.xml \ |
| 66 | + --compare-branch="origin/${{ github.base_ref }}" \ |
| 67 | + --fail-under=100 |
| 68 | + - name: Project coverage floor (>=95% total) |
| 69 | + if: github.event_name == 'pull_request' |
| 70 | + working-directory: common |
| 71 | + run: | |
| 72 | + total=$(go tool cover -func=coverage.out | tail -1 | awk '{print $3}' | tr -d '%') |
| 73 | + echo "Total project coverage: ${total}%" |
| 74 | + awk -v t="$total" 'BEGIN { exit (t+0 >= 95) ? 0 : 1 }' \ |
| 75 | + || { echo "::error::Project coverage ${total}% is below the 95% floor"; exit 1; } |
0 commit comments