Alonso Torres 15f9994022
✨ Add test coverage reports to CI and pull requests (#13156)
Measure the coverage of the backend, common, frontend and render-wasm
test suites in CI, and show it on the workflow run pages and in one
"Coverage Report" comment on each pull request.

- Backend and common run kaocha with the cloverage plugin through a new
  `:coverage` alias, which writes lcov, HTML and an EMMA report. The PR
  report shows lines and Clojure forms (as statements); cloverage
  measures no functions or branches. Plain local runs are unchanged.
- Frontend runs the compiled test bundle with V8 coverage
  (`pnpm run test:coverage`, `frontend/scripts/coverage.js`) and maps it
  back to the ClojureScript sources through the source maps of the test
  build. UI namespaces (`app/main/ui`) are left out.
- Render-wasm runs its native Rust tests under cargo-llvm-cov when
  `RENDER_WASM_COVERAGE` is set. The devenv image lacks the tool, so the
  workflow downloads a pinned release and checks its sha256.
- `scripts/coverage-summary.mjs` renders an lcov file as a markdown table
  by source area for `$GITHUB_STEP_SUMMARY`; each workflow also uploads
  the HTML report as an artifact.
- `scripts/coverage-comment.mjs` keeps a single PR comment, laid out like
  the Vitest Coverage Report Action, with a section per project and the
  coverage of the changed files. Each job updates its own section; the
  data of every project lives in a hidden block of the comment, and a
  job writes again when a concurrent one dropped its data.
- Lines have targets that only colour the report: 70% backend and
  common, 50% frontend, 40% render-wasm.
- The comment step only runs for PRs from branches of this repo: fork
  PRs get a read-only token and keep the summary on the run page.

AI-assisted-by: claude-opus-5-5
2026-11-18 17:53:32 +01:00

42 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
set -ex
case "$(uname -m)" in
aarch64|arm64) _ARCH="aarch64" ;;
*) _ARCH="x86_64" ;;
esac
export SKIA_BINARIES_URL=${SKIA_BINARIES_URL:-"https://github.com/penpot/skia-binaries/releases/download/0.153.3/skia-binaries-b7f043e0b1e2a850e702-${_ARCH}-unknown-linux-gnu-gl-svg-textlayout-binary-cache-webp-pdf.tar.gz"}
export CARGO_BUILD_TARGET=${CARGO_BUILD_TARGET:-"${_ARCH}-unknown-linux-gnu"};
_SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
pushd "$_SCRIPT_DIR" > /dev/null
. ./_build_env frontend
node --test scripts/cargo-build.test.cjs || exit $?
setup
# With RENDER_WASM_COVERAGE set, the same tests run under cargo-llvm-cov
# (must be on PATH) and leave lcov, a JSON summary and HTML in
# target/coverage/.
if [ -n "${RENDER_WASM_COVERAGE:-}" ]; then
rustup component add llvm-tools-preview --toolchain "$RUST_VERSION"
_COV_ARGS=(--target "$CARGO_BUILD_TARGET")
cargo llvm-cov clean --workspace
# Keep going on failure so the reports still get written.
RESULT=0
cargo llvm-cov --no-report "${_COV_ARGS[@]}" --bin render_wasm -- --show-output || RESULT=$?
mkdir -p target/coverage
cargo llvm-cov report "${_COV_ARGS[@]}" --lcov --output-path target/coverage/lcov.info
cargo llvm-cov report "${_COV_ARGS[@]}" --json --summary-only --output-path target/coverage/summary.json
cargo llvm-cov report "${_COV_ARGS[@]}" --html --output-dir target/coverage
else
cargo test --bin render_wasm -- --show-output
RESULT=$?
fi
popd > /dev/null
exit $RESULT