Skip to content

Commit 84fe00d

Browse files
authored
[chore] Create gotest-with-junit Makefile target (#11963)
Creates a target to output junit files from testing. This PR also starts to use it in CI - we don't consume the Junits yet but it would be easy to add on. This will be useful for a number of CI/Devx initiatives in the future. My company, Datadog, plans to use this information to track the build stability of our code in contrib, as well as the stability of code we depend on here in collector.
1 parent a573bc9 commit 84fe00d

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,12 @@ jobs:
169169
key: unittest-${{ runner.os }}-${{ matrix.runner }}-go-build-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
170170
- name: Run Unit Tests
171171
run: |
172-
make -j4 gotest
172+
make -j4 gotest-with-junit
173+
- uses: actions/upload-artifact@v4
174+
with:
175+
name: test-results-${{ runner.os }}-${{ matrix.runner }}-${{ matrix.go-version }}
176+
path: internal/tools/testresults/
177+
retention-days: 4
173178
unittest:
174179
if: always()
175180
runs-on: ubuntu-latest

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ gotest-with-cover:
5656
@$(MAKE) for-all-target TARGET="test-with-cover"
5757
$(GOCMD) tool covdata textfmt -i=./coverage/unit -o ./coverage.txt
5858

59+
.PHONY: gotest-with-junit
60+
gotest-with-junit:
61+
@$(MAKE) for-all-target TARGET="test-with-junit"
62+
5963
.PHONY: gotestifylint-fix
6064
gotestifylint-fix:
6165
$(MAKE) for-all-target TARGET="testifylint-fix"

Makefile.Common

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ ALL_PKGS := $(sort $(shell go list ./...))
44
# COVER_PKGS is the list of packages to include in the coverage
55
COVER_PKGS := $(shell go list ./... | tr "\n" ",")
66

7+
CURR_MOD := $(shell go list -m | tr '/' '-' )
8+
79
GOTEST_TIMEOUT?=240s
810
GOTEST_OPT?= -race -timeout $(GOTEST_TIMEOUT)
911
GOCMD?= go
@@ -19,6 +21,8 @@ TOOLS_MOD_REGEX := "\s+_\s+\".*\""
1921
TOOLS_PKG_NAMES := $(shell grep -E $(TOOLS_MOD_REGEX) < $(TOOLS_MOD_DIR)/tools.go | tr -d " _\"" | grep -vE '/v[0-9]+$$')
2022
TOOLS_BIN_NAMES := $(addprefix $(TOOLS_BIN_DIR)/, $(notdir $(shell echo $(TOOLS_PKG_NAMES))))
2123
CHLOGGEN_CONFIG := .chloggen/config.yaml
24+
# no trailing slash
25+
JUNIT_OUT_DIR ?= $(TOOLS_MOD_DIR)/testresults
2226

2327
ADDLICENSE := $(TOOLS_BIN_DIR)/addlicense
2428
APIDIFF := $(TOOLS_BIN_DIR)/apidiff
@@ -56,6 +60,11 @@ test-with-cover: $(GOTESTSUM)
5660
mkdir -p $(PWD)/coverage/unit
5761
$(GOTESTSUM) --packages="./..." -- $(GOTEST_OPT) -cover -covermode=atomic -coverpkg $(COVER_PKGS) -args -test.gocoverdir="$(PWD)/coverage/unit"
5862

63+
.PHONY: test-with-junit
64+
test-with-junit: $(GOTESTSUM)
65+
mkdir -p $(JUNIT_OUT_DIR)
66+
$(GOTESTSUM) --packages="./..." --junitfile $(JUNIT_OUT_DIR)/$(CURR_MOD)-junit.xml -- $(GOTEST_OPT) ./...
67+
5968
.PHONY: benchmark
6069
benchmark: $(GOTESTSUM)
6170
$(GOTESTSUM) --packages="$(ALL_PKGS)" -- -bench=. -run=notests ./... | tee benchmark.txt

0 commit comments

Comments
 (0)