mirror of
https://github.com/vmware-tanzu/pinniped.git
synced 2026-01-09 07:33:52 +00:00
Add module command lint_with_docker to run lint within docker with a pinned golangci-lint version
This commit is contained in:
@@ -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)."
|
||||
|
||||
1
hack/lib/lint-version.txt
Normal file
1
hack/lib/lint-version.txt
Normal file
@@ -0,0 +1 @@
|
||||
v1.58.1
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user