Repository navigation
Expand file tree
/
Copy pathpublish-pr-coverage-results.yml
More file actions
70 lines (61 loc) · 2.6 KB
/
Copy pathpublish-pr-coverage-results.yml
File metadata and controls
70 lines (61 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
name: Publish Code Coverage Results
on:
workflow_run:
workflows: ["Receive Pull Request"]
types:
- completed
permissions:
contents: read
jobs:
publish-test-results:
name: Publish Code Coverage Results
runs-on: ubuntu-latest
permissions:
actions: read
# the build-and-test job might be skipped, we don't need to run this job then
if: >-
${{ github.event.workflow_run.event == 'pull_request' &&
( github.event.workflow_run.conclusion == 'success' ||
github.event.workflow_run.conclusion == 'failure' ) }}
steps:
# The artifact comes from an untrusted pull request build. It is downloaded
# outside the workspace, nothing in it is ever executed, and only regular
# coverage.cobertura.xml files are read from it as data.
- name: 'Download artifact'
uses: actions/download-artifact@v8
with:
name: coverage-reports
path: ${{ runner.temp }}/artifacts
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}
- name: Download Codacy Coverage Reporter
env:
CODACY_REPORTER_VERSION: 14.1.3
CODACY_REPORTER_SHA256: 15c5f052207d27b8501ab5d5910c68c206ea70b0157ee1725132780530580875
run: |
reporter="$RUNNER_TEMP/codacy/codacy-coverage-reporter"
mkdir -p "$(dirname "$reporter")"
curl --proto "=https" --proto-redir "=https" --tlsv1.2 -fsSL --retry 3 -o "$reporter" \
"https://github.com/codacy/codacy-coverage-reporter/releases/download/${CODACY_REPORTER_VERSION}/codacy-coverage-reporter-linux"
echo "${CODACY_REPORTER_SHA256} ${reporter}" | sha256sum --check --strict
chmod +x "$reporter"
- name: Publish Code Coverage Results
env:
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
run: |
if [[ ! "$HEAD_SHA" =~ ^[0-9a-f]{40}$ ]]; then
echo "::error::Unexpected head SHA format"
exit 1
fi
reports=()
while IFS= read -r -d '' file; do
reports+=(-r "$file")
done < <(find "$RUNNER_TEMP/artifacts" -type f -name "coverage.cobertura.xml" -print0)
if [ ${#reports[@]} -eq 0 ]; then
echo "::error::No coverage reports found in artifact"
exit 1
fi
reporter="$RUNNER_TEMP/codacy/codacy-coverage-reporter"
"$reporter" report --commit-uuid "$HEAD_SHA" "${reports[@]}" --partial &&\
"$reporter" final --commit-uuid "$HEAD_SHA"