From d346a347a04916ce351f93f95f64f796c3b37bf7 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Wed, 6 Mar 2024 01:52:06 -0500 Subject: [PATCH] fix: execute go get/build with mod in readonly mode This will avoid issues where a build or test will inadvertently update dependencies, causing drift between what is in code and what is being tested/run. --- common.mk | 6 +++--- tests.mk | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/common.mk b/common.mk index b12151dcc..d782b5db3 100644 --- a/common.mk +++ b/common.mk @@ -28,10 +28,10 @@ clean: find . -xtype l -delete commands: **/**/commands.go - GOARCH=$(GOARCH) go build -ldflags="-s -w" $(GO_ARGS) -o commands src/commands/commands.go + GOARCH=$(GOARCH) go build -mod=readonly -ldflags="-s -w" $(GO_ARGS) -o commands src/commands/commands.go subcommands: - GOARCH=$(GOARCH) go build -ldflags="-s -w" $(GO_ARGS) -o subcommands/subcommands src/subcommands/subcommands.go + GOARCH=$(GOARCH) go build -mod=readonly -ldflags="-s -w" $(GO_ARGS) -o subcommands/subcommands src/subcommands/subcommands.go $(MAKE) $(SUBCOMMANDS) subcommands/%: @@ -41,7 +41,7 @@ src-clean: rm -rf .gitignore src vendor Makefile *.go glide.* go.sum go.mod triggers: - GOARCH=$(GOARCH) go build -ldflags="-s -w" $(GO_ARGS) -o triggers src/triggers/triggers.go + GOARCH=$(GOARCH) go build -mod=readonly -ldflags="-s -w" $(GO_ARGS) -o triggers src/triggers/triggers.go $(MAKE) $(TRIGGERS) triggers/%: diff --git a/tests.mk b/tests.mk index 76df2c743..bee1c5ad1 100644 --- a/tests.mk +++ b/tests.mk @@ -182,7 +182,7 @@ go-test-plugin: -v $$PWD:$(GO_REPO_ROOT) \ -w $(GO_REPO_ROOT) \ $(BUILD_IMAGE) \ - bash -c "cd plugins/$(PLUGIN_NAME) && go get github.com/onsi/gomega && go test -v -p 1 -race " || exit $$? + bash -c "cd plugins/$(PLUGIN_NAME) && go get github.com/onsi/gomega && go test -v -p 1 -race -mod=readonly " || exit $$? unit-tests: go-tests @echo running bats unit tests...