Skip to content

Commit

Permalink
ci: Use gotestfmt to format go test output
Browse files Browse the repository at this point in the history
The output of go test is notoriously hard to read, especially when a lot
of tests are executed and a lot of output is produced, which is the case
in our CI.

This commit uses gotestfmt to format the go test output. It only prints
the output of failed tests to stdout, because that's what we're usually
interested in. In case we need the full test output, that's now uploaded
as an artifact.
  • Loading branch information
adombeck committed Nov 13, 2024
1 parent a194ef4 commit 95a7624
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ jobs:
with:
go-version-file: go.mod

- name: Prepare tests artifacts path
run: |
set -eu
artifacts_dir=$(mktemp -d --tmpdir authd-test-artifacts-XXXXXX)
echo AUTHD_TEST_ARTIFACTS_DIR="${artifacts_dir}" >> $GITHUB_ENV
- name: Install gotestfmt and our wrapper script
uses: canonical/desktop-engineering/gh-actions/go/gotestfmt@gotestfmt

- name: Run tests (with coverage collection)
run: |
set -eu
Expand All @@ -37,22 +47,24 @@ jobs:
rm -fr "${raw_cov_dir}"
mkdir -p "${raw_cov_dir}"
# Print executed commands to ease debugging
set -x
# Overriding the default coverage directory is not an exported flag of go test (yet), so
# we need to override it using the test.gocoverdir flag instead.
#TODO: Update when https://go-review.googlesource.com/c/go/+/456595 is merged.
go test -cover -covermode=set ./... -shuffle=on -args -test.gocoverdir="${raw_cov_dir}"
go test -json -cover -covermode=set ./... -shuffle=on -args -test.gocoverdir="${raw_cov_dir}" 2>&1 | \
gotestfmt --logfile "${AUTHD_TEST_ARTIFACTS_DIR}/gotestfmt.cover.log"
# Convert the raw coverage data into textfmt so we can merge the Rust one into it
go tool covdata textfmt -i="${raw_cov_dir}" -o="/tmp/coverage.out"
# Filter out the testutils package and the pb.go file
grep -v -e "testutils" "/tmp/coverage.out" >"/tmp/coverage.out.filtered"
- name: Run tests (with race detector)
run: |
go test -race ./...
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
- name: Upload test artifacts
if: failure()
uses: actions/upload-artifact@v4
with:
file: /tmp/coverage.out.filtered
name: authd-${{ github.job }}-artifacts-${{ github.run_attempt }}
path: ${{ env.AUTHD_TEST_ARTIFACTS_DIR }}

0 comments on commit 95a7624

Please sign in to comment.