-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: Collect coverage data during tests
MicroOVN snap built in the CI pipeline now supports coverage instrumentation in its client and daemon binaries. Test jobs will use this build to collect coverage data that gets uploaded as an artifact from each job. After all tests are executed, a new job will collect and merge coverage data from all tests and produce coverage report in Cobertura XML format. Signed-off-by: Martin Kalcok <[email protected]>
- Loading branch information
Showing
1 changed file
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,10 @@ jobs: | |
--classic | ||
- name: Build snap | ||
run: make $MICROOVN_SNAP | ||
run: | | ||
# Build snap with coverage support | ||
sed -i 's/MICROOVN_COVERAGE=.*/MICROOVN_COVERAGE="yes"/g' microovn/.build_control | ||
make $MICROOVN_SNAP | ||
- name: Upload artifacts | ||
if: always() | ||
|
@@ -132,4 +135,60 @@ jobs: | |
snap list | ||
- name: Run system tests | ||
run: .bats/bats-core/bin/bats tests/${{ matrix.test-file }} | ||
run: MICROOVN_COVERAGE_ENABLED=yes make tests/${{ matrix.test-file }} | ||
|
||
- name: Upload test coverage | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: ${{ matrix.test-file }}_coverage | ||
path: ${{ github.workspace }}/.coverage | ||
include-hidden-files: true | ||
retention-days: 1 | ||
|
||
generate-coverage: | ||
name: Generate coverage profile | ||
needs: | ||
- metadata | ||
- system-tests | ||
# 'ubuntu-latest' currently resolves to '22.04' [0] and since we require "Go >=1.20" | ||
# for coverage tools, we need to use explicit 'ubuntu-24.04' image name. | ||
# [0] https://github.com/actions/runner-images/issues/10636 | ||
runs-on: ubuntu-24.04 | ||
env: | ||
COVERAGE_DIR: ${{ github.workspace }}/.coverage | ||
COVERAGE_MERGED: ${{ github.workspace }}/.coverage/_merged | ||
COVERAGE_MERGED_PROFILE: ${{ github.workspace }}/.coverage/_merged/profile.out | ||
steps: | ||
- name: Install dependencies | ||
run: | | ||
sudo apt install -yqq golang | ||
go install github.com/boumenot/[email protected] | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Download test coverage data | ||
uses: actions/download-artifact@v4 | ||
with: | ||
path: ${{ env.COVERAGE_DIR }} | ||
pattern: "*_coverage" | ||
|
||
- name: Merge test coverage data | ||
run: | | ||
mkdir -p "$COVERAGE_MERGED" | ||
coverage_inputs=$(find "$COVERAGE_DIR" -type d -name coverage | tr '\n' ',' | sed 's/,$//g') | ||
go tool covdata merge -i="$coverage_inputs" -o="$COVERAGE_MERGED" | ||
go tool covdata textfmt -i="$COVERAGE_MERGED" -o="$COVERAGE_MERGED_PROFILE" | ||
- name: Generate cobertura.xml | ||
run: | | ||
cd microovn/ | ||
$HOME/go/bin/gocover-cobertura < "$COVERAGE_MERGED_PROFILE" > "$COVERAGE_DIR/cobertura.xml" | ||
- name: Upload cobertura.xml | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: cobertura.xml | ||
path: ${{ env.COVERAGE_DIR }}/cobertura.xml | ||
include-hidden-files: true | ||
|