-
Notifications
You must be signed in to change notification settings - Fork 40
196 lines (175 loc) · 7.08 KB
/
Copy pathci-gcovr.yml
File metadata and controls
196 lines (175 loc) · 7.08 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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
name: Code coverage
on:
workflow_dispatch:
pull_request:
# schedule:
# - cron: '0 20 * * *' # Every day at 12pm PST (UTC-8)
env:
BUILD_TYPE: Debug
MOUNT: /azure-osconfig
REGISTRY: ghcr.io
jobs:
create-ci-matrix:
name: Build CI distro matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.get-matrix.outputs.matrix }}
steps:
- name: Get matrix
id: get-matrix
run: |
matrix="$(cat <<'EOL'
[
{ "name": "ubuntu-22.04", "arch": "amd64", "tag": "@sha256:0eed71cef37604c37186ec035974168a40a84d27e26d3b746a2858d99f305e2e" }
]
EOL
)"
echo Distros to perform CI on: $matrix
echo matrix=$matrix >> $GITHUB_OUTPUT
unit-test:
name: Execute tests and gcovr
needs: create-ci-matrix
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target: ${{ fromJson(needs.create-ci-matrix.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
clean: true
- name: Docker login
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Run container
id: container
uses: ./.github/actions/container-run
with:
registry: ${{ env.REGISTRY }}
container: azure/azure-osconfig/${{ matrix.target.name }}-${{ matrix.target.arch }}
mount: ${{ github.workspace }}:${{ env.MOUNT }}
tag: ${{ matrix.target.tag }}
- name: Generate build
uses: ./.github/actions/container-exec
with:
container: ${{ steps.container.outputs.id }}
cmd: |
mkdir build && cd build
cmake ../src -DCMAKE_C_COMPILER='/usr/bin/gcc' -DCMAKE_CXX_COMPILER='/usr/bin/g++' -DCMAKE_build-type=${{ env.BUILD_TYPE }} -Duse_prov_client=ON -Dhsm_type_symm_key=ON -DCOMPILE_WITH_STRICTNESS=ON -DBUILD_TESTS=ON -DBUILD_SAMPLES=ON -DBUILD_ADAPTERS=ON -Duse_default_uuid=ON -DCOVERAGE=ON
- name: Build Azure OSConfig
uses: ./.github/actions/container-exec
with:
container: ${{ steps.container.outputs.id }}
working-directory: ${{ env.MOUNT }}/build
cmd: cmake --build . --config ${{ env.BUILD_TYPE }} --parallel
- name: Install dependencies
uses: ./.github/actions/container-exec
with:
container: ${{ steps.container.outputs.id }}
cmd: |
apt-get update
apt-get install -y gcovr
- name: Run ctest
uses: ./.github/actions/container-exec
with:
container: ${{ steps.container.outputs.id }}
working-directory: ${{ env.MOUNT }}/build
cmd: ctest --verbose | tee ../${{ matrix.target.name }}-${{ matrix.target.arch }}-ctest.log || true
- name: Run moduletest
uses: ./.github/actions/container-exec
with:
container: ${{ steps.container.outputs.id }}
working-directory: ${{ env.MOUNT }}/build
cmd: bash ${{ env.MOUNT }}/devops/scripts/run-module-tests-action.sh ${{ env.MOUNT }} ${{ env.MOUNT }}/build || true
- name: Run gcovr
uses: ./.github/actions/container-exec
with:
container: ${{ steps.container.outputs.id }}
working-directory: ${{ env.MOUNT }}/build
cmd: |
mkdir -p ../${{ matrix.target.name }}-${{ matrix.target.arch }}
gcovr --root ../ \
--html-details -o ../${{ matrix.target.name }}-${{ matrix.target.arch }}/coverage.html \
--json-summary-pretty --json-summary ../${{ matrix.target.name }}-${{ matrix.target.arch }}/coverage.summary.json \
--json-pretty --json ../${{ matrix.target.name }}-${{ matrix.target.arch }}/coverage.json \
--exclude '.*/adapters/.*' \
--exclude '.*/azure-iot-sdk-c/.*' \
--exclude '.*/modules/test/.*' \
--exclude '.*/tests/.*' \
--gcov-ignore-parse-errors
cp module-test.log ../${{ matrix.target.name }}-${{ matrix.target.arch }}-module-test.log
- uses: actions/upload-artifact@v4
if: success() || failure()
with:
name: gcovr-${{ matrix.target.name }}-${{ matrix.target.arch }}
path: |
${{ matrix.target.name }}-${{ matrix.target.arch }}-ctest.log
${{ matrix.target.name }}-${{ matrix.target.arch }}-module-test.log
${{ matrix.target.name }}-${{ matrix.target.arch }}-gcovr.log
${{ matrix.target.name }}-${{ matrix.target.arch }}/*
report:
name: Code coverage
needs: [ unit-test, create-ci-matrix ]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target: ${{ fromJson(needs.create-ci-matrix.outputs.matrix) }}
permissions:
checks: write
pull-requests: write
if: success() || failure()
steps:
- name: Download gcovr artifacts
uses: actions/download-artifact@v4
with:
pattern: "*"
- name: Show gcovr summary
run: |
jq -r '.files[] | "\(.filename) \(.line_covered) \(.line_total)"' gcovr-${{ matrix.target.name }}-${{ matrix.target.arch }}/${{ matrix.target.name }}-${{ matrix.target.arch }}/coverage.summary.json | awk '
{
filename = $1
covered = $2
total = $3
if (filename ~ /^src\/common\//) {
group = "src/common"
} else if (filename ~ /^src\/modules\//) {
match(filename, /^src\/modules\/[^\/]+/)
group = substr(filename, RSTART, RLENGTH)
} else {
group = "other directories"
}
covered_sum[group] += covered
total_sum[group] += total
covered_overall += covered
total_overall += total
if (covered == 0 && total > 0) {
uncovered_files[uncovered_count++] = filename
}
}
END {
printf "\n### Overall coverage\n"
printf "| covered | total | ratio |\n"
printf "| :-: | :-: | :-: |\n"
printf "| %d | %d | %.2f%% |\n", covered_overall, total_overall, 100 * covered_overall / total_overall
printf "\n### Coverage by directory\n"
printf "| directory | covered | total | ratio |\n"
printf "| :- | :-: | :-: | :-: |\n"
for (g in covered_sum) {
printf "| %s | %d | %d | %.2f%% |\n", g, covered_sum[g], total_sum[g], 100 * covered_sum[g] / total_sum[g]
}
printf "\n### Uncovered files\n"
if (uncovered_count > 0) {
printf "| filename |\n"
printf "| :- |\n"
for (i = 0; i < uncovered_count; i++) {
printf "| %s |\n", uncovered_files[i]
}
} else {
printf "No uncovered files found\n"
}
}' > $GITHUB_STEP_SUMMARY