Skip to content

Commit 38d6d04

Browse files
Add workflow to upload coverage and test reports
1 parent fa8985f commit 38d6d04

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Publish test and coverage results
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Lint and test"]
6+
types:
7+
- completed
8+
9+
jobs:
10+
publish-test-results:
11+
name: "Publish test and coverage results"
12+
runs-on: ubuntu-latest
13+
if: github.event.workflow_run.conclusion != 'skipped' && github.repository_owner == 'Uninett'
14+
15+
steps:
16+
# Checking out the repo is necessary codecov/codecov-action@v5 to work properly
17+
# Codecov requires source code to process the coverage file and generate coverage
18+
# reports
19+
- name: Checkout Code
20+
uses: actions/checkout@v4
21+
with:
22+
ref: ${{ github.event.workflow_run.head_sha }}
23+
24+
- name: Download and Extract Artifacts
25+
env:
26+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
27+
run: |
28+
mkdir -p artifacts && cd artifacts
29+
30+
artifacts_url=${{ github.event.workflow_run.artifacts_url }}
31+
32+
gh api "$artifacts_url" -q '.artifacts[] | [.name, .archive_download_url] | @tsv' | while read artifact
33+
do
34+
IFS=$'\t' read name url <<< "$artifact"
35+
gh api $url > "$name.zip"
36+
unzip -o -d "$name" "$name.zip"
37+
done
38+
39+
- name: "Publish test results"
40+
uses: EnricoMi/publish-unit-test-result-action@v2
41+
with:
42+
commit: ${{ github.event.workflow_run.head_sha }}
43+
check_name: "Test results"
44+
files: artifacts/**/*-results.xml
45+
46+
- name: Read PR number file
47+
if: ${{ hashFiles('artifacts/extra/pr_number') != '' }}
48+
run: |
49+
pr_number=$(cat artifacts/extra/pr_number)
50+
re='^[0-9]+$'
51+
if [[ $pr_number =~ $re ]] ; then
52+
echo "PR_NUMBER=$pr_number" >> $GITHUB_ENV
53+
fi
54+
55+
- name: Read base SHA file
56+
if: ${{ hashFiles('artifacts/extra/base_sha') != '' }}
57+
run: |
58+
base_sha=$(cat artifacts/extra/base_sha)
59+
re='[0-9a-f]{40}'
60+
if [[ $base_sha =~ $re ]] ; then
61+
echo "BASE_SHA=$base_sha" >> $GITHUB_ENV
62+
fi
63+
64+
- name: Upload to Codecov
65+
uses: codecov/codecov-action@v5
66+
with:
67+
fail_ci_if_error: true
68+
token: ${{ secrets.CODECOV_TOKEN }}
69+
verbose: true
70+
override_branch: ${{ github.event.workflow_run.head_branch}}
71+
override_commit: ${{ github.event.workflow_run.head_sha}}
72+
commit_parent: ${{ env.BASE_SHA }}
73+
override_pr: ${{ env.PR_NUMBER }}

0 commit comments

Comments
 (0)