Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

ci: measure unit test coverage on one leg and send it to the pull request bot (#2809)

Raghav Chamadiya56eac7775bfa
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index e97416b3e..0daf39ecb 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -17,6 +17,9 @@ jobs:
test-python:
name: Python ${{ matrix.python-version }} tests
runs-on: ubuntu-latest
+ permissions:
+ contents: read
+ id-token: write # proves the coverage upload comes from this repository
strategy:
fail-fast: false
matrix:
@@ -41,8 +44,38 @@ jobs:
run: uv run pytest tests/providers/ -v --tb=short
- name: Run unit tests
+ if: matrix.python-version != '3.12'
run: uv run pytest tests/unit/ -v --tb=short
+ # One leg measures coverage for the pull request bot's checks comment.
+ - name: Run unit tests with coverage
+ if: matrix.python-version == '3.12'
+ run: uv run --with pytest-cov pytest tests/unit/ -v --tb=short --cov=packages --cov-report=xml
+
+ - name: Upload coverage to Repowise
+ if: always() && matrix.python-version == '3.12'
+ continue-on-error: true
+ env:
+ REPORTS: "coverage.xml"
+ HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
+ PR_NUMBER: ${{ github.event.pull_request.number }}
+ RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
+ run: |
+ shopt -s globstar nullglob
+ files=()
+ for pattern in $REPORTS; do for f in $pattern; do [ -f "$f" ] && files+=(-F "report=@$f"); done; done
+ if [ ${#files[@]} -eq 0 ]; then echo "::warning::Repowise: no coverage report found at: $REPORTS"; exit 0; fi
+ auth=()
+ if [ -n "${ACTIONS_ID_TOKEN_REQUEST_URL:-}" ]; then
+ token=$(curl -sS -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=repowise" | jq -r '.value // empty' || true)
+ [ -n "$token" ] && auth=(-H "Authorization: Bearer $token")
+ fi
+ curl -sS --fail-with-body --max-time 60 "${auth[@]}" "${files[@]}" \
+ -F "repository=$GITHUB_REPOSITORY" -F "head_sha=$HEAD_SHA" -F "pr_number=$PR_NUMBER" \
+ -F "event=$GITHUB_EVENT_NAME" -F "run_url=$RUN_URL" -F "workspace=$GITHUB_WORKSPACE" \
+ https://api.repowise.dev/ci/coverage \
+ || echo "::warning::Repowise: coverage upload failed; see the message above."
+
# ---------------------------------------------------------------------------
# tree-sitter floor — installs the declared minimum tree-sitter version and
# compiles every language's query against it. `uv sync` alone always