Enforce go version at build time. (#1962)

Drop obsolete make target: generate
This commit is contained in:
Ben Ash 2023-07-28 12:02:50 -04:00 committed by GitHub
parent b6a1fc4405
commit c442b25f43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 11 deletions

View file

@ -6,12 +6,15 @@ TF_ACC_TERRAFORM_VERSION ?= 1.2.2
TESTARGS ?= -test.v
TEST_PATH ?= ./...
go-version-check: ## Check go version
@sh -c $(CURDIR)/scripts/goversioncheck.sh
default: build
build: fmtcheck
build: go-version-check fmtcheck
go install
test: fmtcheck
test: go-version-check fmtcheck
TF_ACC= go test $(TESTARGS) -timeout 10m $(TEST_PATH)
testacc: fmtcheck
@ -20,19 +23,14 @@ testacc: fmtcheck
testacc-ent:
make testacc TF_ACC_ENTERPRISE=1
dev: fmtcheck
dev: go-version-check fmtcheck
go build -o terraform-provider-vault
mv terraform-provider-vault ~/.terraform.d/plugins/
debug: fmtcheck
debug: go-version-check fmtcheck
go build -gcflags "all=-N -l" -o terraform-provider-vault
mv terraform-provider-vault ~/.terraform.d/plugins/
generate:
result=$(cd generated && find . -type f -not -name '*_test.go' | grep -v 'registry.go' | xargs rm && cd - )
go run cmd/generate/main.go -openapi-doc=testdata/openapi.json
make fmt
vet:
@echo "go vet ."
@go vet $$(go list ./...) ; if [ $$? -eq 1 ]; then \
@ -45,7 +43,7 @@ vet:
fmt:
gofmt -s -w $(GOFMT_FILES)
fmtcheck:
fmtcheck: go-version-check
@sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'"
errcheck:
@ -73,4 +71,4 @@ ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
endif
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider-test PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)
.PHONY: build test testacc testacc-ent vet fmt fmtcheck errcheck test-compile website website-test
.PHONY: build test testacc testacc-ent vet fmt fmtcheck errcheck test-compile website website-test go-version-check

30
scripts/goversioncheck.sh Executable file
View file

@ -0,0 +1,30 @@
#!/usr/bin/env bash
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0
# Copied from vault-secrets-operator.
GO_CMD=${GO_CMD:-go}
root="$(git rev-parse --show-toplevel || echo .)"
PROJECT="${root##*/}"
GO_VERSION_MIN="${1:-$(cat $root/.go-version)}"
if $GO_CMD version | grep -q devel;
then
GO_VERSION="devel"
else
GO_VERSION=$($GO_CMD version | grep -o 'go[0-9]\+\.[0-9]\+\(\.[0-9]\+\)\?' | tr -d 'go')
IFS="." read -r -a GO_VERSION_ARR <<< "$GO_VERSION"
IFS="." read -r -a GO_VERSION_REQ <<< "$GO_VERSION_MIN"
if [[ ${GO_VERSION_ARR[0]} -lt ${GO_VERSION_REQ[0]} ||
( ${GO_VERSION_ARR[0]} -eq ${GO_VERSION_REQ[0]} &&
( ${GO_VERSION_ARR[1]} -lt ${GO_VERSION_REQ[1]} ||
( ${GO_VERSION_ARR[1]} -eq ${GO_VERSION_REQ[1]} && ${GO_VERSION_ARR[2]} -lt ${GO_VERSION_REQ[2]} )))
]]; then
echo "$PROJECT requires go $GO_VERSION_MIN to build; found $GO_VERSION." >&2
exit 1
fi
fi