Skip to content

Commit

Permalink
.github/workflows/backend-test: Add coverage html report
Browse files Browse the repository at this point in the history
As an artifact, and link to the artifact to view in the browser.

Signed-off-by: René Dudfield <renedudfield@microsoft.com>
  • Loading branch information
illume committed Sep 24, 2024
1 parent f13dd94 commit d66e6d6
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions .github/workflows/backend-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ jobs:
set -x
cd backend
go test ./... -coverprofile=coverage.out -covermode=atomic -coverpkg=./...
go tool cover -html=coverage.out -o backend_coverage.html
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)
Expand All @@ -75,6 +76,19 @@ jobs:
rm ~/.config/Headlamp/kubeconfigs/config
shell: bash

- name: Upload coverage report as artifact
uses: actions/upload-artifact@v3
with:
name: backend-coverage-report
path: ./backend/backend_coverage.html

- name: Get backend_coverage artifact URL
id: get-artifact-url
run: |
ARTIFACT_ID=$(gh api -H "Accept: application/vnd.github.v3+json" /repos/${{ github.repository }}/actions/artifacts | jq -r '.artifacts[] | select(.name=="backend-coverage-report") | .id')
ARTIFACT_URL="https://github.com/${{ github.repository }}/suites/${{ github.run_id }}/artifacts/$ARTIFACT_ID"
echo "artifact_url=$ARTIFACT_URL" >> $GITHUB_ENV
- name: Get base branch code coverage
if: ${{ github.event_name }} == 'pull_request'
run: |
Expand Down Expand Up @@ -134,6 +148,7 @@ jobs:
base_coverage="${{ env.base_coverage }}"
coverage_diff="${{ env.coverage_diff }}"
artifact_url="${{ env.artifact_url }}"
if (( $(echo "$coverage_diff < 0" | bc -l) )); then
emoji="😞" # Decreased coverage
Expand All @@ -148,13 +163,16 @@ jobs:
comment="${comment}
<details>
<summary>See full coverage report</summary>
<summary>Coverage report</summary>
\`\`\`
$testcoverage_full
\`\`\`
</details>"
</details>
[Html coverage report download](artifact_url)
"
echo "$comment"
Expand Down

0 comments on commit d66e6d6

Please sign in to comment.