ci: hide `go test` output to the file on CI

Let's hide stdout of go tests to the files.
In case of failed test - it should be included in junit report anyway and shown in Jenkins.

Closes #3543
This commit is contained in:
Anton Iakimov 2023-08-31 13:43:23 +02:00
parent 5d1c766382
commit 7a9845c6e2
No known key found for this signature in database
GPG Key ID: DEA1FE58DD8BF7FA
4 changed files with 45 additions and 12 deletions

3
.gitignore vendored
View File

@ -82,3 +82,6 @@ package-lock.json
# junit reports for Jenkins integration # junit reports for Jenkins integration
report.xml report.xml
# go test logs
test.log

View File

@ -35,7 +35,6 @@ GIT_COMMIT = $(shell git rev-parse --short HEAD)
AUTHOR ?= $(shell git config user.email || echo $$USER) AUTHOR ?= $(shell git config user.email || echo $$USER)
ENABLE_METRICS ?= true ENABLE_METRICS ?= true
BUILD_TAGS ?=
BUILD_FLAGS ?= $(shell echo "-ldflags='\ BUILD_FLAGS ?= $(shell echo "-ldflags='\
-X github.com/status-im/status-go/params.Version=$(RELEASE_TAG:v%=%) \ -X github.com/status-im/status-go/params.Version=$(RELEASE_TAG:v%=%) \
-X github.com/status-im/status-go/params.GitCommit=$(GIT_COMMIT) \ -X github.com/status-im/status-go/params.GitCommit=$(GIT_COMMIT) \
@ -48,7 +47,6 @@ BUILD_FLAGS_MOBILE ?= $(shell echo "-ldflags='\
-X github.com/status-im/status-go/params.IpfsGatewayURL=$(IPFS_GATEWAY_URL)'") -X github.com/status-im/status-go/params.IpfsGatewayURL=$(IPFS_GATEWAY_URL)'")
networkid ?= StatusChain networkid ?= StatusChain
gotest_extraflags =
DOCKER_IMAGE_NAME ?= statusteam/status-go DOCKER_IMAGE_NAME ?= statusteam/status-go
BOOTNODE_IMAGE_NAME ?= statusteam/bootnode BOOTNODE_IMAGE_NAME ?= statusteam/bootnode
@ -311,28 +309,23 @@ docker-test: ##@tests Run tests in a docker container with golang.
test: test-unit ##@tests Run basic, short tests during development test: test-unit ##@tests Run basic, short tests during development
test-unit: SHELL := /bin/bash -o pipefail test-unit: export BUILD_TAGS ?=
test-unit: UNIT_TEST_PACKAGES = $(shell go list ./... | \ test-unit: export UNIT_TEST_PACKAGES ?= $(shell go list ./... | \
grep -v /vendor | \ grep -v /vendor | \
grep -v /t/e2e | \ grep -v /t/e2e | \
grep -v /t/benchmarks | \ grep -v /t/benchmarks | \
grep -v /transactions/fake ) grep -v /transactions/fake )
test-unit: ##@tests Run unit and integration tests test-unit: ##@tests Run unit and integration tests
for package in $(UNIT_TEST_PACKAGES); do \ ./_assets/scripts/run_unit_tests.sh
set -e; \
package_dir=$$(go list -f {{.Dir}} $${package}); \
go test -tags '$(BUILD_TAGS)' -timeout 30m -v -failfast $${package} $(gotest_extraflags) | \
go-junit-report -iocopy -out $${package_dir}/report.xml; \
done
test-unit-race: gotest_extraflags=-race test-unit-race: export GOTEST_EXTRAFLAGS=-race
test-unit-race: test-unit ##@tests Run unit and integration tests with -race flag test-unit-race: test-unit ##@tests Run unit and integration tests with -race flag
test-e2e: ##@tests Run e2e tests test-e2e: ##@tests Run e2e tests
# order: reliability then alphabetical # order: reliability then alphabetical
# TODO(tiabc): make a single command out of them adding `-p 1` flag. # TODO(tiabc): make a single command out of them adding `-p 1` flag.
test-e2e-race: gotest_extraflags=-race test-e2e-race: export GOTEST_EXTRAFLAGS=-race
test-e2e-race: test-e2e ##@tests Run e2e tests with -race flag test-e2e-race: test-e2e ##@tests Run e2e tests with -race flag
canary-test: node-canary canary-test: node-canary

12
_assets/scripts/colors.sh Normal file
View File

@ -0,0 +1,12 @@
#!/usr/bin/env bash
# Colors
export YLW='\033[1;33m'
export RED='\033[0;31m'
export GRN='\033[0;32m'
export BLU='\033[0;34m'
export BLD='\033[1m'
export RST='\033[0m'
# Clear line
export CLR='\033[2K'

View File

@ -0,0 +1,25 @@
#!/usr/bin/env bash
set -o pipefail
GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)
source "${GIT_ROOT}/_assets/scripts/colors.sh"
for package in ${UNIT_TEST_PACKAGES}; do
echo -e "${GRN}Testing:${RST} ${package}"
package_dir=$(go list -f "{{.Dir}}" "${package}")
output_file=${package_dir}/test.log
go test -tags "${BUILD_TAGS}" -timeout 30m -v -failfast "${package}" ${GOTEST_EXTRAFLAGS} | \
if [ "${CI}" = "true" ]; then cat > "${output_file}"; else tee "${output_file}"; fi
go_test_exit=$?
if [ "${CI}" = "true" ]; then
go-junit-report -in "${output_file}" -out "${package_dir}"/report.xml
fi
if [ ${go_test_exit} -ne 0 ]; then
echo -e "${YLW}Failed, see the log:${RST} ${BLD}${output_file}${RST}"
exit "${go_test_exit}"
fi
done