Skip to content

Commit

Permalink
.github/workflows/backend-test: Add coverage report to PR comment
Browse files Browse the repository at this point in the history
This adds a line to the PR comment with a collapsable toggle
so the user can click to see the full coverage report.

Signed-off-by: René Dudfield <renedudfield@microsoft.com>
  • Loading branch information
illume committed Sep 24, 2024
1 parent dfe1498 commit f13dd94
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/backend-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,13 @@ jobs:
set -x
cd backend
go test ./... -coverprofile=coverage.out -covermode=atomic -coverpkg=./...
testcoverage_full=$(go tool cover -func=coverage.out)
testcoverage=$(go tool cover -func=coverage.out | grep total | grep -Eo '[0-9]+\.[0-9]+')
testcoverage_full_base64=$(echo "$testcoverage_full" | base64 -w 0)
echo "Code coverage: $testcoverage"
echo "$testcoverage_full"
echo "coverage=$testcoverage" >> $GITHUB_ENV
echo "testcoverage_full_base64=$testcoverage_full_base64" >> $GITHUB_ENV
echo "cleaning up..."
rm ~/.config/Headlamp/kubeconfigs/config
shell: bash
Expand Down Expand Up @@ -125,8 +129,12 @@ jobs:
exit 0
fi
testcoverage="${{ env.coverage }}"
testcoverage_full_base64="${{ env.testcoverage_full_base64 }}"
testcoverage_full=$(echo "$testcoverage_full_base64" | base64 --decode)
base_coverage="${{ env.base_coverage }}"
coverage_diff="${{ env.coverage_diff }}"
if (( $(echo "$coverage_diff < 0" | bc -l) )); then
emoji="😞" # Decreased coverage
else
Expand All @@ -135,6 +143,21 @@ jobs:
comment="Backend Code coverage changed from $base_coverage% to $testcoverage%. Change: $coverage_diff% $emoji."
echo "$comment"
# Add the full coverage report as a collapsible section
comment="${comment}
<details>
<summary>See full coverage report</summary>
\`\`\`
$testcoverage_full
\`\`\`
</details>"
echo "$comment"
if [[ "${{github.event.pull_request.head.repo.full_name}}" == "${{github.repository}}" ]]; then
# Forks (like dependabot ones) do not have permission to comment on the PR,
# so do not fail the action if this fails.
Expand Down

0 comments on commit f13dd94

Please sign in to comment.