Skip to content

Commit

Permalink
Install golangci-lint in .tools directory in Makefile (#5)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* 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 <[email protected]>

---------

Signed-off-by: John Schaeffer <[email protected]>
  • Loading branch information
jnschaeffer authored Feb 14, 2024
1 parent e9a832e commit 2dba94e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*~
coverage.out
bin/*
bin/*
.tools/*
24 changes: 17 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 2dba94e

Please sign in to comment.