Skip to content

feat(tool/cmd/coverage): write per-package report to step summary - #7877

Draft
g-husam wants to merge 1 commit into
mainfrom
ci/coverage-threshold
Draft

g-husam wants to merge 1 commit into
mainfrom
ci/coverage-threshold

Conversation

@g-husam

@g-husam g-husam commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

The coverage tool now appends a Markdown report to the file named by GITHUB_STEP_SUMMARY when that variable is set. The report shows the total statement coverage, the target, whether the check passed, and a per-package breakdown aggregated from coverage.out.

Previously the coverage result was only visible in the job log. Every workflow already runs this tool, so each pull request now gets a coverage report on its workflow run summary page without workflow changes, extra permissions, or new dependencies.

The coverage tool now appends a Markdown report to the file named by
GITHUB_STEP_SUMMARY when that variable is set. The report shows the total
statement coverage, the target, whether the check passed, and a per-package
breakdown aggregated from coverage.out.

Previously the coverage result was only visible in the job log. Every
workflow already runs this tool, so each pull request now gets a coverage
report on its workflow run summary page without workflow changes, extra
permissions, or new dependencies.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request adds functionality to append a Markdown coverage report to the file specified by the GITHUB_STEP_SUMMARY environment variable, which is useful for GitHub Actions. It includes functions to parse Go coverage profiles, aggregate statement coverage by package, and format the results into a Markdown table, along with comprehensive unit tests. Feedback suggests simplifying the file closing and error handling logic in the writeStepSummary function to improve readability.

Comment thread tool/cmd/coverage/main.go
Comment on lines +148 to +170
func writeStepSummary(total, target float64) error {
name := os.Getenv("GITHUB_STEP_SUMMARY")
if name == "" {
return nil
}
profile, err := os.ReadFile("coverage.out")
if err != nil {
return err
}
pkgs, err := packageCoverage(string(profile))
if err != nil {
return err
}
f, err := os.OpenFile(name, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
if err != nil {
return err
}
if _, err := f.WriteString(formatSummary(total, target, pkgs)); err != nil {
f.Close()
return err
}
return f.Close()
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Prefer simple and direct resource closing (e.g., calling Close() directly and handling the error) over complex anonymous functions with deferred closes and named return values, to keep the code simple and readable.

func writeStepSummary(total, target float64) error {
	name := os.Getenv("GITHUB_STEP_SUMMARY")
	if name == "" {
		return nil
	}
	profile, err := os.ReadFile("coverage.out")
	if err != nil {
		return err
	}
	pkgs, err := packageCoverage(string(profile))
	if err != nil {
		return err
	}
	f, err := os.OpenFile(name, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
	if err != nil {
		return err
	}
	_, err = f.WriteString(formatSummary(total, target, pkgs))
	if cerr := f.Close(); err == nil {
		err = cerr
	}
	return err
}
References
  1. Prefer simple and direct resource closing (e.g., calling Close() directly and handling the error) over complex anonymous functions with deferred closes and named return values, to keep the code simple and readable.

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