-
Notifications
You must be signed in to change notification settings - Fork 3
167 lines (150 loc) · 5.61 KB
/
coverage-report.yml
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
name: Coverage Report
on:
workflow_call:
inputs:
actions-repo:
type: string
default: 'nubificus/vaccel'
actions-rev:
type: string
default: 'main'
options:
type: string
default: 'auto_features=enabled'
commit:
type: boolean
default: false
comment-diff:
type: boolean
default: false
secrets:
GIT_CLONE_PAT:
required: false
env:
ACTIONS_REV: ${{ (github.repository != inputs.actions-repo) && inputs.actions-rev || '' }}
jobs:
coverage-report:
name: Coverage Report
runs-on: [gcc-dind-2204-amd64]
strategy:
matrix:
build-type: [plain]
fail-fast: false
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout .github directory
uses: actions/checkout@v4
with:
sparse-checkout: .github
repository: ${{ inputs.actions-repo }}
ref: ${{ env.ACTIONS_REV }}
- name: Set repository directories
id: set-repo-dirs
run: |
echo "repo=${{ github.event.repository.name }}" >> "$GITHUB_OUTPUT"
echo "repo-default=${{ github.event.repository.name }}_${{ github.event.repository.default_branch }}" \
>> "$GITHUB_OUTPUT"
shell: bash
- name: Initialize workspace
uses: ./.github/actions/initialize-workspace
with:
remote-actions-repo: ${{ inputs.actions-repo }}
token: ${{ secrets.GIT_CLONE_PAT || github.token }}
dot-github-only: 'true'
- name: Checkout current branch
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref || github.ref_name }}
path: ${{ steps.set-repo-dirs.outputs.repo }}
- name: Build project
uses: ./.github/actions/build
with:
build-path: build_${{ matrix.build-type }}
build-type: ${{ matrix.build-type }}
source-path: ${{ steps.set-repo-dirs.outputs.repo }}
coverage: 'true'
options: ${{ inputs.options }}
- name: Generate coverage report
uses: ./.github/actions/run-tests
with:
build-path: build_${{ matrix.build-type }}
source-path: ${{ steps.set-repo-dirs.outputs.repo }}
coverage: 'true'
- name: Checkout default_branch
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.repository.default_branch }}
path: ${{ steps.set-repo-dirs.outputs.repo-default }}
- name: Build project @default_branch
if: ${{ inputs.comment-diff == true }}
uses: ./.github/actions/build
with:
build-path: build_${{ matrix.build-type }}
build-type: ${{ matrix.build-type }}
source-path: ${{ steps.set-repo-dirs.outputs.repo-default }}
coverage: 'true'
options: ${{ inputs.options }}
- name: Generate coverage report @default_branch
if: ${{ inputs.comment-diff == true }}
uses: ./.github/actions/run-tests
with:
build-path: build_${{ matrix.build-type }}
source-path: ${{ steps.set-repo-dirs.outputs.repo-default }}
coverage: 'true'
- name: Calculate coverage diff
if: ${{ inputs.comment-diff == true }}
run: |
pycobertura diff \
"$(find \
"${{ steps.set-repo-dirs.outputs.repo-default }}/build_${{ matrix.build-type }}" \
-name "coverage*.xml")" \
"$(find \
"${{ steps.set-repo-dirs.outputs.repo }}/build_${{ matrix.build-type }}" \
-name "coverage*.xml")" \
--no-color --no-source -f markdown > coverage_diff.txt || PYCOB_RESULT="$?"
echo "pycobertura exited with ${PYCOB_RESULT:-0}"
[ "$PYCOB_RESULT" == 1 ] && exit 1
echo -e '# Coverage report diff\n' > coverage_diff.md && \
cat coverage_diff.txt >> coverage_diff.md
shell: bash
- name: PR comment with file
if: ${{ inputs.comment-diff == true }}
uses: thollander/actions-comment-pull-request@v3
with:
file-path: ./coverage_diff.md
comment-tag: coverage
mode: recreate
- name: Generate markdown file
id: generate-md-file
if: ${{ inputs.commit == true }}
run: |
COVERAGE_FILE="docs/tests/coverage/coverage.md"
pycobertura show \
"$(find "${{ steps.set-repo-dirs.outputs.repo }}/build_${{ matrix.build-type }}" \
-name "coverage*.xml")" \
--format markdown --output "coverage.md"
printf "%s\n%s\n\n" \
'<!-- markdownlint-disable-file MD013 -->' \
'# Tests coverage report' \
> "${{ steps.set-repo-dirs.outputs.repo }}/$COVERAGE_FILE"
cat coverage.md >> "${{ steps.set-repo-dirs.outputs.repo }}/$COVERAGE_FILE"
rm -f coverage.md
echo "coverage-file=${COVERAGE_FILE}" >> "$GITHUB_OUTPUT"
shell: bash
- name: Commit report
if: ${{ inputs.commit == true }}
uses: ./.github/actions/commit-file
with:
workdir: ${{ steps.set-repo-dirs.outputs.repo }}
branch: ${{ github.event.pull_request.head.ref || github.ref_name }}
file: ${{ steps.generate-md-file.outputs.coverage-file }}
message: "docs(coverage): Update coverage report"
- name: Clean-up
if: ${{ always() }}
run: |
sudo rm -rf coverage* ${{ steps.set-repo-dirs.outputs.repo }} \
${{ steps.set-repo-dirs.outputs.repo-default }}