penpot/.github/workflows/tests-wasm.yml
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

123 lines
3.8 KiB
YAML

name: "CI: WASM"
defaults:
run:
shell: bash
on:
pull_request:
paths:
- 'render-wasm/**'
types:
- opened
- synchronize
- ready_for_review
push:
branches:
- develop
- staging
paths:
- 'render-wasm/**'
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
test-render-wasm:
if: ${{ !github.event.pull_request.draft }}
permissions:
contents: read
pull-requests: write # coverage comment on the PR
name: "Render WASM Tests"
runs-on: penpot-extended-runner
container:
image: penpotapp/devenv:latest
volumes:
- /var/cache/github-runner/m2:/root/.m2
- /var/cache/github-runner/gitlib:/root/.gitlibs
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Format
working-directory: ./render-wasm
run: |
cargo fmt --check
- name: Lint
working-directory: ./render-wasm
run: |
./lint
- name: Install cargo-llvm-cov
env:
CARGO_LLVM_COV_VERSION: "0.9.1"
run: |
case "$(uname -m)" in
aarch64|arm64)
arch="aarch64"
sha256="abf5f13c1520f8756d2192bfaaeadb0208f5b7eaa8cadc15bf847befa42b7360"
;;
*)
arch="x86_64"
sha256="b3f68e625481fed9b16444174f3fa5ebcdbde4a1878803a35eabe2dcefcdc41a"
;;
esac
archive="cargo-llvm-cov-${arch}-unknown-linux-gnu.tar.gz"
curl -fsSL --retry 3 -o "$RUNNER_TEMP/$archive" \
"https://github.com/taiki-e/cargo-llvm-cov/releases/download/v${CARGO_LLVM_COV_VERSION}/${archive}"
echo "${sha256} $RUNNER_TEMP/$archive" | sha256sum -c -
tar -xzf "$RUNNER_TEMP/$archive" -C /usr/local/bin cargo-llvm-cov
cargo llvm-cov --version
- name: Test
working-directory: ./render-wasm
env:
RENDER_WASM_COVERAGE: "true"
run: |
./test
- name: Coverage summary
if: ${{ !cancelled() && hashFiles('render-wasm/target/coverage/lcov.info') != '' }}
run: |
node scripts/coverage-summary.mjs \
--title "Render WASM test coverage" \
--note "Rust sources under \`render-wasm/src\`, measured by cargo-llvm-cov on the native test build." \
--lcov render-wasm/target/coverage/lcov.info \
> render-wasm/target/coverage/summary.md
cat render-wasm/target/coverage/summary.md >> "$GITHUB_STEP_SUMMARY"
- name: Coverage comment
# Fork PRs get a read-only token, so only branches of this repo comment.
if: ${{ !cancelled() && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && hashFiles('render-wasm/target/coverage/lcov.info') != '' }}
continue-on-error: true
env:
GITHUB_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
node scripts/coverage-comment.mjs \
--project "Render WASM" \
--lcov render-wasm/target/coverage/lcov.info \
--llvm-json render-wasm/target/coverage/summary.json
- name: Upload coverage report
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
if: ${{ !cancelled() }}
with:
name: render-wasm-coverage
path: render-wasm/target/coverage/
overwrite: true
if-no-files-found: ignore
retention-days: 7