Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse coverage to Cobertura format and upload artifact #796

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 36 additions & 8 deletions .github/workflows/qa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,20 @@ jobs:
echo AUTHD_TEST_ARTIFACTS_PATH="${artifacts_dir}" >> $GITHUB_ENV

echo ASAN_OPTIONS="log_path=${artifacts_dir}/asan.log:print_stats=true" >> $GITHUB_ENV

- name: Install coverage collection dependencies
if: matrix.test == 'coverage'
run: |
set -eu

# Dependendencies for C coverage collection
sudo apt install -y gcovr

# Dependendencies for Go coverage collection
go install github.com/AlekSi/gocov-xml@latest
go install github.com/axw/gocov/gocov@latest
dotnet tool install -g dotnet-reportgenerator-globaltool

- name: Run tests (with coverage collection)
if: matrix.test == 'coverage'
env:
Expand All @@ -216,10 +230,10 @@ jobs:
set -euo pipefail

# The coverage is not written if the output directory does not exist, so we need to create it.
cov_dir="$(pwd)/coverage"
cod_cov_dir="$(pwd)/coverage/codecov"
raw_cov_dir="${cov_dir}/raw"
mkdir -p "${raw_cov_dir}" "${cod_cov_dir}"
cov_dir=${PWD}/coverage
codecov_dir=${cov_dir}/codecov
raw_cov_dir=${cov_dir}/raw
mkdir -p "${raw_cov_dir}" "${codecov_dir}"

# Print executed commands to ease debugging
set -x
Expand All @@ -237,10 +251,17 @@ jobs:
cat "${raw_cov_dir}/rust-cov/rust2go_coverage" >>"${cov_dir}/coverage.out"

# Filter out the testutils package and the pb.go file
grep -v -e "testutils" -e "pb.go" "${cov_dir}/coverage.out" >"${cod_cov_dir}/coverage.out.filtered"
grep -v -e "testutils" -e "pb.go" -e "testsdetection" "${cov_dir}/coverage.out" >"${cov_dir}/coverage.out.filtered"

# Generate the Cobertura report for Go and Rust
gocov convert "${cov_dir}/coverage.out.filtered" | gocov-xml > "${cov_dir}/coverage.xml"
reportgenerator -reports:"${cov_dir}/coverage.xml" -targetdir:"${codecov_dir}" -reporttypes:Cobertura

# Generate the Cobertura report for C
gcovr --cobertura "${codecov_dir}/Cobertura_C.xml" "${raw_cov_dir}"

# Move gcov output to coverage dir
mv "${raw_cov_dir}"/*.gcov "${cod_cov_dir}"
# Store the coverage directory for the next steps
echo COVERAGE_DIR="${codecov_dir}" >> ${GITHUB_ENV}

- name: Run tests (with race detector)
if: matrix.test == 'race'
Expand Down Expand Up @@ -304,9 +325,16 @@ jobs:
if: matrix.test == 'coverage'
uses: codecov/codecov-action@v5
with:
directory: ./coverage/codecov
files: ${{ env.COVERAGE_DIR }}/Cobertura.xml, ${{ env.COVERAGE_DIR }}/Cobertura_C.xml
token: ${{ secrets.CODECOV_TOKEN }}

- name: Upload coverage artifacts
if: matrix.test == 'coverage' && github.ref == 'refs/heads/main'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal but is there a github env to get the default branch for a project?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. This is the only way of figuring out the current branch, AFAIK.

uses: actions/upload-artifact@v4
with:
name: coverage.zip
path: ${{ env.COVERAGE_DIR }}

- name: Upload test artifacts
if: always()
uses: actions/upload-artifact@v4
Expand Down
Loading