diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index e52f13b61a326..97672f5e82a14 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -291,14 +291,20 @@ jobs: - name: Run Unit Tests if: startsWith( matrix.go-version, '1.23' ) != true run: make gotest GROUP=${{ matrix.group }} - - name: Run Unit Tests With Coverage - if: startsWith( matrix.go-version, '1.23' ) # only run coverage on one version - run: make gotest-with-cover GROUP=${{ matrix.group }} + - name: Run Unit Tests With JUnit and Coverage + if: startsWith( matrix.go-version, '1.23' ) # only run junit/coverage on one version + run: make gotest-with-junit-and-cover GROUP=${{ matrix.group }} - uses: actions/upload-artifact@v4 if: startsWith( matrix.go-version, '1.23' ) # only upload artifact for one version with: name: coverage-artifacts-${{ matrix.go-version }}-${{ matrix.runner }}-${{ matrix.group }} path: ${{ matrix.group }}-coverage.txt + - uses: actions/upload-artifact@v4 + if: startsWith( matrix.go-version, '1.23' ) # only upload artifact for one version + with: + name: test-results-${{ matrix.go-version }}-${{ matrix.runner }}-${{ matrix.group }} + path: internal/tools/testresults/ + retention-days: 4 unittest: if: ${{ github.actor != 'dependabot[bot]' && always() }} runs-on: ubuntu-24.04 diff --git a/.gitignore b/.gitignore index 3d8526e84e354..ae90d00cdceef 100644 --- a/.gitignore +++ b/.gitignore @@ -35,6 +35,7 @@ __debug_bin* coverage/* *-coverage.txt integration-coverage.html +internal/tools/testresults/* # Wix *.wixobj diff --git a/Makefile b/Makefile index 1ec201d508f16..2149143aeb90d 100644 --- a/Makefile +++ b/Makefile @@ -154,6 +154,14 @@ gotest: gotest-with-cover: @$(MAKE) $(FOR_GROUP_TARGET) TARGET="test-with-cover" $(GOCMD) tool covdata textfmt -i=./coverage/unit -o ./$(GROUP)-coverage.txt + +.PHONY: gotest-with-junit +gotest-with-junit: + @$(MAKE) for-all-target TARGET="test-with-junit" + +.PHONY: gotest-with-junit-and-cover +gotest-with-junit-and-cover: + @$(MAKE) for-all-target TARGET="test-with-junit-and-cover" .PHONY: gobuildtest gobuildtest: diff --git a/Makefile.Common b/Makefile.Common index 57dd75701cb05..13cbf9096b434 100644 --- a/Makefile.Common +++ b/Makefile.Common @@ -30,6 +30,8 @@ GOTESTARCH?=$(GOARCH) DOCKERCMD ?= docker +CURR_MOD := $(shell go list -m | tr '/' '-' ) + # In order to help reduce toil related to managing tooling for the open telemetry collector # this section of the makefile looks at only requiring command definitions to be defined # as part of $(TOOLS_MOD_DIR)/tools.go, following the existing practice. @@ -42,6 +44,9 @@ TOOLS_BIN_DIR := $(SRC_ROOT)/.tools TOOLS_BIN_NAMES := $(addprefix $(TOOLS_BIN_DIR)/, $(notdir $(TOOLS_PKG_NAMES))) CHLOGGEN_CONFIG := .chloggen/config.yaml +# no trailing slash +JUNIT_OUT_DIR ?= $(TOOLS_MOD_DIR)/testresults + .PHONY: install-tools install-tools: $(TOOLS_BIN_NAMES) @@ -107,6 +112,17 @@ do-unit-tests-with-cover: $(GOTESTSUM) $(GOTESTSUM) $(GOTESTSUM_OPT) --packages="./..." -- $(GOTEST_OPT_WITH_COVERAGE) $(GOCMD) tool cover -html=coverage.txt -o coverage.html +.PHONY: test-with-junit +test-with-junit: $(GOTESTSUM) + mkdir -p $(JUNIT_OUT_DIR) + $(GOTESTSUM) $(GOTESTSUM_OPT) --packages="./..." --junitfile $(JUNIT_OUT_DIR)/$(CURR_MOD)-junit.xml -- $(GOTEST_OPT) ./... + +.PHONY: test-with-junit-and-cover +test-with-junit-and-cover: $(GOTESTSUM) + mkdir -p $(JUNIT_OUT_DIR) + $(GOTESTSUM) $(GOTESTSUM_OPT) --packages="./..." --junitfile $(JUNIT_OUT_DIR)/$(CURR_MOD)-junit.xml -- $(GOTEST_OPT_WITH_COVERAGE) ./... + $(GOCMD) tool cover -html=coverage.txt -o coverage.html + .PHONY: buildtest buildtest: ifneq (,$(wildcard ./*.go))