From 2dba94efb28407101ed1d14437e6bd058523c151 Mon Sep 17 00:00:00 2001 From: John Schaeffer Date: Wed, 14 Feb 2024 12:19:23 -0500 Subject: [PATCH] Install golangci-lint in .tools directory in Makefile (#5) * Install golangci-lint in .tools directory in Makefile CI is currently failing because it requires golangci-lint, which does not exist in the CI environment. This commit updates the Makefile so that it includes a .tools directory, as well as a Make target for golangci-lint and reference to the vendored golangci-lint binary in the lint target. Signed-off-by: John Schaeffer * Update test CI workflow to use Go 1.21 iam-runtime-infratographer and golangci-lint both require Go 1.21. This commit updates the test CI workflow to use it instead of 1.20. Signed-off-by: John Schaeffer --------- Signed-off-by: John Schaeffer --- .github/workflows/test.yaml | 2 +- .gitignore | 3 ++- Makefile | 24 +++++++++++++++++------- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 0b8b815e..91d588ed 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -19,7 +19,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v4 with: - go-version: "1.20" + go-version: "1.21" - name: Run go tests and generate coverage report run: make test diff --git a/.gitignore b/.gitignore index da7c1dde..857b4d19 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *~ coverage.out -bin/* \ No newline at end of file +bin/* +.tools/* diff --git a/Makefile b/Makefile index 4e7467d6..4089d5ac 100644 --- a/Makefile +++ b/Makefile @@ -1,20 +1,30 @@ -all: lint test +ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) +TOOLS_DIR := .tools + +GOLANGCI_LINT_REPO = github.com/golangci/golangci-lint +GOLANGCI_LINT_VERSION = v1.56.1 + +all: test build PHONY: test coverage lint golint clean vendor docker-up docker-down unit-test -GOOS=linux -# use the working dir as the app name, this should be the repo name -APP_NAME=$(shell basename $(CURDIR)) test: | lint @echo Running tests... @go test -mod=readonly -race -coverprofile=coverage.out -covermode=atomic ./... -lint: +lint: $(TOOLS_DIR)/golangci-lint @echo Linting Go files... - @golangci-lint run --modules-download-mode=readonly + @$(TOOLS_DIR)/golangci-lint run --modules-download-mode=readonly build: - @CGO_ENABLED=0 GOOS=linux go build -mod=readonly -v -o bin/${APP_NAME} + @CGO_ENABLED=0 go build -mod=readonly -v -o bin/${APP_NAME} go-dependencies: @go mod download @go mod tidy + +$(TOOLS_DIR): + mkdir -p $(TOOLS_DIR) + +$(TOOLS_DIR)/golangci-lint: | $(TOOLS_DIR) + @echo "Installing $(GOLANGCI_LINT_REPO)/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)" + @GOBIN=$(ROOT_DIR)/$(TOOLS_DIR) go install $(GOLANGCI_LINT_REPO)/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)