Skip to content

Commit 95e35ee

Browse files
authored
Add support for JUnit test results (#37941)
Mimicking open-telemetry/opentelemetry-collector#11963 This effort is related to #36761. We'll need JUnit test results so issuegenerator(being worked on this PR: open-telemetry/opentelemetry-go-build-tools#672) can generate issues based on failing tests on main. cc @mx-psi Signed-off-by: Arthur Silva Sens <[email protected]>
1 parent 2bdf1a8 commit 95e35ee

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

.github/workflows/build-and-test.yml

+9-3
Original file line numberDiff line numberDiff line change
@@ -291,14 +291,20 @@ jobs:
291291
- name: Run Unit Tests
292292
if: startsWith( matrix.go-version, '1.23' ) != true
293293
run: make gotest GROUP=${{ matrix.group }}
294-
- name: Run Unit Tests With Coverage
295-
if: startsWith( matrix.go-version, '1.23' ) # only run coverage on one version
296-
run: make gotest-with-cover GROUP=${{ matrix.group }}
294+
- name: Run Unit Tests With JUnit and Coverage
295+
if: startsWith( matrix.go-version, '1.23' ) # only run junit/coverage on one version
296+
run: make gotest-with-junit-and-cover GROUP=${{ matrix.group }}
297297
- uses: actions/upload-artifact@v4
298298
if: startsWith( matrix.go-version, '1.23' ) # only upload artifact for one version
299299
with:
300300
name: coverage-artifacts-${{ matrix.go-version }}-${{ matrix.runner }}-${{ matrix.group }}
301301
path: ${{ matrix.group }}-coverage.txt
302+
- uses: actions/upload-artifact@v4
303+
if: startsWith( matrix.go-version, '1.23' ) # only upload artifact for one version
304+
with:
305+
name: test-results-${{ matrix.go-version }}-${{ matrix.runner }}-${{ matrix.group }}
306+
path: internal/tools/testresults/
307+
retention-days: 4
302308
unittest:
303309
if: ${{ github.actor != 'dependabot[bot]' && always() }}
304310
runs-on: ubuntu-24.04

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ __debug_bin*
3535
coverage/*
3636
*-coverage.txt
3737
integration-coverage.html
38+
internal/tools/testresults/*
3839

3940
# Wix
4041
*.wixobj

Makefile

+8
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@ gotest:
154154
gotest-with-cover:
155155
@$(MAKE) $(FOR_GROUP_TARGET) TARGET="test-with-cover"
156156
$(GOCMD) tool covdata textfmt -i=./coverage/unit -o ./$(GROUP)-coverage.txt
157+
158+
.PHONY: gotest-with-junit
159+
gotest-with-junit:
160+
@$(MAKE) for-all-target TARGET="test-with-junit"
161+
162+
.PHONY: gotest-with-junit-and-cover
163+
gotest-with-junit-and-cover:
164+
@$(MAKE) for-all-target TARGET="test-with-junit-and-cover"
157165

158166
.PHONY: gobuildtest
159167
gobuildtest:

Makefile.Common

+16
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ GOTESTARCH?=$(GOARCH)
3030

3131
DOCKERCMD ?= docker
3232

33+
CURR_MOD := $(shell go list -m | tr '/' '-' )
34+
3335
# In order to help reduce toil related to managing tooling for the open telemetry collector
3436
# this section of the makefile looks at only requiring command definitions to be defined
3537
# as part of $(TOOLS_MOD_DIR)/tools.go, following the existing practice.
@@ -42,6 +44,9 @@ TOOLS_BIN_DIR := $(SRC_ROOT)/.tools
4244
TOOLS_BIN_NAMES := $(addprefix $(TOOLS_BIN_DIR)/, $(notdir $(TOOLS_PKG_NAMES)))
4345
CHLOGGEN_CONFIG := .chloggen/config.yaml
4446

47+
# no trailing slash
48+
JUNIT_OUT_DIR ?= $(TOOLS_MOD_DIR)/testresults
49+
4550
.PHONY: install-tools
4651
install-tools: $(TOOLS_BIN_NAMES)
4752

@@ -107,6 +112,17 @@ do-unit-tests-with-cover: $(GOTESTSUM)
107112
$(GOTESTSUM) $(GOTESTSUM_OPT) --packages="./..." -- $(GOTEST_OPT_WITH_COVERAGE)
108113
$(GOCMD) tool cover -html=coverage.txt -o coverage.html
109114

115+
.PHONY: test-with-junit
116+
test-with-junit: $(GOTESTSUM)
117+
mkdir -p $(JUNIT_OUT_DIR)
118+
$(GOTESTSUM) $(GOTESTSUM_OPT) --packages="./..." --junitfile $(JUNIT_OUT_DIR)/$(CURR_MOD)-junit.xml -- $(GOTEST_OPT) ./...
119+
120+
.PHONY: test-with-junit-and-cover
121+
test-with-junit-and-cover: $(GOTESTSUM)
122+
mkdir -p $(JUNIT_OUT_DIR)
123+
$(GOTESTSUM) $(GOTESTSUM_OPT) --packages="./..." --junitfile $(JUNIT_OUT_DIR)/$(CURR_MOD)-junit.xml -- $(GOTEST_OPT_WITH_COVERAGE) ./...
124+
$(GOCMD) tool cover -html=coverage.txt -o coverage.html
125+
110126
.PHONY: buildtest
111127
buildtest:
112128
ifneq (,$(wildcard ./*.go))

0 commit comments

Comments
 (0)