-
Notifications
You must be signed in to change notification settings - Fork 22
Add coverage-report.json and enable report update via CI #246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+107
−0
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7731915
Add coverage report and update workflow
mohanmanikanta2299 2b6d046
Added permission to write.
mohanmanikanta2299 e25249a
chore: update coverage report
github-actions[bot] 66f3930
revert: enable workflow to run on-push for main branch.
mohanmanikanta2299 cc5a1dc
Commit coverage-report only on push.
mohanmanikanta2299 f906d28
compute line coverage
mohanmanikanta2299 8f0d577
Update script for line compute
mohanmanikanta2299 33e9f73
chore: update coverage report
github-actions[bot] 73343ea
enable on-push for main branch only
mohanmanikanta2299 8243405
Create a separate job for updating coverage-report
mohanmanikanta2299 f51144b
refactor: python script, raise PR for coverage report update.
mohanmanikanta2299 7c67a18
Test:PR generation on push in non-main branch
mohanmanikanta2299 340c48f
minor fixes to compute coverage, ignore coverage.out file from commits
mohanmanikanta2299 eff94f1
revert test changes
mohanmanikanta2299 a605931
pinned gha commit hash and added comments.
mohanmanikanta2299 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import json | ||
| import os | ||
| import subprocess | ||
| import datetime | ||
|
|
||
| covered = 0 | ||
| total = 0 | ||
| with open("coverage.out", "r", encoding="utf-8") as f: | ||
| next(f) # skip mode line | ||
| for line in f: | ||
| line = line.strip() | ||
| if not line: | ||
| continue | ||
| try: | ||
| _, num_stmts, num_executed = line.rsplit(" ", 2) | ||
| num_stmts = int(num_stmts) | ||
| num_executed = int(num_executed) | ||
| except ValueError: | ||
| continue | ||
| total += num_stmts | ||
| if num_executed > 0: | ||
| covered += num_stmts | ||
|
|
||
| # Use go tool cover -func for line_rate so it matches the CI display value. | ||
| # It uses AST function boundaries and excludes non-function-level blocks, | ||
| # which is why it differs from the raw block count above. | ||
| out = subprocess.check_output(["go", "tool", "cover", "-func=coverage.out"], text=True) | ||
| line_rate = 0.0 | ||
| for row in out.splitlines(): | ||
| if row.startswith("total:"): | ||
| line_rate = float(row.split()[-1].rstrip("%")) | ||
| break | ||
|
|
||
| # Derive lines_total so that lines_covered / lines_total == line_rate. | ||
| lines_total = round(covered / (line_rate / 100)) if line_rate > 0 else total | ||
|
|
||
| repo = os.environ["GITHUB_REPOSITORY"] | ||
| report = { | ||
| "repo": repo, | ||
| "language": "go", | ||
| "date": datetime.date.today().isoformat(), | ||
| "commit": os.environ.get("GITHUB_SHA", "")[:7], | ||
| "branch": os.environ.get("GITHUB_REF_NAME", "main"), | ||
| "run_url": f"https://github.com/{repo}/actions/runs/{os.environ['GITHUB_RUN_ID']}", | ||
| "line_rate": line_rate, | ||
| "lines_covered": covered, | ||
| "lines_total": lines_total, | ||
| } | ||
|
|
||
| with open("coverage-report.json", "w", encoding="utf-8") as f: | ||
| json.dump(report, f, indent=2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,3 +10,6 @@ copywrite | |
|
|
||
| # Ignore local configs | ||
| .env | ||
|
|
||
| # Go test coverage profiles | ||
| coverage.out | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "repo": "hashicorp/copywrite", | ||
| "language": "go", | ||
| "date": "2026-07-01", | ||
| "commit": "8f0d577", | ||
| "branch": "feature/add_coverage_file", | ||
| "run_url": "https://github.com/hashicorp/copywrite/actions/runs/28511185693", | ||
| "line_rate": 81.8, | ||
|
mohanmanikanta2299 marked this conversation as resolved.
|
||
| "lines_covered": 1017, | ||
| "lines_total": 1414 | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.