Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: automate go version upgrade #281

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 39 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,62 @@

.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
zucchinidev marked this conversation as resolved.
Show resolved Hide resolved
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
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

###### 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
Loading