diff --git a/.envrc b/.envrc index b0d5a510..0783ed12 100644 --- a/.envrc +++ b/.envrc @@ -2,7 +2,6 @@ AKASH_ROOT=$(pwd) export AKASH_ROOT dotenv -dotenv_if_exists dev.env TOOLS=${AKASH_ROOT}/script/tools.sh SEMVER=${AKASH_ROOT}/script/semver.sh @@ -19,6 +18,14 @@ fi AKASH_DIRENV_SET=1 +dotenv_if_exists dev.env + +if [[ ${GOWORK} != "off" ]] && [[ -f go.work ]]; then + GOWORK=${AKASH_ROOT}/go.work +else + GOWORK=off +fi + export TOOLS export SEMVER export GOTOOLCHAIN diff --git a/Makefile b/Makefile index 5a308ba6..65fc7e70 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,31 @@ ifeq (, $(GOTOOLCHAIN)) $(error "GOTOOLCHAIN is not set") endif +ifeq ($(GO111MODULE),off) +else + GOMOD=readonly +endif + +ifneq ($(GOWORK),off) + ifeq ($(shell test -e ${AKASH_ROOT}/go/go.work && echo -n yes),yes) + GOWORK=${AKASH_ROOT}/go/go.work + else + GOWORK=off + endif +endif + +ifneq ($(GOWORK),off) + ifeq ($(GOMOD),$(filter $(GOMOD),mod "")) +$(error '-mod may only be set to readonly or vendor when in workspace mode, but it is set to ""') + endif +endif + +ifeq ($(GOMOD),vendor) + ifneq ($(wildcard ./vendor/.),) +$(error "go -mod is in vendor mode but vendor dir has not been found. consider to run go mod vendor") + endif +endif + GO_ROOT := go TS_ROOT := $(AKASH_TS_ROOT) diff --git a/make/test.mk b/make/test.mk index 6265358c..d9b6f0bc 100644 --- a/make/test.mk +++ b/make/test.mk @@ -8,7 +8,7 @@ ts GO_TEST_OPTS ?= GO_TEST_TIMEOUT ?= 300 -test_go_flags := -mod=readonly -timeout $(GO_TEST_TIMEOUT)s +test_go_flags := -mod=$(GOMOD) -timeout $(GO_TEST_TIMEOUT)s ifneq (,$(findstring nocache,$(GO_TEST_OPTS))) test_go_flags += -count=1 @@ -38,10 +38,12 @@ test-coverage-ts: $(AKASH_TS_NODE_MODULES) .PHONY: test-go test-go: export GO111MODULE := $(GO111MODULE) +test-coverage-go: export GOWORK := $(GOWORK) test-go: @$(TOOLS) gotest "$(GO_MODULES)" "$(test_go_flags)" "$(GO_TEST_DIRS)" .PHONY: test-coverage-go test-coverage-go: export GO111MODULE := $(GO111MODULE) +test-coverage-go: export GOWORK := $(GOWORK) test-coverage-go: @$(TOOLS) gocoverage "$(GO_MODULES)" "$(test_go_flags)" "$(GO_TEST_DIRS)"