Skip to content

Commit dc8d0a8

Browse files
committed
chore: use gotestsum for running tests
Introduced a helper script to manage gotestsum binary installation across CI environments. Replaced make targets with gotestsum to improve test reporting and consistency in Tekton pipelines and GitHub Actions. This allows output to json and stdout at the same time
1 parent 665c586 commit dc8d0a8

4 files changed

Lines changed: 64 additions & 5 deletions

File tree

.tekton/generate-coverage-release.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,18 @@ spec:
8282
value: "$(context.pipelineRun.name)"
8383
- name: TESTRR_RUN_LABEL
8484
value: "tekton-coverage-release"
85+
- name: GH_TOKEN
86+
valueFrom:
87+
secretKeyRef:
88+
name: "nightly-ci-github-hub-token"
89+
key: "hub-token"
8590
script: |
8691
#!/usr/bin/env bash
8792
set -euo pipefail
93+
./hack/install-gotestsum.sh 1.13.0 "$(go env GOPATH)/bin"
8894
test_status=0
89-
make test GO_TEST_FLAGS="-json -coverprofile=coverage.txt -covermode=atomic" \
90-
2>&1 | tee /tmp/testrr-coverage-go.json || test_status=$?
95+
gotestsum --format standard-verbose --jsonfile /tmp/testrr-coverage-go.json -- \
96+
-coverprofile=coverage.txt -covermode=atomic ./pkg/... || test_status=$?
9197
if ! ./hack/upload-testrr.sh /tmp/testrr-coverage-go.json; then
9298
echo "WARNING: testrr upload failed; continuing without failing Tekton"
9399
fi

.tekton/go.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,20 @@ spec:
8080
value: "$(context.pipelineRun.name)"
8181
- name: TESTRR_RUN_LABEL
8282
value: "pac-unit-tests"
83+
- name: GH_TOKEN
84+
valueFrom:
85+
secretKeyRef:
86+
name: "nightly-ci-github-hub-token"
87+
key: "hub-token"
8388
workingDir: $(workspaces.source.path)
8489
script: |
8590
#!/usr/bin/env bash
8691
set -euo pipefail
8792
git config --global --add safe.directory $(workspaces.source.path)
93+
./hack/install-gotestsum.sh 1.13.0 "$(go env GOPATH)/bin"
8894
test_status=0
89-
make test GO_TEST_FLAGS="-json -coverprofile=coverage.txt -covermode=atomic" \
90-
2>&1 | tee /tmp/testrr-unit-go.json || test_status=$?
95+
gotestsum --format standard-verbose --jsonfile /tmp/testrr-unit-go.json -- \
96+
-coverprofile=coverage.txt -covermode=atomic ./pkg/... || test_status=$?
9197
if ! ./hack/upload-testrr.sh /tmp/testrr-unit-go.json; then
9298
echo "WARNING: testrr upload failed; continuing without failing Tekton"
9399
fi

hack/gh-workflow-ci.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,10 @@ run_e2e_tests() {
219219

220220
# shellcheck disable=SC2001
221221
test_pattern="$(echo "${tests[*]}" | sed 's/ /|/g')"
222-
make test-e2e GO_TEST_FLAGS="-json -run \"${test_pattern}\"" 2>&1 | tee "${raw_output}" || test_status=$?
222+
./hack/install-gotestsum.sh 1.13.0 "${HOME}/go/bin"
223+
env GODEBUG=asynctimerchan=1 \
224+
gotestsum --format standard-verbose --jsonfile "${raw_output}" -- \
225+
-race -failfast -timeout 45m -count=1 -tags=e2e -run "${test_pattern}" ./test || test_status=$?
223226
if ! TESTRR_RUN_LABEL="${TESTRR_RUN_LABEL:-gha-e2e-${target}}" ./hack/upload-testrr.sh "${raw_output}"; then
224227
echo "::warning::testrr upload failed; continuing without failing GitHub Actions"
225228
fi

hack/install-gotestsum.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env bash
2+
# description: Download gotestsum binary from GitHub releases.
3+
# this lets us pin the version and avoid slow `go install` in CI.
4+
# Author: Chmouel Boudjnah <chmouel@chmouel.com>
5+
set -eufo pipefail
6+
7+
VERSION=${1:-}
8+
TARGETDIR=${2:-}
9+
10+
[[ -z ${VERSION} || -z ${TARGETDIR} ]] && { echo "Usage: $0 <version> <targetdir>" && exit 1; }
11+
[[ -d ${TARGETDIR} ]] || mkdir -p "${TARGETDIR}"
12+
[[ -x ${TARGETDIR}/gotestsum ]] && {
13+
"${TARGETDIR}/gotestsum" --version 2>/dev/null | grep -q "${VERSION}" && exit 0
14+
rm -f "${TARGETDIR}/gotestsum"
15+
}
16+
17+
detect_os_arch() {
18+
local os arch
19+
20+
case "$(uname -s)" in
21+
Linux*) os=linux ;;
22+
Darwin*) os=darwin ;;
23+
*) echo "Unknown OS" && exit 1 ;;
24+
esac
25+
26+
case "$(uname -m)" in
27+
x86_64) arch=amd64 ;;
28+
arm64 | aarch64) arch=arm64 ;;
29+
*) echo "Unknown arch" && exit 1 ;;
30+
esac
31+
32+
echo "${os}_${arch}"
33+
}
34+
35+
os_arch=$(detect_os_arch)
36+
download_url="https://github.com/gotestyourself/gotestsum/releases/download/v${VERSION}/gotestsum_${VERSION}_${os_arch}.tar.gz"
37+
38+
token="${GH_TOKEN:-${GITHUB_TOKEN:-}}"
39+
curl_args=(-sL --fail-early -f)
40+
[[ -n "${token}" ]] && curl_args+=(-H "Authorization: Bearer ${token}")
41+
42+
echo -n "Downloading gotestsum ${VERSION} (${os_arch}) to ${TARGETDIR}: "
43+
curl "${curl_args[@]}" -o- "${download_url}" | tar -xz -C "${TARGETDIR}" gotestsum
44+
echo "Done"

0 commit comments

Comments
 (0)