Merge pull request #12197 from prometheus/superq/sync_old_ci_lint

Update golangci-lint
This commit is contained in:
Julien Pivotto 2023-06-27 15:22:34 +02:00 committed by GitHub
commit 6188038f61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 68 additions and 18 deletions

View file

@ -150,7 +150,7 @@ jobs:
uses: golangci/golangci-lint-action@v3.4.0 uses: golangci/golangci-lint-action@v3.4.0
with: with:
args: --verbose args: --verbose
version: v1.51.2 version: v1.53.3
fuzzing: fuzzing:
uses: ./.github/workflows/fuzzing.yml uses: ./.github/workflows/fuzzing.yml
if: github.event_name == 'pull_request' if: github.event_name == 'pull_request'

View file

@ -31,14 +31,19 @@ issues:
linters-settings: linters-settings:
depguard: depguard:
list-type: blacklist rules:
include-go-root: true main:
packages-with-error-message: deny:
- sync/atomic: "Use go.uber.org/atomic instead of sync/atomic" - pkg: "sync/atomic"
- github.com/stretchr/testify/assert: "Use github.com/stretchr/testify/require instead of github.com/stretchr/testify/assert" desc: "Use go.uber.org/atomic instead of sync/atomic"
- github.com/go-kit/kit/log: "Use github.com/go-kit/log instead of github.com/go-kit/kit/log" - pkg: "github.com/stretchr/testify/assert"
- io/ioutil: "Use corresponding 'os' or 'io' functions instead." desc: "Use github.com/stretchr/testify/require instead of github.com/stretchr/testify/assert"
- regexp: "Use github.com/grafana/regexp instead of regexp" - pkg: "github.com/go-kit/kit/log"
desc: "Use github.com/go-kit/log instead of github.com/go-kit/kit/log"
- pkg: "io/ioutil"
desc: "Use corresponding 'os' or 'io' functions instead."
- pkg: "regexp"
desc: "Use github.com/grafana/regexp instead of regexp"
errcheck: errcheck:
exclude-functions: exclude-functions:
# Don't flag lines such as "io.Copy(io.Discard, resp.Body)". # Don't flag lines such as "io.Copy(io.Discard, resp.Body)".
@ -56,3 +61,9 @@ linters-settings:
local-prefixes: github.com/prometheus/prometheus local-prefixes: github.com/prometheus/prometheus
gofumpt: gofumpt:
extra-rules: true extra-rules: true
revive:
rules:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter
- name: unused-parameter
severity: warning
disabled: true

View file

@ -61,7 +61,7 @@ PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_
SKIP_GOLANGCI_LINT := SKIP_GOLANGCI_LINT :=
GOLANGCI_LINT := GOLANGCI_LINT :=
GOLANGCI_LINT_OPTS ?= GOLANGCI_LINT_OPTS ?=
GOLANGCI_LINT_VERSION ?= v1.51.2 GOLANGCI_LINT_VERSION ?= v1.53.3
# golangci-lint only supports linux, darwin and windows platforms on i386/amd64. # golangci-lint only supports linux, darwin and windows platforms on i386/amd64.
# windows isn't included here because of the path separator being different. # windows isn't included here because of the path separator being different.
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin)) ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))

32
scripts/golangci-lint.yml Normal file
View file

@ -0,0 +1,32 @@
---
# This action is synced from https://github.com/prometheus/prometheus
name: golangci-lint
on:
push:
paths:
- "go.sum"
- "go.mod"
- "**.go"
- "scripts/errcheck_excludes.txt"
- ".github/workflows/golangci-lint.yml"
- ".golangci.yml"
pull_request:
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: install Go
uses: actions/setup-go@v3
with:
go-version: 1.20.x
- name: Install snmp_exporter/generator dependencies
run: sudo apt-get update && sudo apt-get -y install libsnmp-dev
if: github.repository == 'prometheus/snmp_exporter'
- name: Lint
uses: golangci/golangci-lint-action@v3.4.0
with:
version: v1.53.3

View file

@ -37,7 +37,7 @@ if [ -z "${GITHUB_TOKEN}" ]; then
fi fi
# List of files that should be synced. # List of files that should be synced.
SYNC_FILES="CODE_OF_CONDUCT.md LICENSE Makefile.common SECURITY.md .yamllint .github/workflows/golangci-lint.yml" SYNC_FILES="CODE_OF_CONDUCT.md LICENSE Makefile.common SECURITY.md .yamllint scripts/golangci-lint.yml"
# Go to the root of the repo # Go to the root of the repo
cd "$(git rev-parse --show-cdup)" || exit 1 cd "$(git rev-parse --show-cdup)" || exit 1
@ -115,20 +115,23 @@ process_repo() {
local needs_update=() local needs_update=()
for source_file in ${SYNC_FILES}; do for source_file in ${SYNC_FILES}; do
source_checksum="$(sha256sum "${source_dir}/${source_file}" | cut -d' ' -f1)" source_checksum="$(sha256sum "${source_dir}/${source_file}" | cut -d' ' -f1)"
if [[ "${source_file}" == 'scripts/golangci-lint.yml' ]] && ! check_go "${org_repo}" "${default_branch}" ; then
target_file="$(curl -sL --fail "https://raw.githubusercontent.com/${org_repo}/${default_branch}/${source_file}")" echo "${org_repo} is not Go, skipping golangci-lint.yml."
continue
fi
if [[ "${source_file}" == 'LICENSE' ]] && ! check_license "${target_file}" ; then if [[ "${source_file}" == 'LICENSE' ]] && ! check_license "${target_file}" ; then
echo "LICENSE in ${org_repo} is not apache, skipping." echo "LICENSE in ${org_repo} is not apache, skipping."
continue continue
fi fi
if [[ "${source_file}" == '.github/workflows/golangci-lint.yml' ]] && ! check_go "${org_repo}" "${default_branch}" ; then target_filename="${source_file}"
echo "${org_repo} is not Go, skipping .github/workflows/golangci-lint.yml." if [[ "${source_file}" == 'scripts/golangci-lint.yml' ]] ; then
continue target_filename=".github/workflows/${source_file}"
fi fi
target_file="$(curl -sL --fail "https://raw.githubusercontent.com/${org_repo}/${default_branch}/${target_filename}")"
if [[ -z "${target_file}" ]]; then if [[ -z "${target_file}" ]]; then
echo "${source_file} doesn't exist in ${org_repo}" echo "${source_file} doesn't exist in ${org_repo}"
case "${source_file}" in case "${source_file}" in
CODE_OF_CONDUCT.md | SECURITY.md | .github/workflows/golangci-lint.yml) CODE_OF_CONDUCT.md | SECURITY.md)
echo "${source_file} missing in ${org_repo}, force updating." echo "${source_file} missing in ${org_repo}, force updating."
needs_update+=("${source_file}") needs_update+=("${source_file}")
;; ;;
@ -159,8 +162,12 @@ process_repo() {
# Update the files in target repo by one from prometheus/prometheus. # Update the files in target repo by one from prometheus/prometheus.
for source_file in "${needs_update[@]}"; do for source_file in "${needs_update[@]}"; do
target_filename="${source_file}"
if [[ "${source_file}" == 'scripts/golangci-lint.yml' ]] ; then
target_filename=".github/workflows/${source_file}"
fi
case "${source_file}" in case "${source_file}" in
*) cp -f "${source_dir}/${source_file}" "./${source_file}" ;; *) cp -f "${source_dir}/${source_file}" "./${target_filename}" ;;
esac esac
done done