diff --git a/hack/install-linter.sh b/hack/install-linter.sh index 042b23811..1c942acdf 100755 --- a/hack/install-linter.sh +++ b/hack/install-linter.sh @@ -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)." diff --git a/hack/lib/lint-version.txt b/hack/lib/lint-version.txt new file mode 100644 index 000000000..1c55d0483 --- /dev/null +++ b/hack/lib/lint-version.txt @@ -0,0 +1 @@ +v1.58.1 diff --git a/hack/module.sh b/hack/module.sh index 3cd2754a3..d4843f567 100755 --- a/hack/module.sh +++ b/hack/module.sh @@ -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'