Skip to content

Commit ed5e1de

Browse files
denisonbarbosa3v1n0
authored andcommitted
Parse coverage to Cobertura format and upload it as artifact
In order to submit our coverage to TiCS, we need them parsed in Cobertura format. Since we need to parse this for TiCS, let's reuse the assets and upload those Cobertura reports to Codecov as well.
1 parent 4adde50 commit ed5e1de

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

Diff for: .github/workflows/qa.yaml

+36-8
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,20 @@ jobs:
216216
echo AUTHD_TEST_ARTIFACTS_PATH="${artifacts_dir}" >> $GITHUB_ENV
217217
218218
echo ASAN_OPTIONS="log_path=${artifacts_dir}/asan.log:print_stats=true" >> $GITHUB_ENV
219+
220+
- name: Install coverage collection dependencies
221+
if: matrix.test == 'coverage'
222+
run: |
223+
set -eu
224+
225+
# Dependendencies for C coverage collection
226+
sudo apt install -y gcovr
227+
228+
# Dependendencies for Go coverage collection
229+
go install github.com/AlekSi/gocov-xml@latest
230+
go install github.com/axw/gocov/gocov@latest
231+
dotnet tool install -g dotnet-reportgenerator-globaltool
232+
219233
- name: Run tests (with coverage collection)
220234
if: matrix.test == 'coverage'
221235
env:
@@ -224,10 +238,10 @@ jobs:
224238
set -euo pipefail
225239
226240
# The coverage is not written if the output directory does not exist, so we need to create it.
227-
cov_dir="$(pwd)/coverage"
228-
cod_cov_dir="$(pwd)/coverage/codecov"
229-
raw_cov_dir="${cov_dir}/raw"
230-
mkdir -p "${raw_cov_dir}" "${cod_cov_dir}"
241+
cov_dir=${PWD}/coverage
242+
codecov_dir=${cov_dir}/codecov
243+
raw_cov_dir=${cov_dir}/raw
244+
mkdir -p "${raw_cov_dir}" "${codecov_dir}"
231245
232246
# Print executed commands to ease debugging
233247
set -x
@@ -245,10 +259,17 @@ jobs:
245259
cat "${raw_cov_dir}/rust-cov/rust2go_coverage" >>"${cov_dir}/coverage.out"
246260
247261
# Filter out the testutils package and the pb.go file
248-
grep -v -e "testutils" -e "pb.go" "${cov_dir}/coverage.out" >"${cod_cov_dir}/coverage.out.filtered"
262+
grep -v -e "testutils" -e "pb.go" -e "testsdetection" "${cov_dir}/coverage.out" >"${cov_dir}/coverage.out.filtered"
263+
264+
# Generate the Cobertura report for Go and Rust
265+
gocov convert "${cov_dir}/coverage.out.filtered" | gocov-xml > "${cov_dir}/coverage.xml"
266+
reportgenerator -reports:"${cov_dir}/coverage.xml" -targetdir:"${codecov_dir}" -reporttypes:Cobertura
267+
268+
# Generate the Cobertura report for C
269+
gcovr --cobertura "${codecov_dir}/Cobertura_C.xml" "${raw_cov_dir}"
249270
250-
# Move gcov output to coverage dir
251-
mv "${raw_cov_dir}"/*.gcov "${cod_cov_dir}"
271+
# Store the coverage directory for the next steps
272+
echo COVERAGE_DIR="${codecov_dir}" >> ${GITHUB_ENV}
252273
253274
- name: Run tests (with race detector)
254275
if: matrix.test == 'race'
@@ -312,9 +333,16 @@ jobs:
312333
if: matrix.test == 'coverage'
313334
uses: codecov/codecov-action@v5
314335
with:
315-
directory: ./coverage/codecov
336+
files: ${{ env.COVERAGE_DIR }}/Cobertura.xml, ${{ env.COVERAGE_DIR }}/Cobertura_C.xml
316337
token: ${{ secrets.CODECOV_TOKEN }}
317338

339+
- name: Upload coverage artifacts
340+
if: matrix.test == 'coverage' && github.ref == 'refs/heads/main'
341+
uses: actions/upload-artifact@v4
342+
with:
343+
name: coverage.zip
344+
path: ${{ env.COVERAGE_DIR }}
345+
318346
- name: Upload test artifacts
319347
if: always()
320348
uses: actions/upload-artifact@v4

0 commit comments

Comments
 (0)