diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index d2e5f23cb3c..870a47f6d53 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -169,7 +169,12 @@ jobs: key: unittest-${{ runner.os }}-${{ matrix.runner }}-go-build-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }} - name: Run Unit Tests run: | - make -j4 gotest + make -j4 gotest-with-junit + - uses: actions/upload-artifact@v4 + with: + name: test-results-${{ runner.os }}-${{ matrix.runner }}-${{ matrix.go-version }} + path: internal/tools/testresults/ + retention-days: 4 unittest: if: always() runs-on: ubuntu-latest diff --git a/Makefile b/Makefile index ed0d28aef00..88047fc48bf 100644 --- a/Makefile +++ b/Makefile @@ -56,6 +56,10 @@ gotest-with-cover: @$(MAKE) for-all-target TARGET="test-with-cover" $(GOCMD) tool covdata textfmt -i=./coverage/unit -o ./coverage.txt +.PHONY: gotest-with-junit +gotest-with-junit: + @$(MAKE) for-all-target TARGET="test-with-junit" + .PHONY: gotestifylint-fix gotestifylint-fix: $(MAKE) for-all-target TARGET="testifylint-fix" diff --git a/Makefile.Common b/Makefile.Common index 610c909eb4f..c003cfab3d0 100644 --- a/Makefile.Common +++ b/Makefile.Common @@ -4,6 +4,8 @@ ALL_PKGS := $(sort $(shell go list ./...)) # COVER_PKGS is the list of packages to include in the coverage COVER_PKGS := $(shell go list ./... | tr "\n" ",") +CURR_MOD := $(shell go list -m | tr '/' '-' ) + GOTEST_TIMEOUT?=240s GOTEST_OPT?= -race -timeout $(GOTEST_TIMEOUT) GOCMD?= go @@ -19,6 +21,8 @@ TOOLS_MOD_REGEX := "\s+_\s+\".*\"" TOOLS_PKG_NAMES := $(shell grep -E $(TOOLS_MOD_REGEX) < $(TOOLS_MOD_DIR)/tools.go | tr -d " _\"" | grep -vE '/v[0-9]+$$') TOOLS_BIN_NAMES := $(addprefix $(TOOLS_BIN_DIR)/, $(notdir $(shell echo $(TOOLS_PKG_NAMES)))) CHLOGGEN_CONFIG := .chloggen/config.yaml +# no trailing slash +JUNIT_OUT_DIR ?= $(TOOLS_MOD_DIR)/testresults ADDLICENSE := $(TOOLS_BIN_DIR)/addlicense APIDIFF := $(TOOLS_BIN_DIR)/apidiff @@ -56,6 +60,11 @@ test-with-cover: $(GOTESTSUM) mkdir -p $(PWD)/coverage/unit $(GOTESTSUM) --packages="./..." -- $(GOTEST_OPT) -cover -covermode=atomic -coverpkg $(COVER_PKGS) -args -test.gocoverdir="$(PWD)/coverage/unit" +.PHONY: test-with-junit +test-with-junit: $(GOTESTSUM) + mkdir -p $(JUNIT_OUT_DIR) + $(GOTESTSUM) --packages="./..." --junitfile $(JUNIT_OUT_DIR)/$(CURR_MOD)-junit.xml -- $(GOTEST_OPT) ./... + .PHONY: benchmark benchmark: $(GOTESTSUM) $(GOTESTSUM) --packages="$(ALL_PKGS)" -- -bench=. -run=notests ./... | tee benchmark.txt