Skip to content

Commit 92f2b0b

Browse files
committed
Make linting work with remote config
1 parent 596b5d5 commit 92f2b0b

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

.github/workflows/golangci_lint.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,21 @@ jobs:
1010
contents: read
1111
actions: read
1212
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v5
15+
with:
16+
persist-credentials: false
17+
18+
- name: Get golangci-lint version from asdf
19+
id: get-version
20+
run: |
21+
version=$(grep '^golangci-lint ' .tool-versions | awk '{print $2}')
22+
echo "version=${version}" | tee -a "$GITHUB_OUTPUT"
23+
1324
- name: golangci-lint
1425
if: ${{ always() && !contains(join(github.event.pull_request.labels.*.name, ' '), 'allow-lint-issues') }}
15-
uses: smartcontractkit/.github/actions/ci-lint-go@ci-lint-go/v2
26+
# NOTE: Keep this version in sync with ACTION_CI_LINT_GO_GIT_TAG in ./script/lint.sh
27+
uses: smartcontractkit/.github/actions/ci-lint-go@ci-lint-go/3.0.0
1628
with:
17-
golangci-lint-version: v2.2.2
29+
checkout-repo: false
30+
golangci-lint-version: v${{ steps.get-version.outputs.version }}

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,12 @@ generate: mockery install-protoc gomods cre-protoc modgraph
4242
cre-protoc:
4343
cd pkg/capabilities/v2/protoc && go build -o protoc-gen-cre .
4444

45+
4546
.PHONY: lint-workspace lint
46-
GOLANGCI_LINT_VERSION := 1.64.8
47+
# If GOLANGCI_LINT_VERSION is not set, extract it from .tool-versions
48+
ifndef GOLANGCI_LINT_VERSION
49+
GOLANGCI_LINT_VERSION := $(shell grep '^golangci-lint ' .tool-versions | awk '{print $$2}')
50+
endif
4751
GOLANGCI_LINT_COMMON_OPTS := --max-issues-per-linter 0 --max-same-issues 0
4852
GOLANGCI_LINT_DIRECTORY := ./golangci-lint
4953

script/lint.sh

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,43 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
# run_linter.sh
44
# This script runs golangci-lint either locally or in a Docker container based on version matching.
5+
56
# Parameters
67
GOLANGCI_LINT_VERSION="$1"
78
COMMON_OPTS="$2"
89
DIRECTORY="$3"
910
EXTRA_OPTS="$4"
1011
OUTPUT_FILE="$DIRECTORY/$(date +%Y-%m-%d_%H:%M:%S).txt"
1112

13+
# Require GOLANGCI_LINT_VERSION as first argument
14+
if [[ -z "${GOLANGCI_LINT_VERSION:-}" ]]; then
15+
echo "Error: GOLANGCI_LINT_VERSION env var is required." >&2
16+
echo "Usage: $0 <golangci-lint-version> <common-opts> <directory> [extra-opts]" >&2
17+
exit 1
18+
fi
19+
20+
1221
# Prepare the lint directory
1322
mkdir -p "$DIRECTORY"
1423

24+
# Check if user provided a local config path via env var
25+
if [[ -n "${GOLANGCI_LINT_CONFIG:-}" ]]; then
26+
CONFIG_FILE="$GOLANGCI_LINT_CONFIG"
27+
echo "Using user-provided config: $CONFIG_FILE"
28+
else
29+
# NOTE: Keep this version in sync with the action tag in /.github/workflows/golangci_lint.yml
30+
ACTION_CI_LINT_GO_GIT_TAG="${CI_LINT_GO_VERSION:-ci-lint-go/3.0.0}"
31+
# Download remote golangci-lint config to gitignored directory
32+
REMOTE_CONFIG_URL="https://raw.githubusercontent.com/smartcontractkit/.github/refs/tags/${ACTION_CI_LINT_GO_GIT_TAG}/actions/ci-lint-go/files/golangci-default.yml"
33+
CONFIG_FILE="$DIRECTORY/golangci.remote.yml"
34+
echo "Downloading remote config from: $REMOTE_CONFIG_URL"
35+
curl -sfL "$REMOTE_CONFIG_URL" -o "$CONFIG_FILE"
36+
fi
37+
38+
# Always use the selected config
39+
COMMON_OPTS="$COMMON_OPTS --config $CONFIG_FILE"
40+
1541
DOCKER_CMD="docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v$GOLANGCI_LINT_VERSION golangci-lint run $COMMON_OPTS $EXTRA_OPTS"
1642

1743
if command -v golangci-lint >/dev/null 2>&1; then

0 commit comments

Comments
 (0)