From 9b7abf517eabe75cda2ac4b2823abd490ee7db65 Mon Sep 17 00:00:00 2001 From: Roman Zajic Date: Tue, 3 Feb 2026 15:08:09 +0800 Subject: [PATCH] chore: Test coverage report for CI (#371) ## Description Add CI script to invoke coverage report run based on label added to PR. --- .github/PULL_REQUEST_TEMPLATE.md | 12 +++++++++ .github/workflows/ci.yml | 46 +++++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 .github/PULL_REQUEST_TEMPLATE.md diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..a4f2447 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,12 @@ +## Description + + + +## Testing + + + + +## Checklist + +- [ ] I have run the CI coverage report. Add the `run-coverage` label to this PR to enable it. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e763e29..62f01e5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ on: - "!rln/resources/**" - "!utils/src/**" pull_request: - types: [opened, synchronize, reopened, ready_for_review] + types: [opened, synchronize, reopened, ready_for_review, labeled] paths-ignore: - "**.md" - "!.github/workflows/*.yml" @@ -220,3 +220,47 @@ jobs: branchName: ${{ github.base_ref }} cwd: ${{ matrix.crate }} features: ${{ matrix.feature }} + + coverage: + if: github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'run-coverage') + runs-on: ubuntu-latest + timeout-minutes: 60 + + name: Coverage Report + steps: + - name: Checkout sources + uses: actions/checkout@v4 + - name: Install stable toolchain + uses: dtolnay/rust-toolchain@stable + - uses: Swatinem/rust-cache@v2 + - name: Install dependencies + run: make installdeps + - name: Install cargo-tarpaulin + run: cargo install cargo-tarpaulin + - name: Run coverage + run: | + cargo tarpaulin --out Html --output-dir ./coverage -- --test-threads 1 + - name: Upload coverage reports + uses: actions/upload-artifact@v4 + with: + name: coverage-reports + path: ./coverage/ + - name: Comment on PR with coverage link + uses: actions/github-script@v7 + with: + script: | + const artifacts = await github.rest.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: context.runId, + }); + const coverageArtifact = artifacts.data.artifacts.find(art => art.name === 'coverage-reports'); + if (coverageArtifact) { + const artifactUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/artifacts/${coverageArtifact.id}`; + await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: `Coverage report uploaded. [Download HTML Report](${artifactUrl})` + }); + }