Skip to content

Commit 8ec0475

Browse files
committed
Ensure local golangci-lint version mirrors CI
This commit sets up a repo-local tooling/bin/golangci-lint that will use the same version as CI instead of using whatever local version of golangci-lint is available on a developer's device. Signed-off-by: Michael Shen <[email protected]>
1 parent 8e3d2fe commit 8ec0475

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

.devcontainer/postCreate.sh

-6
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ cd api && npm ci
1919
# TODO: if we need to, we should move this out of here and into `api/package.json`
2020
npm install -g [email protected]
2121

22-
# Install the golang-lint
23-
# binary will be $(go env GOPATH)/bin/golangci-lint
24-
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.61.0
25-
26-
golangci-lint --version
27-
2822
# Setup the welcome screen
2923
echo "cat .devcontainer/motd" >> ~/.bashrc
3024
echo "cat .devcontainer/motd" >> ~/.zshrc

.github/workflows/ci-go.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,6 @@ jobs:
4545
- name: 'Lint'
4646
uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86 # v6.1.0
4747
with:
48-
version: 'v1.61.0'
48+
# The repo's top-level Makefile parses the version of golangci-lint from here
49+
version: v1.61.0
4950
args: '-v --build-tags=containers_image_openpgp $(go list -f ''{{.Dir}}/...'' -m | xargs)'

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ node_modules
1212
.idea
1313
env
1414
frontend/archive.tar.gz
15+
tooling/bin

Makefile

+11-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ SHELL = /bin/bash
33
# This build tag is currently leveraged by tooling/image-sync
44
# https://github.com/containers/image?tab=readme-ov-file#building
55
GOTAGS?='containers_image_openpgp'
6+
TOOLS_BIN_DIR := tooling/bin
67

78
all: test lint
89

@@ -14,7 +15,15 @@ test:
1415
# There is currently no convenient way to run golangci-lint against a whole Go workspace
1516
# https://github.com/golang/go/issues/50745
1617
MODULES := $(shell go list -f '{{.Dir}}/...' -m | xargs)
17-
lint:
18-
golangci-lint run -v --build-tags=$(GOTAGS) $(MODULES)
18+
lint: $(GOLANGCI_LINT)
19+
$(GOLANGCI_LINT) run -v --build-tags=$(GOTAGS) $(MODULES)
1920

2021
.PHONY: all clean lint test
22+
23+
GOLANGCI_LINT_BIN := golangci-lint
24+
GOLANGCI_LINT_VER := $(shell cat .github/workflows/ci-go.yml | grep [[:space:]]version: | sed 's/.*version: //')
25+
GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER))
26+
27+
$(GOLANGCI_LINT): # Setup a repo-local golangci-lint in $(GOLANGCI_LINT)
28+
$(shell curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(TOOLS_BIN_DIR) $(GOLANGCI_LINT_VER))
29+
$(shell mv $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN) $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER))

0 commit comments

Comments
 (0)