|
31 | 31 |
|
32 | 32 | env: |
33 | 33 | UV_PYTHON_PREFERENCE: only-managed |
| 34 | + CHECK_COVERAGE: ${{ matrix.python-version == '3.10' && matrix.torch-version == '2.12.0' }} |
34 | 35 |
|
35 | 36 | steps: |
36 | 37 | - name: Checkout code |
|
66 | 67 | env: |
67 | 68 | HF_HUB_DOWNLOAD_TIMEOUT: 60 |
68 | 69 | run: | |
69 | | - uv run pytest tests |
| 70 | + if [ "${CHECK_COVERAGE}" = "true" ]; then |
| 71 | + uv run pytest tests \ |
| 72 | + --cov=kernels \ |
| 73 | + --cov-report=term-missing \ |
| 74 | + --cov-report=json:coverage.json |
| 75 | + else |
| 76 | + uv run pytest tests |
| 77 | + fi |
70 | 78 |
|
71 | 79 | - name: Re-run dependency test with dependencies installed |
72 | 80 | working-directory: ./kernels |
@@ -98,3 +106,63 @@ jobs: |
98 | 106 | run: | |
99 | 107 | uv run kernels check kernels-community/activation |
100 | 108 | uv run kernels versions kernels-community/activation |
| 109 | +
|
| 110 | + # This is done to securely run the coverage test and to post comments even |
| 111 | + # on fork PRs. |
| 112 | + - name: Render coverage report for PR comment |
| 113 | + if: env.CHECK_COVERAGE == 'true' && github.event_name == 'pull_request' |
| 114 | + working-directory: ./kernels |
| 115 | + env: |
| 116 | + HEAD_SHA: ${{ github.event.pull_request.head.sha }} |
| 117 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 118 | + PY_VERSION: ${{ matrix.python-version }} |
| 119 | + TORCH_VERSION: ${{ matrix.torch-version }} |
| 120 | + run: | |
| 121 | + set -euo pipefail |
| 122 | + mkdir -p coverage-artifact |
| 123 | +
|
| 124 | + PCT=$(jq -r '.totals.percent_covered' coverage.json) |
| 125 | + PCT_INT=$(printf '%.0f' "$PCT") |
| 126 | + PCT_DISPLAY=$(printf '%.1f' "$PCT") |
| 127 | + if [ "$PCT_INT" -ge 80 ]; then |
| 128 | + EMOJI=":white_check_mark:" |
| 129 | + elif [ "$PCT_INT" -ge 70 ]; then |
| 130 | + EMOJI=":warning:" |
| 131 | + else |
| 132 | + EMOJI=":red_circle:" |
| 133 | + fi |
| 134 | +
|
| 135 | + uv run coverage report --format=markdown > coverage-artifact/cov-table.md |
| 136 | +
|
| 137 | + { |
| 138 | + echo "<!-- coverage-report -->" |
| 139 | + echo "## Coverage report — \`kernels/\`" |
| 140 | + echo |
| 141 | + echo "> Measured on: **Python ${PY_VERSION} / Torch ${TORCH_VERSION}**." |
| 142 | + echo "> Other CI configurations are not included in this number." |
| 143 | + echo "> Hardware-gated code paths (ROCm/XPU/NPU/Darwin/Windows) are excluded or unreachable on the Linux+CUDA runner." |
| 144 | + echo |
| 145 | + echo "**Total coverage: \`${PCT_DISPLAY}%\`** — threshold: 80% — ${EMOJI}" |
| 146 | + echo |
| 147 | + echo "<details>" |
| 148 | + echo "<summary>Per-file breakdown</summary>" |
| 149 | + echo |
| 150 | + cat coverage-artifact/cov-table.md |
| 151 | + echo |
| 152 | + echo "</details>" |
| 153 | + echo |
| 154 | + echo "_Updated by the \`Test kernels\` workflow on commit \`${HEAD_SHA}\`._" |
| 155 | + } > coverage-artifact/body.md |
| 156 | +
|
| 157 | + # `workflow_run.pull_requests` is empty for fork PRs, so the |
| 158 | + # downstream comment workflow reads the PR number from here. |
| 159 | + echo "${PR_NUMBER}" > coverage-artifact/pr_number.txt |
| 160 | +
|
| 161 | + - name: Upload coverage artifact |
| 162 | + if: env.CHECK_COVERAGE == 'true' && github.event_name == 'pull_request' |
| 163 | + uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 |
| 164 | + with: |
| 165 | + name: coverage-report |
| 166 | + path: kernels/coverage-artifact/ |
| 167 | + retention-days: 1 |
| 168 | + if-no-files-found: error |
0 commit comments