Skip to content

Commit 2339b2c

Browse files
authored
[chore] Avoid go list ./... on GL compile step (#6878)
* [chore] Avoid `go list ./...` on GL compile step * Remove extra white-space * Better formatting * Remove unmatched `(` * Add missing space * Specify COVER_TESTING=true on build-and-test * Specify COVER_TESTING=true on reusable-unit-test * Remove identation from conditionals * Add COVER_TESTING=true to integration-test workflow * Add COVER_TESTING=true to integration-test-discovery-k8s
1 parent caca98b commit 2339b2c

File tree

5 files changed

+28
-12
lines changed

5 files changed

+28
-12
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ jobs:
112112
- uses: ./.github/actions/setup-environment
113113

114114
- name: Run Unit Tests With Coverage
115-
run: make gotest-with-codecov
115+
run: COVER_TESTING=true make gotest-with-codecov
116116

117117
- name: Upload coverage report
118118
uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # 5.5.1

.github/workflows/integration-test.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ jobs:
147147
PROFILE: [ "integration", "smartagent" ]
148148
fail-fast: false
149149
env:
150+
COVER_TESTING: true
150151
TEST_OUTPUT: ${{ github.job }}-${{ matrix.PROFILE }}-${{ matrix.ARCH }}.out
151152
steps:
152153
# Multiarch images require more disk space
@@ -232,6 +233,7 @@ jobs:
232233
PROFILE: [ "integration", "smartagent" ]
233234
fail-fast: false
234235
env:
236+
COVER_TESTING: true
235237
TEST_OUTPUT: ${{ github.job }}-${{ matrix.PROFILE }}-${{ matrix.RUNNER }}.out
236238
steps:
237239
# Multiarch images require more disk space
@@ -336,6 +338,8 @@ jobs:
336338
strategy:
337339
matrix: ${{ fromJSON(needs.integration-test-discovery-matrix.outputs.matrix) }}
338340
fail-fast: false
341+
env:
342+
COVER_TESTING: true
339343
steps:
340344
- name: Free up disk space for next step
341345
uses: jlumbroso/[email protected]
@@ -442,6 +446,7 @@ jobs:
442446
KUBECONFIG=$HOME/.kube/config SKIP_TEARDOWN=true make integration-test-${{ matrix.SERVICE }}-discovery-k8s-with-cover
443447
env:
444448
CONTAINER_COVER_DEST: '/etc/otel/collector/coverage'
449+
COVER_TESTING: true
445450
- name: Print logs
446451
if: failure()
447452
run: |

.github/workflows/reusable-unit-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
trap "go-junit-report -set-exit-code < unit-test-results-${{ inputs.OS }}/go-unit-tests.out > unit-test-results-${{ inputs.OS }}/junit/results.xml" EXIT
3838
3939
if ${{ inputs.COVERAGE }}; then
40-
make gotest-cover-without-race | tee unit-test-results-${{ inputs.OS }}/go-unit-tests.out
40+
COVER_TESTING=true make gotest-cover-without-race | tee unit-test-results-${{ inputs.OS }}/go-unit-tests.out
4141
else
4242
make test-all | tee unit-test-results/go-unit-tests.out
4343
fi

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ SKIP_COMPILE=false
4040
ARCH?=amd64
4141
BUNDLE_SUPPORTED_ARCHS := amd64 arm64
4242
SKIP_BUNDLE=false
43-
# Used for building the collector to collect coverage information
44-
COVER_TESTING=false
4543

4644
# For integration testing against local changes you can run
4745
# SPLUNK_OTEL_COLLECTOR_IMAGE='otelcol:latest' make -e docker-otelcol integration-test
@@ -201,6 +199,9 @@ integration-test-istio-discovery-k8s:
201199
integration-test-istio-discovery-k8s-with-cover:
202200
@make integration-test-cover-target TARGET='discovery_integration_istio_k8s'
203201

202+
ifeq ($(COVER_TESTING),true)
203+
# These targets are expensive to build, so only build if explicitly requested
204+
204205
.PHONY: gotest-with-codecov
205206
gotest-with-codecov:
206207
@$(MAKE) for-all-target TARGET="test-with-codecov"
@@ -211,6 +212,8 @@ gotest-cover-without-race:
211212
@$(MAKE) for-all-target TARGET="test-cover-without-race"
212213
$(GOCMD) tool covdata textfmt -i=./coverage -o ./coverage.txt
213214

215+
endif
216+
214217
.PHONY: tidy-all
215218
tidy-all:
216219
$(MAKE) for-all-target TARGET="tidy"

Makefile.Common

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Explicitly define the shell we will use for commands.
22
SHELL?=/bin/bash
33

4+
# Used for building the collector to collect coverage information
5+
COVER_TESTING?=false
6+
47
# Add support to use Makefile on Windows
58
SHELL_CASE_EXP = case "$$(uname -s)" in CYGWIN*|MINGW*|MSYS*) echo "true";; esac;
69
UNIX_SHELL_ON_WINDOWS := $(shell $(SHELL_CASE_EXP))
@@ -45,14 +48,6 @@ BUILD_TYPE?=release
4548
# COVER_PKGS is the list of packages to include in the test coverage
4649
EXCLUDE_MODS=-not -path "./examples/*" -not -path "./packaging/technical-addon/*"
4750
FIND_MOD_ARGS=-type f -name "go.mod"
48-
COVER_PKGS := $(shell find . $(EXCLUDE_MODS) $(FIND_MOD_ARGS) -execdir $(GOCMD) list ./... \; | tr "\n" "," )
49-
50-
COVER_DIR?=coverage
51-
COVER_DIR_ABS?=$(SRC_ROOT)/$(COVER_DIR)
52-
TEST_COVER_DIR?=$(SRC_ROOT)/tests/$(COVER_DIR)
53-
COVER_OPTS?=-cover -covermode=atomic -coverpkg $(COVER_PKGS)
54-
COVER_TESTING_OPTS?=$(COVER_OPTS) -args -test.gocoverdir="$(COVER_DIR_ABS)"
55-
COVER_TESTING_INTEGRATION_OPTS?=$(COVER_OPTS) -args -test.gocoverdir="$(TEST_COVER_DIR)"
5651

5752
ALL_PKG_DIRS := $(shell $(GOCMD) list -f '{{ .Dir }}' ./... | $(NORMALIZE_DIRS))
5853

@@ -89,6 +84,17 @@ common: checklicense lint misspell
8984
test:
9085
$(GOTEST) $(GOTEST_OPT) $(ALL_PKG_DIRS)
9186

87+
ifeq ($(COVER_TESTING),true)
88+
# These variables and targets are expensive to build, so only build if explicitly requested
89+
90+
COVER_PKGS := $(shell find . $(EXCLUDE_MODS) $(FIND_MOD_ARGS) -execdir $(GOCMD) list ./... \; | tr "\n" "," )
91+
COVER_DIR?=coverage
92+
COVER_DIR_ABS?=$(SRC_ROOT)/$(COVER_DIR)
93+
TEST_COVER_DIR?=$(SRC_ROOT)/tests/$(COVER_DIR)
94+
COVER_OPTS?=-cover -covermode=atomic -coverpkg $(COVER_PKGS)
95+
COVER_TESTING_OPTS?=$(COVER_OPTS) -args -test.gocoverdir="$(COVER_DIR_ABS)"
96+
COVER_TESTING_INTEGRATION_OPTS?=$(COVER_OPTS) -args -test.gocoverdir="$(TEST_COVER_DIR)"
97+
9298
.PHONY: test-with-codecov
9399
test-with-codecov:
94100
mkdir -p $(COVER_DIR)
@@ -102,6 +108,8 @@ test-cover-without-race:
102108
mkdir -p $(COVER_DIR_ABS)
103109
$(GOTEST) $(GOTEST_OPT_WITHOUT_RACE) ./... $(COVER_TESTING_OPTS)
104110

111+
endif
112+
105113
.PHONY: addlicense
106114
addlicense:
107115
@ADDLICENCESEOUT=`$(ADDLICENCESE) -y "" -c 'Splunk, Inc.' $(ALL_SRC) 2>&1`; \

0 commit comments

Comments
 (0)