Skip to content

Commit

Permalink
gha: collate and calculate coverage for all test runs
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksa Sarai <[email protected]>
  • Loading branch information
cyphar committed Jul 4, 2024
1 parent 2dd1217 commit f7b4ae9
Showing 1 changed file with 73 additions and 5 deletions.
78 changes: 73 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,29 @@ on:
- cron: "30 10 * * 0"

jobs:
test:
test-windows:
strategy:
matrix:
go-version:
- "1.21"
- "1.22"
- "^1"
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: unit tests
run: go test -v -cover ./...

test-unix:
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
go-version:
- "1.21"
- "1.22"
Expand All @@ -33,9 +48,62 @@ jobs:
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: mkdir gocoverdir
run: |
GOCOVERDIR="$(mktemp -d gocoverdir.XXXXXXXX)"
echo "GOCOVERDIR=$GOCOVERDIR" >>"$GITHUB_ENV"
- name: unit tests
run: go test -v -cover ./...
# TODO: Merge the code coverage stats from both runs...
run: |
GOCOVERDIR="$GOCOVERDIR/nonroot"
mkdir -p "$GOCOVERDIR"
go test -v -cover -test.gocoverdir="$GOCOVERDIR" ./...
- name: unit tests (root)
if: ${{ ! startsWith(matrix.os, 'windows-') }}
run: sudo go test -v -cover ./...
run: |
GOCOVERDIR="$GOCOVERDIR/root"
mkdir -p "$GOCOVERDIR"
sudo go test -v -cover -test.gocoverdir="$GOCOVERDIR" ./...
- name: upload coverage
uses: actions/upload-artifact@v4
with:
name: coverage-${{ runner.os }}-${{ github.job }}-${{ strategy.job-index }}
path: ${{ env.GOCOVERDIR }}

coverage:
runs-on: ubuntu-latest
needs:
- test-windows
- test-unix
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: "^1"
- name: download all coverage
uses: actions/download-artifact@v4
with:
path: coverage
- name: generate coverage list
run: |
GOCOVERDIRS="$(printf '%s,' gocoverdir.*/* | sed 's|,$||')"
echo "GOCOVERDIRS=$GOCOVERDIRS" >>"$GITHUB_ENV"
FULLCOVERAGE_FILE="$(mktemp fullcoverage.XXXXXXXX)"
echo "FULLCOVERAGE_FILE=$FULLCOVERAGE_FILE" >>"$GITHUB_ENV"
- name: compute coverage
run: go tool covdata percent -i "$GOCOVERDIRS"
- name: compute func coverage
run: go tool covdata func -i "$GOCOVERDIRS"
- name: merge coverage
run: |
go tool covdata textfmt -i "$GOCOVERDIRS" -o "$FULLCOVERAGE_FILE"
go tool cover -html="$FULLCOVERAGE_FILE" -o "$FULLCOVERAGE_FILE.html"
- name: upload merged coverage
uses: actions/upload-artifact@v4
with:
name: fullcoverage-${{ github.job }}
path: ${{ env.FULLCOVERAGE_FILE }}
- name: upload coverage html
uses: actions/upload-artifact@v4
with:
name: fullcoverage-${{ github.job }}.html
path: ${{ env.FULLCOVERAGE_FILE }}.html

0 comments on commit f7b4ae9

Please sign in to comment.