forked from mirror/crumbs-original
feat: add coverage summary to GitHub Actions job summary
Write a markdown coverage table to $GITHUB_STEP_SUMMARY for both unit and E2E test jobs. Uses a small bash script that parses json-summary output from the coverage reporters. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
committed by
Fred Cabassut
co-authored by
Claude Opus 4.6
parent
4ef5dbf20b
commit
bd4016c998
@@ -48,6 +48,10 @@ jobs:
|
|||||||
- run: pnpm install --frozen-lockfile
|
- run: pnpm install --frozen-lockfile
|
||||||
- run: pnpm test:unit:coverage
|
- run: pnpm test:unit:coverage
|
||||||
|
|
||||||
|
- name: Coverage summary
|
||||||
|
if: always()
|
||||||
|
run: bash scripts/coverage-summary.sh "Unit Test Coverage" coverage/unit/coverage-summary.json
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v4
|
- uses: actions/upload-artifact@v4
|
||||||
if: always()
|
if: always()
|
||||||
with:
|
with:
|
||||||
@@ -103,6 +107,10 @@ jobs:
|
|||||||
if: always()
|
if: always()
|
||||||
run: npx nyc report
|
run: npx nyc report
|
||||||
|
|
||||||
|
- name: Coverage summary
|
||||||
|
if: always()
|
||||||
|
run: bash scripts/coverage-summary.sh "E2E Test Coverage" coverage/e2e/coverage-summary.json
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v4
|
- uses: actions/upload-artifact@v4
|
||||||
if: always()
|
if: always()
|
||||||
with:
|
with:
|
||||||
|
|||||||
Executable
+37
@@ -0,0 +1,37 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Writes a coverage summary table to $GITHUB_STEP_SUMMARY (or stdout if not in CI).
|
||||||
|
# Usage: scripts/coverage-summary.sh <title> <json-summary-path>
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
TITLE="${1:?Usage: coverage-summary.sh <title> <json-summary-path>}"
|
||||||
|
JSON="${2:?Usage: coverage-summary.sh <title> <json-summary-path>}"
|
||||||
|
|
||||||
|
if [ ! -f "$JSON" ]; then
|
||||||
|
echo "Coverage summary not found: $JSON" >&2
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Resolve to absolute path for require()
|
||||||
|
ABS_JSON="$(cd "$(dirname "$JSON")" && pwd)/$(basename "$JSON")"
|
||||||
|
|
||||||
|
# Extract totals with node (available in CI, no jq dependency)
|
||||||
|
read -r stmts branches funcs lines < <(node -e "
|
||||||
|
const s = require('$ABS_JSON').total;
|
||||||
|
console.log(s.statements.pct, s.branches.pct, s.functions.pct, s.lines.pct);
|
||||||
|
")
|
||||||
|
|
||||||
|
TABLE="## $TITLE
|
||||||
|
|
||||||
|
| Metric | Coverage |
|
||||||
|
|--------|----------|
|
||||||
|
| Statements | ${stmts}% |
|
||||||
|
| Branches | ${branches}% |
|
||||||
|
| Functions | ${funcs}% |
|
||||||
|
| Lines | ${lines}% |
|
||||||
|
"
|
||||||
|
|
||||||
|
if [ -n "${GITHUB_STEP_SUMMARY:-}" ]; then
|
||||||
|
echo "$TABLE" >> "$GITHUB_STEP_SUMMARY"
|
||||||
|
else
|
||||||
|
echo "$TABLE"
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user