From 087e1926afdca0882d1baedecd98c2accd830435 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Dudfield?= Date: Tue, 24 Sep 2024 12:00:27 +0200 Subject: [PATCH] .github/workflows/backend-test: Add coverage html report MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As an artifact, and link to the artifact to view in the browser. Signed-off-by: René Dudfield --- .github/workflows/backend-test.yml | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/.github/workflows/backend-test.yml b/.github/workflows/backend-test.yml index eb3799f51d0..ce983009a7b 100644 --- a/.github/workflows/backend-test.yml +++ b/.github/workflows/backend-test.yml @@ -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) @@ -75,6 +76,21 @@ 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 + env: + GH_TOKEN: ${{ github.token }} + 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: | @@ -134,6 +150,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 @@ -148,13 +165,16 @@ jobs: comment="${comment}
- See full coverage report + Coverage report \`\`\` $testcoverage_full \`\`\` -
" + + + [Html coverage report download]($artifact_url) + " echo "$comment"