Skip to content

Commit fae2442

Browse files
authored
Fix XDG_DATA_HOME build issue (#264)
This mirrors the same fix made previously in operator-controller: #790 Signed-off-by: Tayler Geiger <[email protected]>
1 parent 364f0a4 commit fae2442

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Makefile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ export IMAGE_TAG
1010

1111
IMAGE := $(IMAGE_REPO):$(IMAGE_TAG)
1212

13-
# setup-envtest on *nix uses XDG_DATA_HOME, falling back to HOME, as the default storage directory. Some CI setups
14-
# don't have XDG_DATA_HOME set; in those cases, we set it here so setup-envtest functions correctly. This shouldn't
15-
# affect developers.
16-
export XDG_DATA_HOME ?= /tmp/.local/share
13+
# By default setup-envtest will write to $XDG_DATA_HOME, or $HOME/.local/share if that is not defined.
14+
# If $HOME is not set, we need to specify a binary directory to prevent an error in setup-envtest.
15+
# Useful for some CI/CD environments that set neither $XDG_DATA_HOME nor $HOME.
16+
SETUP_ENVTEST_BIN_DIR_OVERRIDE=
17+
ifeq ($(shell [[ $$HOME == "" || $$HOME == "/" ]] && [[ $$XDG_DATA_HOME == "" ]] && echo true ), true)
18+
SETUP_ENVTEST_BIN_DIR_OVERRIDE += --bin-dir /tmp/envtest-binaries
19+
endif
1720

1821
# bingo manages consistent tooling versions for things like kind, kustomize, etc.
1922
include .bingo/Variables.mk
@@ -70,7 +73,7 @@ vet: ## Run go vet against code.
7073

7174
.PHONY: test-unit
7275
test-unit: generate fmt vet $(SETUP_ENVTEST) ## Run tests.
73-
eval $$($(SETUP_ENVTEST) use -p env $(ENVTEST_SERVER_VERSION)) && go test $(shell go list ./... | grep -v /test/e2e) -coverprofile cover.out
76+
eval $$($(SETUP_ENVTEST) use -p env $(ENVTEST_SERVER_VERSION) $(SETUP_ENVTEST_BIN_DIR_OVERRIDE)) && go test $(shell go list ./... | grep -v /test/e2e) -coverprofile cover.out
7477

7578
FOCUS := $(if $(TEST),-v -focus "$(TEST)")
7679
ifeq ($(origin E2E_FLAGS), undefined)

0 commit comments

Comments
 (0)