Skip to content

ci: measure test coverage and add Codecov badge - #267

Merged
shenxianpeng merged 2 commits into
mainfrom
chore/add-code-coverage
Aug 12, 2026
Merged

ci: measure test coverage and add Codecov badge#267
shenxianpeng merged 2 commits into
mainfrom
chore/add-code-coverage

Conversation

@shenxianpeng

@shenxianpeng shenxianpeng commented Aug 12, 2026

Copy link
Copy Markdown
Member

What

Mirror the coverage setup that commit-check already has:

  1. Measure coverage — new .github/workflows/coverage.yml runs the suite with pytest-cov on every push to main and every PR, then uploads coverage.xml to Codecov.
  2. Show the percentage in the README — Codecov badge in the header, linked to the commit-check-action report.

Design notes

  • Based on the earlier draft in chore/test-add-pr-comments-coverage (which was never merged), including its reviewed tweaks:
    • actions pinned to commit SHAs per repo convention
    • fail_ci_if_error only on push to main, so a flaky upload never blocks a PR
    • permissions: contents: read
  • Coverage is measured once on ubuntu-latest / Python 3.10 (the repo's floor, see test.yml) rather than from the whole 3×2 test matrix — a single deterministic upload, same as the sibling repo's approach.
  • No explicit secrets.CODECOV_TOKEN input: codecov-action@v7 uploads tokenlessly for public repos. If you'd rather pin it explicitly, adding token: ${{ secrets.CODECOV_TOKEN }} is a one-liner (that's what commit-check does).
  • .gitignore gains .coverage*, coverage.xml, htmlcov/; existing entries untouched.

Verified locally

  • pytest --cov=main main_test.py116 passed, 92% coverage (419 stmts, 32 miss)
  • Badge URL returns 200 and renders an SVG: https://codecov.io/gh/commit-check/commit-check-action/branch/main/graph/badge.svg?token=G3R0LFO0YF (token was already public in the repo history)
  • pre-commit passes on all touched files

Note: the badge shows the percentage only after the first upload lands on main.

Summary by CodeRabbit

  • Quality Improvements
    • Added automated test coverage checks for changes submitted to the main branch.
    • Coverage reports are uploaded for tracking and review.
  • Documentation
    • Added a coverage status badge to the project README.

@shenxianpeng
shenxianpeng requested a review from a team as a code owner August 12, 2026 19:36
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@shenxianpeng, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 54 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5a321e6d-ad6e-4669-b369-bc7f05f027ce

📥 Commits

Reviewing files that changed from the base of the PR and between c6c6102 and 97c01ec.

📒 Files selected for processing (1)
  • README.md
📝 Walkthrough

Walkthrough

The PR adds a GitHub Actions coverage workflow, ignores generated coverage files, and adds a Codecov badge to the README.

Changes

Coverage reporting

Layer / File(s) Summary
Coverage workflow
.github/workflows/coverage.yml
Runs tests with coverage on pushes and pull requests targeting main. Uploads coverage.xml to Codecov with different failure behavior for pushes and pull requests.
Coverage artifacts and status
.gitignore, README.md
Ignores generated coverage outputs and adds a Codecov coverage badge.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested labels: enhancement

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main changes: measuring test coverage and adding a Codecov badge.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/add-code-coverage

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Commit Check

All 6 checks passed

Show all 6 checks
Commit message
  ✔ PR title (ci: measure test coverage and add Codecov badge)
  ✔ Commit 1/2 (ci: measure test coverage and add Codecov badge)
  ✔ Commit 2/2 (chore: Change Codecov badge token)
Branch
  ✔ Branch (chore/add-code-coverage)
Author
  ✔ Author name (Xianpeng Shen)
  ✔ Author email (xianpeng.shen@gmail.com)

commit-check 2.14.0 · Rules reference

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/coverage.yml:
- Line 16: Update the actions/checkout step in the coverage workflow to set
persist-credentials to false, preventing the checkout token from remaining in
local Git configuration while preserving the existing pinned action reference.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9e5559e2-b93c-449f-83c1-f1feb4ecff55

📥 Commits

Reviewing files that changed from the base of the PR and between 2f0a330 and c6c6102.

📒 Files selected for processing (3)
  • .github/workflows/coverage.yml
  • .gitignore
  • README.md

coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- workflow ---'
cat -n .github/workflows/coverage.yml
printf '%s\n' '--- checkout references ---'
rg -n -C 3 'actions/checkout|persist-credentials|pull_request|permissions|run:' .github/workflows
printf '%s\n' '--- pinned action metadata ---'
curl -fsSL 'https://raw.githubusercontent.com/actions/checkout/3d3c42e5aac5ba805825da76410c181273ba90b1/action.yml' | sed -n '1,180p'

Repository: commit-check/commit-check-action

Length of output: 15131


🏁 Script executed:

#!/bin/bash
set -e
python3 - <<'PY'
import re
from pathlib import Path
from urllib.request import urlopen

workflow = Path(".github/workflows/coverage.yml").read_text()
metadata_url = (
    "https://raw.githubusercontent.com/actions/checkout/"
    "3d3c42e5aac5ba805825da76410c181273ba90b1/action.yml"
)
metadata = urlopen(metadata_url, timeout=10).read().decode()

assert re.search(r"^\s*pull_request:\s*$", workflow, re.M)
assert re.search(r"^\s*permissions:\s*$", workflow, re.M)
assert re.search(r"^\s+contents:\s+read\s*$", workflow, re.M)
checkout = workflow.index("actions/checkout@")
first_run = workflow.index("run:", checkout)
assert first_run > checkout
assert re.search(
    r"persist-credentials:\s*[\r\n ]",
    metadata,
)
assert re.search(
    r"persist-credentials:\s*\n(?:\s+.*\n)*?\s+default:\s*true\b",
    metadata,
)

print("pull_request trigger: present")
print("job token permission: contents: read")
print("repository-controlled run step after checkout: present")
print("pinned actions/checkout persist-credentials default: true")
print("pinned actions/checkout token input default: github.token")
PY

Repository: commit-check/commit-check-action

Length of output: 2457


🏁 Script executed:

#!/bin/bash
set -e
python3 - <<'PY'
import re
from pathlib import Path
from urllib.request import urlopen

workflow = Path(".github/workflows/coverage.yml").read_text()
metadata = urlopen(
    "https://raw.githubusercontent.com/actions/checkout/"
    "3d3c42e5aac5ba805825da76410c181273ba90b1/action.yml",
    timeout=10,
).read().decode()

assert re.search(r"^\s*pull_request:\s*$", workflow, re.M)
assert re.search(r"^\s*contents:\s+read\s*$", workflow, re.M)
checkout = workflow.index("actions/checkout@")
assert workflow.index("run:", checkout) > checkout
assert re.search(
    r"persist-credentials:\s*\n(?:\s+.*\n)*?\s+default:\s*true\b",
    metadata,
)
assert re.search(r"default:\s*\$\{\{\s*github\.token\s*\}\}", metadata)

print("pull_request trigger: present")
print("job token permission: contents: read")
print("post-checkout run step: present")
print("persist-credentials default: true")
print("token default: github.token")
PY

Repository: commit-check/commit-check-action

Length of output: 2456


🏁 Script executed:

#!/bin/bash
set -e
curl -fsSL \
  'https://raw.githubusercontent.com/actions/checkout/3d3c42e5aac5ba805825da76410c181273ba90b1/action.yml' |
python3 -c '
import re
import sys
from pathlib import Path

workflow = Path(".github/workflows/coverage.yml").read_text()
metadata = sys.stdin.read()

assert re.search(r"^\s*pull_request:\s*$", workflow, re.M)
assert re.search(r"^\s*contents:\s+read\s*$", workflow, re.M)
checkout = workflow.index("actions/checkout@")
assert workflow.index("run:", checkout) > checkout
assert re.search(
    r"persist-credentials:\s*\n(?:\s+.*\n)*?\s+default:\s*true\b",
    metadata,
)
assert re.search(r"default:\s*\$\{\{\s*github\.token\s*\}\}", metadata)

print("pull_request trigger: present")
print("job token permission: contents: read")
print("post-checkout run step: present")
print("persist-credentials default: true")
print("token default: github.token")
'

Repository: commit-check/commit-check-action

Length of output: 331


Disable checkout credential persistence.

Because this pull_request job runs repository-controlled code after checkout, the default persist-credentials: true exposes the contents: read token through local Git configuration. Set persist-credentials: false.

Proposed fix
       - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+        with:
+          persist-credentials: false
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
🧰 Tools
🪛 zizmor (1.29.0)

[warning] 16-16: credential persistence through GitHub Actions artifacts (artipacked): does not set persist-credentials: false

(artipacked)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/coverage.yml at line 16, Update the actions/checkout step
in the coverage workflow to set persist-credentials to false, preventing the
checkout token from remaining in local Git configuration while preserving the
existing pinned action reference.

Source: Linters/SAST tools

Updated Codecov badge token in README.md
@shenxianpeng shenxianpeng added the maintenance Maintenance update label Aug 12, 2026
@shenxianpeng
shenxianpeng merged commit 74c6dcb into main Aug 12, 2026
16 checks passed
@shenxianpeng
shenxianpeng deleted the chore/add-code-coverage branch August 12, 2026 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Maintenance update

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant