|
15 | 15 | timeout-minutes: 10 |
16 | 16 | steps: |
17 | 17 | - uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + # Full history so diff-cover can resolve origin/<base_ref>. |
| 20 | + fetch-depth: 0 |
18 | 21 | - uses: actions/setup-node@v4 |
19 | 22 | with: |
20 | 23 | # >=22 for --test-coverage-exclude support (added 22.5.0). |
|
26 | 29 | if: always() |
27 | 30 | with: |
28 | 31 | fail_ci_if_error: false |
| 32 | + |
| 33 | + # ------------------------------------------------------------------ |
| 34 | + # Org patch-coverage mandate: every changed line in a PR diff must be |
| 35 | + # covered by a test (100%). Tool: diff-cover |
| 36 | + # (https://github.com/Bachmann1234/diff-cover). |
| 37 | + # |
| 38 | + # The node test runner reports coverage on the COMPILED JS in dist-test/. |
| 39 | + # `--enable-source-maps` makes the built-in lcov reporter rewrite both |
| 40 | + # the file paths and the line numbers back to the original TypeScript |
| 41 | + # sources (src/*.ts) via the emitted .js.map files, so diff-cover lines |
| 42 | + # up with the PR diff. Without it, lcov emits dist-test/src/*.js with |
| 43 | + # JS line numbers and the gate silently no-ops. |
| 44 | + # ------------------------------------------------------------------ |
| 45 | + - name: Generate lcov mapped to TS sources |
| 46 | + if: github.event_name == 'pull_request' |
| 47 | + run: | |
| 48 | + npm run pretest |
| 49 | + mkdir -p coverage |
| 50 | + node --enable-source-maps --test --experimental-test-coverage \ |
| 51 | + --test-coverage-exclude='dist-test/test/**' \ |
| 52 | + --test-coverage-exclude='dist/**' \ |
| 53 | + --test-coverage-exclude='node_modules/**' \ |
| 54 | + --test-reporter=lcov --test-reporter-destination=coverage/lcov.info \ |
| 55 | + --test-reporter=spec --test-reporter-destination=stdout \ |
| 56 | + dist-test/test/integration.test.js \ |
| 57 | + dist-test/test/live-smoke.test.js \ |
| 58 | + dist-test/test/client-unit.test.js \ |
| 59 | + dist-test/test/index-unit.test.js \ |
| 60 | + dist-test/test/tools-unit.test.js |
| 61 | + - uses: actions/setup-python@v5 |
| 62 | + if: github.event_name == 'pull_request' |
| 63 | + with: |
| 64 | + python-version: '3.12' |
| 65 | + - name: Install diff-cover |
| 66 | + if: github.event_name == 'pull_request' |
| 67 | + run: pip install diff-cover |
| 68 | + - name: Patch coverage gate (100% of changed lines) |
| 69 | + if: github.event_name == 'pull_request' |
| 70 | + run: | |
| 71 | + git fetch origin "${{ github.base_ref }}" --depth=1 || true |
| 72 | + diff-cover coverage/lcov.info \ |
| 73 | + --compare-branch="origin/${{ github.base_ref }}" \ |
| 74 | + --fail-under=100 |
0 commit comments