Skip to content

Commit

Permalink
ci: Use gotestfmt to format go test output (#220)
Browse files Browse the repository at this point in the history
UDENG-5208
  • Loading branch information
adombeck authored Nov 18, 2024
2 parents bd71c2b + ca35d7c commit 28f390f
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@main

- 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 28f390f

Please sign in to comment.