Skip to content

Commit

Permalink
ci: Collect coverage data during tests
Browse files Browse the repository at this point in the history
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
mkalcok committed Oct 1, 2024
1 parent 7b13d0a commit 9c47bdc
Showing 1 changed file with 61 additions and 2 deletions.
63 changes: 61 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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

0 comments on commit 9c47bdc

Please sign in to comment.