Skip to content

ci: add coverage workflow with Coveralls - #1474

Open
ligurio wants to merge 1 commit into
EmmyLuaLs:mainfrom
ligurio:ligurio/gh-xxxx-cov
Open

ligurio wants to merge 1 commit into
EmmyLuaLs:mainfrom
ligurio:ligurio/gh-xxxx-cov

Conversation

@ligurio

@ligurio ligurio commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Measure workspace test coverage with cargo-llvm-cov and upload the resulting LCOV report to Coveralls.

  • Run on push to main and pull_request targeting main, plus workflow_dispatch.
  • Use --workspace --all-features to match the test suite in test.yml.
  • Install llvm-tools-preview and cargo-llvm-cov via taiki-e/install-action.
  • Cache cargo/target with Swatinem/rust-cache (shared-key: coverage).
  • Authenticate to Coveralls with GITHUB_TOKEN; the job fails if upload fails.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review: .github/workflows/coverage.yml

Overall this is a clean, idiomatic workflow. A few issues and suggestions below.

Issues

  1. Coveralls upload on pull_request from forks (GITHUB_TOKEN / secrets) — Medium

    • coverallsapp/github-action@v2 requires a token to upload. GITHUB_TOKEN works for pushes but may behave inconsistently on PRs from forks (secrets are not exposed to fork PRs by default). Recommend guarding the upload step or using pull_request_target/COVERALLS_REPO_TOKEN as appropriate:
      - name: Upload to Coveralls
        if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false
        uses: coverallsapp/github-action@v2
        with:
          file: ./lcov.info
          format: lcov
          github-token: ${{ secrets.GITHUB_TOKEN }}
  2. Coveralls parallel / flag-name not set — Low

    • With a single job this is fine, but if coverage is ever split across jobs you'll need parallel: true + flag-name and a coverallsapp/github-action@v2 finalizer (carryforward/finish). Worth a comment for future maintainers.
  3. --all-features coverage cost — Informational

    • cargo llvm-cov --workspace --all-features can be slow and may fail if mutually exclusive features exist. Confirm no conflicting features; otherwise consider --no-default-features --features ci.
  4. fetch-depth: 0 — Nit

    • Typically needed for accurate line/changed-code coverage (Coveralls computes diff vs. base). Good that you included it — no change needed, just noting it's intentional.
  5. Missing concurrency group — Low

    • Multiple PR pushes will queue duplicate runs. Consider:
      concurrency:
        group: coverage-${{ github.ref }}
        cancel-in-progress: true
  6. Pin installer action to a version — Low

    • taiki-e/install-action@cargo-llvm-cov is pinned by tool name, which is acceptable, but consider @v2 plus tool: cargo-llvm-cov for explicit version pinning and reproducibility:
      - uses: taiki-e/install-action@v2
        with:
          tool: cargo-llvm-cov
  7. LCOV upload path — Nit

    • file: ./lcov.info vs. output-path lcov.info — consistent, but prefer a workspace-relative path without ./ to avoid ambiguity (lcov.info).
  8. No artifact retention of lcov.info — Nit

    • Optional: add actions/upload-artifact on failure/always so reviewers can inspect coverage locally if Coveralls upload fails.

Style / consistency

  • env values as bare scalars (RUST_BACKTRACE: 1) are fine, though some linters (actionlint/yamllint) prefer strings. Not a blocker.
  • permissions: contents: read is good and least-privilege for checkout.
  • Job timeout (60 min) and cache key (shared-key: coverage) look reasonable.

No issues found in

  • Branch triggers, workflow_dispatch, toolchain component (llvm-tools-preview), cache strategy, and general structure are correct.

Summary

Severity Item
Medium Coveralls upload token behavior on fork PRs — add if: guard
Low Add concurrency to cancel stale runs
Low Pin taiki-e/install-action to a version
Nit Normalize lcov.info path; consider artifact upload

@ligurio

ligurio commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Summary of changes

  • Added a concurrency group so stale pull-request runs are cancelled.
  • Pinned taiki-e/install-action to v2 with an explicit
    tool: cargo-llvm-cov input.
  • Normalized the LCOV path to lcov.info.
  • Added an if: guard so the Coveralls upload is skipped for pull requests from
    forks instead of failing the job.
  • No artifact-upload step was added (see item 8).

Medium severity

1. Coveralls upload token behavior on pull requests from forks

Status: fixed (guard added); pull_request_target intentionally not used.

Secrets are not exposed to workflows triggered by pull_request events from
forks, so a fork PR cannot upload coverage using a repository secret. A
read-only GITHUB_TOKEN may or may not be accepted by Coveralls, so the upload
is now skipped for fork PRs to avoid spurious red runs:

if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false

pull_request_target is not a safe fix here: running the test suite requires
checking out and executing untrusted code from the PR, which would do so with a
write-capable token. If coverage for fork PRs becomes a requirement, the secure
pattern is a two-workflow setup: run tests on pull_request without a token,
upload lcov.info as an artifact, and have a separate workflow_run workflow
that only downloads the artifact and posts it to Coveralls.

Tradeoff: coverage is currently not reported for fork PRs. Same-repository PRs
and pushes to main are unaffected.

Low severity

2. Coveralls parallel jobs / flag-name not set

Status: not changed.

A single job produces the whole report, so parallel: true, flag-name, and a
parallel-finished finalizer are unnecessary. If coverage is ever split across
multiple jobs, the workflow will need those inputs plus a finalizer job with
parallel-finished: true and carryforward.

5. Missing concurrency group

Status: fixed.

concurrency:
  group: coverage-${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: ${{ github.event_name == 'pull_request' }}

Only pull-request runs are cancelled; pushes to main are allowed to finish so
the main-branch coverage history is not interrupted.

6. Pin the installer action

Status: fixed.

- uses: taiki-e/install-action@v2
  with:
    tool: cargo-llvm-cov

The @v2 action with an explicit tool input is the documented form and gives
a reproducible pinning point.

Informational

3. --all-features coverage cost

Status: kept as is.

The workspace declares no mutually exclusive features. --all-features enables
cli (for the binary crates) and slow-tests (for emmylua_code_analysis and
emmylua_ls); there are no compile_error! guards for conflicting features.
This also matches the existing test job in test.yml
(cargo test --workspace --all-features), so coverage reflects the same test set
that CI already runs.

Nits

4. fetch-depth: 0

Status: intentional.

Full history is fetched so Coveralls can compute changed-code/diff coverage and
resolve the base commit for pull requests.

7. LCOV upload path

Status: fixed.

The upload now uses file: lcov.info (workspace-relative) instead of
./lcov.info.

8. Artifact retention of lcov.info

Status: not changed (by design).

Keeping lcov.info as a workflow artifact is useful for local inspection when
the Coveralls upload fails, but it adds storage usage on every run. This was
deliberately left out; it can be added later with
actions/upload-artifact@v4, if-no-files-found: ignore, and a short
retention-days if needed.

Style / consistency

Status: no change.

Bare scalar env values such as RUST_BACKTRACE: 1 are valid YAML and accepted
by GitHub Actions. permissions: contents: read is intentional least-privilege
access for checkout; the Coveralls action does not require extra GITHUB_TOKEN
permissions for uploads.

Measure workspace test coverage with cargo-llvm-cov and upload the
resulting LCOV report to Coveralls.

- Run on push to main and pull_request targeting main, plus
  workflow_dispatch.
- Use --workspace --all-features to match the test suite in test.yml.
- Install llvm-tools-preview and cargo-llvm-cov via
  taiki-e/install-action.
- Cache cargo/target with Swatinem/rust-cache (shared-key: coverage).
- Authenticate to Coveralls with GITHUB_TOKEN; the job fails if
  upload fails.
@ligurio

ligurio commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

@CppCXY The commit 3474c99 ("refactor project") introduced a number of regressions. To minimize the risk of regressions, I suggest measuring code coverage and aiming to increase it with every new change. Shall we merge it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant