Skip to content

Commit 7190c20

Browse files
Update linter setup in CI and locally (#757)
1 parent f6b70ec commit 7190c20

File tree

2 files changed

+75
-14
lines changed

2 files changed

+75
-14
lines changed

.github/workflows/pr_test.yml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
name: Test
2+
13
on:
24
pull_request:
35
types:
@@ -8,7 +10,6 @@ on:
810
- unlabeled
911
branches:
1012
- main
11-
name: Test
1213
jobs:
1314
changelog:
1415
if: github.actor != 'dependabot[bot]'
@@ -27,6 +28,30 @@ jobs:
2728
uses: golangci/golangci-lint-action@v8
2829
with:
2930
version: v2.4.0
31+
golangci-latest:
32+
name: lint-latest (informational)
33+
runs-on: ubuntu-latest
34+
continue-on-error: true
35+
steps:
36+
- name: Checkout code
37+
uses: actions/checkout@v5
38+
- name: Setup Go
39+
uses: actions/setup-go@v6
40+
with:
41+
go-version: 1.24.x
42+
- name: Run golangci-lint@latest
43+
id: lint
44+
uses: golangci/golangci-lint-action@v8
45+
with:
46+
version: latest
47+
continue-on-error: true
48+
- name: Report lint summary
49+
run: |
50+
if [ "${{ steps.lint.outcome }}" == "success" ]; then
51+
echo "✅ golangci-lint@latest passed." >> $GITHUB_STEP_SUMMARY
52+
else
53+
echo "⚠️ golangci-lint@latest failed (informational only)." >> $GITHUB_STEP_SUMMARY
54+
fi
3055
test:
3156
strategy:
3257
matrix:

Makefile

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,15 @@ DEFAULT_FASTLY_TEST_COMPUTE_SERVICE_ID = XsjdElScZGjmfCcTwsYRC1
2323
FASTLY_TEST_NGWAF_WORKSPACE_ID ?=
2424
DEFAULT_FASTLY_TEST_NGWAF_WORKSPACE_ID = Am2qjXkgamuYp3u54rQkLD
2525
FASTLY_API_KEY ?=
26-
#
26+
2727
# Enables support for tools such as https://github.com/rakyll/gotest
2828
TEST_COMMAND ?= $(GO) test
2929

30+
# Tooling versions
31+
GOLANGCI_LINT_VERSION = v2.4.0
32+
BIN_DIR := $(CURDIR)/bin
33+
GOLANGCI_LINT := $(BIN_DIR)/golangci-lint
34+
3035
all: mod-download tidy fmt lint test semgrep ## Runs all of the required cleaning and verification targets.
3136
.PHONY: all
3237

@@ -40,26 +45,53 @@ tidy: ## Cleans the Go module.
4045
@$(GO) mod tidy
4146
.PHONY: tidy
4247

43-
fmt: ## Properly formats Go files and orders dependencies.
48+
install-linter: ## Installs golangci-lint v2.4.0 into ./bin (cross-platform)
49+
@echo "==> Installing golangci-lint $(GOLANGCI_LINT_VERSION)"
50+
@mkdir -p $(BIN_DIR)
51+
@if [ ! -x "$(GOLANGCI_LINT)" ]; then \
52+
OS=$$(uname | tr '[:upper:]' '[:lower:]'); \
53+
ARCH=$$(uname -m); \
54+
case "$$ARCH" in \
55+
x86_64) ARCH="amd64" ;; \
56+
arm64|aarch64) ARCH="arm64" ;; \
57+
*) echo "Unsupported architecture: $$ARCH" && exit 1 ;; \
58+
esac; \
59+
URL="https://github.com/golangci/golangci-lint/releases/download/$(GOLANGCI_LINT_VERSION)/golangci-lint-$(GOLANGCI_LINT_VERSION)-$$OS-$$ARCH.tar.gz"; \
60+
echo "Downloading: $$URL"; \
61+
curl -sSfL "$$URL" | tar -xz -C $(BIN_DIR) --strip-components=1; \
62+
fi
63+
.PHONY: install-linter
64+
65+
check-linter-version: ## Verifies installed golangci-lint version matches expected
66+
@echo "==> Checking golangci-lint version"
67+
@EXPECTED="$(GOLANGCI_LINT_VERSION)"; \
68+
INSTALLED=$$($(GOLANGCI_LINT) version --format short | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+'); \
69+
if [ "$$INSTALLED" != "$$EXPECTED" ]; then \
70+
echo "Expected golangci-lint $$EXPECTED but found $$INSTALLED"; \
71+
exit 1; \
72+
fi
73+
.PHONY: check-linter-version
74+
75+
fmt: install-linter ## Properly formats Go files and orders dependencies.
4476
@echo "==> Running golangci-lint fmt"
45-
@golangci-lint fmt
77+
@$(GOLANGCI_LINT) fmt
4678
.PHONY: fmt
4779

48-
test: ## Runs the test suite with VCR mocks enabled.
49-
@echo "==> Testing ${NAME}"
50-
@$(TEST_COMMAND) -timeout=30s -parallel=20 -tags="${GOTAGS}" ${GOPKGS} ${TESTARGS}
51-
.PHONY: test
52-
53-
lint: ## Runs golangci lint
80+
lint: install-linter check-linter-version ## Runs golangci lint
5481
@echo "==> Running golangci-lint"
55-
@golangci-lint run
82+
@$(GOLANGCI_LINT) run
5683
.PHONY: lint
5784

5885
semgrep: ## Run semgrep checker.
5986
@if [[ "$$(uname)" == 'Darwin' ]]; then brew install semgrep; fi
6087
@if command -v semgrep &> /dev/null; then semgrep ci --config auto --exclude-rule generic.secrets.security.detected-private-key.detected-private-key $(SEMGREP_ARGS); fi
6188
.PHONY: semgrep
6289

90+
test: ## Runs the test suite with VCR mocks enabled.
91+
@echo "==> Testing ${NAME}"
92+
@$(TEST_COMMAND) -timeout=30s -parallel=20 -tags="${GOTAGS}" ${GOPKGS} ${TESTARGS}
93+
.PHONY: test
94+
6395
test-race: ## Runs the test suite with the -race flag to identify race conditions, if they exist.
6496
@echo "==> Testing ${NAME} (race)"
6597
@$(TEST_COMMAND) -timeout=60s -race -tags="${GOTAGS}" ${GOPKGS} ${TESTARGS}
@@ -89,9 +121,13 @@ fix-ngwaf-fixtures: ## Updates test fixtures with a specified default Next-Gen W
89121

90122
nilaway: ## Run nilaway
91123
@nilaway ./...
124+
.PHONY: nilaway
125+
126+
clean-bin: ## Removes locally installed binaries
127+
@echo "==> Cleaning ./bin directory"
128+
@rm -rf $(BIN_DIR)
129+
.PHONY: clean-bin
92130

93-
.PHONY: help
94131
help: ## Prints this help menu.
95132
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
96-
97-
.PHONY: clean
133+
.PHONY: help

0 commit comments

Comments
 (0)