Skip to content

Commit

Permalink
collect and upload junits
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitpatel96 committed Jan 7, 2025
1 parent 52aea84 commit b21363a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/build-and-test-arm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
id: setup-go
with:
go-version: "~1.22.5"
cache: false
Expand All @@ -68,7 +69,12 @@ jobs:
if: steps.go-cache.outputs.cache-hit != 'true'
run: make install-tools
- name: Run Unit Tests
run: make -j2 gotest GROUP=${{ matrix.group }}
run: make -j2 gotest-with-junit GROUP=${{ matrix.group }}
- uses: actions/upload-artifact@v4
with:
name: test-results_${{ matrix.group }}_${{ runner.os }}_${{ runner.arch }}_${{ steps.setup-go.outputs.go-version }}
path: internal/tools/testresults/
retention-days: 4
arm-unittest:
if: ${{ github.actor != 'dependabot[bot]' && (contains(github.event.pull_request.labels.*.name, 'Run ARM') || github.event_name == 'push' || github.event_name == 'merge_group') }}
runs-on: ubuntu-24.04
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/build-and-test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ jobs:
- name: install IIS
run: Install-WindowsFeature -name Web-Server -IncludeManagementTools
- uses: actions/setup-go@v5
id: setup-go
with:
go-version: "1.22.8"
cache: false
Expand All @@ -78,7 +79,12 @@ jobs:
# specifically to Windows, see https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/34691
run: make "$(${PWD} -replace '\\', '/')/.tools/gotestsum"
- name: Run Unit tests
run: make -j2 gotest GROUP=${{ matrix.group }}
run: make -j2 gotest-with-junit GROUP=${{ matrix.group }}
- uses: actions/upload-artifact@v4
with:
name: test-results_${{ matrix.group }}_${{ runner.os }}_${{ runner.arch }}_${{ steps.setup-go.outputs.go-version }}
path: internal/tools/testresults/
retention-days: 4
windows-unittest:
if: ${{ github.actor != 'dependabot[bot]' && (contains(github.event.pull_request.labels.*.name, 'Run Windows') || github.event_name == 'push' || github.event_name == 'merge_group') }}
runs-on: windows-latest
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ jobs:
fail-fast: false
matrix:
go-version: ["1.23.0", "1.22.8"] # 1.20 is interpreted as 1.2 without quotes
runner: [ubuntu-24.04]
os: [ubuntu-24.04]
group:
- receiver-0
- receiver-1
Expand All @@ -271,6 +271,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
id: setup-go
with:
go-version: ${{ matrix.go-version }}
cache: false
Expand All @@ -297,7 +298,12 @@ jobs:
key: go-test-build-${{ runner.os }}-${{ matrix.go-version }}-${{ matrix.runner }}-${{ hashFiles('**/go.sum') }}
- name: Run Unit Tests
if: startsWith( matrix.go-version, '1.22' ) != true
run: make gotest GROUP=${{ matrix.group }}
run: make gotest-with-junit GROUP=${{ matrix.group }}
- uses: actions/upload-artifact@v4
with:
name: test-results_${{ matrix.group }}_${{ runner.os }}_${{ runner.arch }}_${{ steps.setup-go.outputs.go-version }}
path: internal/tools/testresults/
retention-days: 4
- name: Run Unit Tests With Coverage
if: startsWith( matrix.go-version, '1.22' ) # only run coverage on one version
run: make gotest-with-cover GROUP=${{ matrix.group }}
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ 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_GROUP_TARGET) TARGET="test-with-junit"

.PHONY: gobuildtest
gobuildtest:
$(MAKE) $(FOR_GROUP_TARGET) TARGET="buildtest"
Expand Down
11 changes: 11 additions & 0 deletions Makefile.Common
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ $(TOOLS_BIN_DIR):
$(TOOLS_BIN_NAMES): $(TOOLS_BIN_DIR) $(TOOLS_MOD_DIR)/go.mod
cd $(TOOLS_MOD_DIR) && GOOS="" GOARCH="" $(GOCMD) build -o $@ -trimpath $(filter %/$(notdir $@),$(TOOLS_PKG_NAMES))

JUNIT_OUT_DIR ?= $(TOOLS_MOD_DIR)/testresults

ADDLICENSE := $(TOOLS_BIN_DIR)/addlicense
MDLINKCHECK := $(TOOLS_BIN_DIR)/markdown-link-check
MISSPELL := $(TOOLS_BIN_DIR)/misspell -error
Expand Down Expand Up @@ -97,6 +99,9 @@ ALL_SRC_AND_SHELL := find . -type f \( -iname '*.go' -o -iname "*.sh" \) ! -path

# All source code and documents. Used in spell check.
ALL_SRC_AND_DOC_CMD := find $(ALL_PKG_DIRS) -name "*.md" -o -name "*.go" -o -name "*.yaml" -not -path '*/third_party/*' -type f | sort

CURR_MOD := $(shell go list -m | tr '/' '-' )

ifeq ($(UNIX_SHELL_ON_WINDOWS),true)
# Windows has a low limit, 8192 chars, to create a process. Workaround it by breaking it in smaller commands.
MISSPELL_CMD := $(ALL_SRC_AND_DOC_CMD) | xargs -n 20 $(MISSPELL)
Expand Down Expand Up @@ -138,6 +143,12 @@ test-with-cover: $(GOTESTSUM)
mkdir -p $(PWD)/coverage/unit
$(GOTESTSUM) $(GOTESTSUM_OPT) --packages="./..." -- $(GOTEST_OPT) -cover -covermode=atomic -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: do-unit-tests-with-cover
do-unit-tests-with-cover: $(GOTESTSUM)
@echo "running $(GOCMD) unit test ./... + coverage in `pwd`"
Expand Down

0 comments on commit b21363a

Please sign in to comment.