Add module command lint_with_docker to run lint within docker with a pinned golangci-lint version

This commit is contained in:
Joshua Casey
2024-05-07 13:21:47 -05:00
parent 1e6b8a0be0
commit c31a0e37bf
3 changed files with 22 additions and 8 deletions

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bash
# Copyright 2022-2023 the Pinniped contributors. All Rights Reserved.
# Copyright 2022-2024 the Pinniped contributors. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
set -euo pipefail
@@ -11,11 +11,15 @@ cd "${ROOT}"
# Print the Go version.
go version
lint_version=$(cat hack/lib/lint-version.txt)
echo "Will install golangci-lint@${lint_version}"
# Install the same version of the linter that is used in the CI pipelines
# so you can get the same results when running the linter locally.
# Whenever the linter is updated in the CI pipelines, it should also be
# updated here to make local development more convenient.
go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.1
go install -v "github.com/golangci/golangci-lint/cmd/golangci-lint@${lint_version}"
golangci-lint --version
echo "Finished. You may need to run 'rehash' in your current shell before using the new version (e.g. if you are using gvm)."

View File

@@ -0,0 +1 @@
v1.58.1

View File

@@ -12,10 +12,6 @@ function tidy_cmd() {
echo "go mod tidy -v -go=${version} -compat=${version}"
}
function lint_cmd() {
echo "golangci-lint run --modules-download-mode=readonly --timeout=30m"
}
function test_cmd() {
echo "go test -count 1 -race ./..."
}
@@ -61,8 +57,21 @@ function main() {
;;
'lint' | 'linter' | 'linters')
golangci-lint --version
echo
with_modules 'lint_cmd'
go version
golangci-lint run --modules-download-mode=readonly --timeout=30m
;;
'lint_in_docker')
local lint_version
lint_version="${2:-latest}"
docker run --rm \
--volume "${ROOT/..}":/pinniped \
--volume "$(go env GOCACHE):/gocache" \
--volume "$(go env GOMODCACHE):/gomodcache" \
--env GOCACHE=/gocache \
--env GOMODCACHE=/gomodcache \
--workdir /pinniped \
golangci/golangci-lint:$lint_version \
./hack/module.sh lint
;;
'test' | 'tests')
with_modules 'test_cmd'