Skip to content

Commit

Permalink
chore: refactor gowork detection
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian committed Sep 10, 2024
1 parent bcb2271 commit 9d45efc
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
9 changes: 8 additions & 1 deletion .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 3 additions & 1 deletion make/test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)"

0 comments on commit 9d45efc

Please sign in to comment.