From af87d20c8be3ade31b202df3c5c290c5fd5bc2a6 Mon Sep 17 00:00:00 2001 From: Andrea Zucchini Date: Mon, 13 Nov 2023 16:40:21 +0000 Subject: [PATCH 1/2] chore: automate go version upgrade We will use the latest version of Golang for executing the tests. We change the structure of the Makefile and the run-test GitHub action to bump the Golang version automatically in the Makefile, go.mod and GitHub action files. [#186180915](https://www.pivotaltracker.com/story/show/186180915) --- .github/workflows/run-tests.yml | 9 ++---- Makefile | 49 ++++++++++++++++++++++++++------- 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 0f8fcb33..c5414868 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -13,17 +13,14 @@ on: jobs: test: runs-on: ubuntu-latest - strategy: - matrix: - version: [ '1.20', '1.21' ] - name: Go ${{ matrix.version }} + name: Go test outputs: pr_number: ${{ github.event.number }} steps: - uses: actions/setup-go@v2 with: - go-version: ${{ matrix.version }} - - uses: actions/checkout@v2 + go-version: '1.21.4' + - uses: actions/checkout@v4 - run: make test call-dependabot-pr-workflow: needs: test diff --git a/Makefile b/Makefile index de2670d0..4232d6ef 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,29 @@ .DEFAULT_GOAL = help +GO-VERSION = 1.21.4 +GO-VER = go$(GO-VERSION) + +GO_OK := $(or $(USE_GO_CONTAINERS), $(shell which go 1>/dev/null 2>/dev/null; echo $$?)) +DOCKER_OK := $(shell which docker 1>/dev/null 2>/dev/null; echo $$?) + +ifeq ($(GO_OK), 0) # use local go binary + +PAK_PATH=$(PWD) +GO=go +GOFMT=gofmt + +else ifeq ($(DOCKER_OK), 0) + +PAK_PATH=/brokerapi +GO_DOCKER_OPTS=--rm -v $(PWD):$(PAK_PATH) -w $(PAK_PATH) --network=host +GO=docker run $(GO_DOCKER_OPTS) golang:latest go +GOFMT=docker run $(GO_DOCKER_OPTS) golang:latest gofmt + +else +$(error either Go or Docker must be installed) +endif + .PHONY: help help: ## list Makefile targets @@ -9,26 +32,32 @@ help: ## list Makefile targets ###### Targets ################################################################ -test: version download fmt vet ginkgo ## Runs all build, static analysis, and test steps +test: deps-go-binary download fmt vet ginkgo ## Runs all build, static analysis, and test steps download: ## Download dependencies - go mod download + ${GO} mod download vet: ## Run static code analysis - go vet ./... - go run honnef.co/go/tools/cmd/staticcheck ./... + ${GO} vet ./... + ${GO} run honnef.co/go/tools/cmd/staticcheck ./... ginkgo: ## Run tests using Ginkgo - go run github.com/onsi/ginkgo/v2/ginkgo -r + ${GO} run github.com/onsi/ginkgo/v2/ginkgo -r fmt: ## Checks that the code is formatted correctly - @@if [ -n "$$(gofmt -s -e -l -d .)" ]; then \ + @@if [ -n "$$(${GOFMT} -s -e -l -d .)" ]; then \ echo "gofmt check failed: run 'gofmt -d -e -l -w .'"; \ exit 1; \ fi generate: ## Generates the fakes using counterfeiter - go generate ./... - -version: ## Display the version of Go - @@go version + ${GO} generate ./... + +.PHONY: deps-go-binary +deps-go-binary: +ifeq ($(SKIP_GO_VERSION_CHECK),) + @@if [ "$$($(GO) version | awk '{print $$3}')" != "${GO-VER}" ]; then \ + echo "Go version does not match: expected: ${GO-VER}, got $$($(GO) version | awk '{print $$3}')"; \ + exit 1; \ + fi +endif From bdd6ec3bab67b6d36a10c9b2f2ea4e6dc9406350 Mon Sep 17 00:00:00 2001 From: Andrea Zucchini Date: Tue, 14 Nov 2023 12:32:43 +0000 Subject: [PATCH 2/2] chore: simplify code [#186180915](https://www.pivotaltracker.com/story/show/186180915) --- Makefile | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/Makefile b/Makefile index 4232d6ef..295f7f8e 100644 --- a/Makefile +++ b/Makefile @@ -5,26 +5,9 @@ GO-VERSION = 1.21.4 GO-VER = go$(GO-VERSION) -GO_OK := $(or $(USE_GO_CONTAINERS), $(shell which go 1>/dev/null 2>/dev/null; echo $$?)) -DOCKER_OK := $(shell which docker 1>/dev/null 2>/dev/null; echo $$?) - -ifeq ($(GO_OK), 0) # use local go binary - -PAK_PATH=$(PWD) GO=go GOFMT=gofmt -else ifeq ($(DOCKER_OK), 0) - -PAK_PATH=/brokerapi -GO_DOCKER_OPTS=--rm -v $(PWD):$(PAK_PATH) -w $(PAK_PATH) --network=host -GO=docker run $(GO_DOCKER_OPTS) golang:latest go -GOFMT=docker run $(GO_DOCKER_OPTS) golang:latest gofmt - -else -$(error either Go or Docker must be installed) -endif - .PHONY: help help: ## list Makefile targets