Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions .github/workflows/golangci_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,21 @@ jobs:
contents: read
actions: read
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
persist-credentials: false

- name: Get golangci-lint version from asdf
id: get-version
run: |
version=$(grep '^golangci-lint ' .tool-versions | awk '{print $2}')
echo "version=${version}" | tee -a "$GITHUB_OUTPUT"

- name: golangci-lint
if: ${{ always() && !contains(join(github.event.pull_request.labels.*.name, ' '), 'allow-lint-issues') }}
uses: smartcontractkit/.github/actions/ci-lint-go@ci-lint-go/v2
# NOTE: Keep this version in sync with ACTION_CI_LINT_GO_GIT_TAG in ./script/lint.sh
uses: smartcontractkit/.github/actions/ci-lint-go@ci-lint-go/3.0.0
Comment thread Dismissed
with:
golangci-lint-version: v2.2.2
checkout-repo: false
golangci-lint-version: v${{ steps.get-version.outputs.version }}
162 changes: 0 additions & 162 deletions .golangci.yml

This file was deleted.

6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ generate: mockery install-protoc gomods cre-protoc modgraph
cre-protoc:
cd pkg/capabilities/v2/protoc && go build -o protoc-gen-cre .


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

Expand Down
28 changes: 27 additions & 1 deletion script/lint.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,43 @@
#!/bin/bash
#!/usr/bin/env bash

# run_linter.sh
# This script runs golangci-lint either locally or in a Docker container based on version matching.

# Parameters
GOLANGCI_LINT_VERSION="$1"
COMMON_OPTS="$2"
DIRECTORY="$3"
EXTRA_OPTS="$4"
OUTPUT_FILE="$DIRECTORY/$(date +%Y-%m-%d_%H:%M:%S).txt"

# Require GOLANGCI_LINT_VERSION as first argument
if [[ -z "${GOLANGCI_LINT_VERSION:-}" ]]; then
echo "Error: GOLANGCI_LINT_VERSION env var is required." >&2
echo "Usage: $0 <golangci-lint-version> <common-opts> <directory> [extra-opts]" >&2
exit 1
fi


# Prepare the lint directory
mkdir -p "$DIRECTORY"

# Check if user provided a local config path via env var
if [[ -n "${GOLANGCI_LINT_CONFIG:-}" ]]; then
CONFIG_FILE="$GOLANGCI_LINT_CONFIG"
echo "Using user-provided config: $CONFIG_FILE"
else
# NOTE: Keep this version in sync with the action tag in /.github/workflows/golangci_lint.yml
ACTION_CI_LINT_GO_GIT_TAG="${CI_LINT_GO_VERSION:-ci-lint-go/3.0.0}"
# Download remote golangci-lint config to gitignored directory
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"
CONFIG_FILE="$DIRECTORY/golangci.remote.yml"
echo "Downloading remote config from: $REMOTE_CONFIG_URL"
curl -sfL "$REMOTE_CONFIG_URL" -o "$CONFIG_FILE"
fi

# Always use the selected config
COMMON_OPTS="$COMMON_OPTS --config $CONFIG_FILE"

DOCKER_CMD="docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v$GOLANGCI_LINT_VERSION golangci-lint run $COMMON_OPTS $EXTRA_OPTS"

if command -v golangci-lint >/dev/null 2>&1; then
Expand Down
Loading