diff --git a/script/lint.sh b/script/lint.sh index ae3878b9f40..e87c295b06e 100755 --- a/script/lint.sh +++ b/script/lint.sh @@ -8,7 +8,6 @@ set -e CUSTOM_GCL="$(script/setup-custom-gcl.sh)" CDPATH="" cd -- "$(dirname -- "$0")/.." -BIN="$(pwd -P)"/bin EXIT_CODE=0 @@ -17,17 +16,49 @@ fail() { EXIT_CODE=1 } -MOD_DIRS="$(git ls-files '*go.mod' | xargs dirname | sort)" +MOD_DIRS="$(git ls-files '*go.mod' | xargs dirname | sort -u)" -for dir in $MOD_DIRS; do - [ "$dir" = "example/newreposecretwithlibsodium" ] && continue - echo linting "$dir" +# Number of module lint jobs to run concurrently. +# Override with LINT_JOBS, otherwise use detected CPU count. +: "${LINT_JOBS:=$(getconf _NPROCESSORS_ONLN 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)}" + +LINT_DIRS="$(printf '%s\n' "$MOD_DIRS" | grep -v '^example/newreposecretwithlibsodium$')" + +LINT_FAILED=0 +RUNNING=0 +PIDS="" + +wait_pids() { + for pid in $PIDS; do + if ! wait "$pid"; then + LINT_FAILED=1 + fi + done + PIDS="" + RUNNING=0 +} + +for dir in $LINT_DIRS; do ( + echo linting "$dir" cd "$dir" "$CUSTOM_GCL" run - ) || fail "failed linting $dir" + ) & + + PIDS="$PIDS $!" + RUNNING=$((RUNNING + 1)) + + if [ "$RUNNING" -ge "$LINT_JOBS" ]; then + wait_pids + fi done +wait_pids + +if [ "$LINT_FAILED" -ne 0 ]; then + fail "failed linting one or more module directories" +fi + if [ -n "$CHECK_GITHUB_OPENAPI" ]; then echo validating openapi_operations.yaml script/metadata.sh update-openapi --validate || fail "failed validating openapi_operations.yaml" @@ -36,6 +67,4 @@ fi echo validating generated files script/generate.sh --check || fail "failed validating generated files" -[ -z "$FAILED" ] || exit 1 - exit "$EXIT_CODE" diff --git a/script/setup-custom-gcl.sh b/script/setup-custom-gcl.sh index 81d84215756..0dd896cfd33 100755 --- a/script/setup-custom-gcl.sh +++ b/script/setup-custom-gcl.sh @@ -5,7 +5,7 @@ set -e # should be in sync with .custom-gcl.yml -GOLANGCI_LINT_VERSION="2.10.1" +GOLANGCI_LINT_VERSION="v2.10.1" # should in sync with fmt.sh and lint.sh BIN="$(pwd -P)"/bin @@ -13,8 +13,8 @@ BIN="$(pwd -P)"/bin mkdir -p "$BIN" # install golangci-lint and custom-gcl in ./bin if they don't exist with the correct version -if ! "$BIN"/custom-gcl --version 2> /dev/null | grep -q "$GOLANGCI_LINT_VERSION"; then - GOBIN="$BIN" go install "github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v$GOLANGCI_LINT_VERSION" +if ! "$BIN"/custom-gcl version --short 2> /dev/null | grep -q "$GOLANGCI_LINT_VERSION"; then + curl -sSfL https://golangci-lint.run/install.sh | sh -s -- -b "$BIN" "$GOLANGCI_LINT_VERSION" "$BIN"/golangci-lint custom --name custom-gcl --destination "$BIN" fi