Skip to content

Commit

Permalink
chore: upgrade to Go 1.22 (#461)
Browse files Browse the repository at this point in the history
As part of this upgrade, I also upgrade golangci-lint to close #406. In
order to successfully install a newer golangci-lint locally, I had to
rip out the `hack/tools` workflow and run the linter in a container
instead. Per the golangci-lint docs, installing binaries or using a
container is preferred for local installation, and `go install` (which
is what the `hack/tools` workflow used) is not guaranteed to work:
https://golangci-lint.run/welcome/install/#install-from-source
  • Loading branch information
ctreatma authored May 16, 2024
1 parent b7357e2 commit 79823d0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 65 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@ jobs:
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Determine golangci-lint version
id: golangcilint
run: |
line=$(grep GOLANGCI_LINT_VERSION= Makefile)
version=$(echo ${line} | cut -d = -f2)
echo "version=$version" >> "$GITHUB_OUTPUT"
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.49
version: ${{ steps.golangcilint.outputs.version }}

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
24 changes: 6 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@ PLATFORMS?=darwin linux windows freebsd
ARCHITECTURES?=amd64 arm64
GOBIN?=$(shell go env GOPATH)/bin
FORMATTER?=$(GOBIN)/goimports
GO_INSTALL = ./hack/go_install.sh
TOOLS_DIR := hack/tools
TOOLS_BIN_DIR := $(abspath $(TOOLS_DIR)/bin)


# Binaries.
GOLANGCI_LINT_VER := v1.49
GOLANGCI_LINT_BIN := golangci-lint
GOLANGCI_LINT := $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER)
CRI=docker
CRI_COMMAND_BASE=${CRI} run --rm -u ${CURRENT_UID}:${CURRENT_GID} $(DOCKER_EXTRA_ARGS)
GOLANGCI_LINT_VERSION=v1.58.1
GOLANGCI_LINT_IMAGE=golangci/golangci-lint:${GOLANGCI_LINT_VERSION}
GOLANGCI_LINT=${CRI_COMMAND_BASE} -v $(CURDIR):/app -w /app -e GOLANGCI_LINT_CACHE=/tmp/.cache -e GOCACHE=/tmp/.cache ${GOLANGCI_LINT_IMAGE} golangci-lint

# Setup linker flags option for build that interoperate with variable names in src code
LDFLAGS?=-ldflags "-X $(PACKAGE_NAME)/cmd.Version=$(VERSION) -X $(PACKAGE_NAME)/cmd.Build=$(BUILD)"
Expand All @@ -42,7 +39,7 @@ fmt: $(FORMATTER)
$(FORMATTER):
go get golang.org/x/tools/cmd/goimports

lint: $(GOLANGCI_LINT) ## Lint codebase
lint: ## Lint codebase
$(GOLANGCI_LINT) run -v --fast=false

build:
Expand All @@ -69,12 +66,3 @@ generate-docs: clean-docs

test:
go test -v ./... -timeout 1000s


## --------------------------------------
## Tooling Binaries
## --------------------------------------

$(GOLANGCI_LINT): ## Build golangci-lint from tools folder.
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) github.com/golangci/golangci-lint/cmd/golangci-lint $(GOLANGCI_LINT_BIN) $(GOLANGCI_LINT_VER)
golangci-lint: $(LINTER)
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/equinix/metal-cli

go 1.19
go 1.22

require (
github.com/equinix/equinix-sdk-go v0.39.1
Expand Down
45 changes: 0 additions & 45 deletions hack/go_install.sh

This file was deleted.

0 comments on commit 79823d0

Please sign in to comment.