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