Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 37 additions & 8 deletions script/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ set -e
CUSTOM_GCL="$(script/setup-custom-gcl.sh)"

CDPATH="" cd -- "$(dirname -- "$0")/.."
BIN="$(pwd -P)"/bin

EXIT_CODE=0

Expand All @@ -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"
Expand All @@ -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"
6 changes: 3 additions & 3 deletions script/setup-custom-gcl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
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

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

Expand Down
Loading