From 98d06d097e18989457515965e382af013fdb61cb Mon Sep 17 00:00:00 2001 From: munlicode Date: Sun, 8 Mar 2026 19:49:18 +0500 Subject: [PATCH 1/2] feat: Make `script/lint.sh` output simpler read. --- script/lint.sh | 81 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 65 insertions(+), 16 deletions(-) diff --git a/script/lint.sh b/script/lint.sh index e87c295b06e..7f62405ad2f 100755 --- a/script/lint.sh +++ b/script/lint.sh @@ -11,8 +11,14 @@ CDPATH="" cd -- "$(dirname -- "$0")/.." EXIT_CODE=0 +# Colors & Formatting +GREEN='\033[0;32m' +RED='\033[0;31m' +YELLOW='\033[0;33m' +BOLD='\033[1m' +NC='\033[0m' + fail() { - echo "$@" EXIT_CODE=1 } @@ -24,28 +30,55 @@ MOD_DIRS="$(git ls-files '*go.mod' | xargs dirname | sort -u)" LINT_DIRS="$(printf '%s\n' "$MOD_DIRS" | grep -v '^example/newreposecretwithlibsodium$')" +FAILED_COUNT=0 LINT_FAILED=0 RUNNING=0 PIDS="" +DIRS_IN_FLIGHT="" + +LOG_DIR="$(mktemp -d)" +trap 'rm -rf "$LOG_DIR"' EXIT + +# --- Helper Functions --- +print_header() { + printf "${BOLD}%s${NC}\n\n" "$1" +} + wait_pids() { + i=1 for pid in $PIDS; do - if ! wait "$pid"; then - LINT_FAILED=1 + # Identify the directory for this PID + dir=$(echo "$DIRS_IN_FLIGHT" | awk -v i="$i" '{print $i}') + log_file="$LOG_DIR/$(echo "$dir" | tr '/' '_').log" + + if wait "$pid"; then + printf "${GREEN}✔ %-40s [ PASS ]${NC}\n" "$dir" + else + printf "${RED}✘ %-40s [ FAIL ]${NC}\n" "$dir" + if [ -f "$log_file" ]; then + sed 's/^/ /' "$log_file" + fi + FAILED_COUNT=$((FAILED_COUNT + 1)) + fail fi + i=$((i + 1)) done PIDS="" + DIRS_IN_FLIGHT="" RUNNING=0 } +print_header "Linting modules" + for dir in $LINT_DIRS; do - ( - echo linting "$dir" - cd "$dir" - "$CUSTOM_GCL" run - ) & + log_file="$LOG_DIR/$(echo "$dir" | tr '/' '_').log" + + # Run the linter in the background and redirect output to a log file + (cd "$dir" && "$CUSTOM_GCL" run --color always > "$log_file" 2>&1) & PIDS="$PIDS $!" + DIRS_IN_FLIGHT="$DIRS_IN_FLIGHT $dir" RUNNING=$((RUNNING + 1)) if [ "$RUNNING" -ge "$LINT_JOBS" ]; then @@ -55,16 +88,32 @@ done wait_pids -if [ "$LINT_FAILED" -ne 0 ]; then - fail "failed linting one or more module directories" +if [ -n "$CHECK_GITHUB_OPENAPI" ]; then + print_header "Validating openapi_operations.yaml" + if script/metadata.sh update-openapi --validate; then + printf "${GREEN}✔ openapi_operations.yaml is valid${NC}\n" + else + printf "${RED}✘ openapi_operations.yaml validation failed${NC}\n" + fail + fi +fi + +print_header "Validating generated files" +if script/generate.sh --check; then + printf "${GREEN}✔ Generated files are up to date${NC}\n" +else + printf "${RED}✘ Generated files out of sync${NC}\n" + fail fi -if [ -n "$CHECK_GITHUB_OPENAPI" ]; then - echo validating openapi_operations.yaml - script/metadata.sh update-openapi --validate || fail "failed validating openapi_operations.yaml" +# --- Final Summary --- +printf -- "----------------------------\n" +SUMMARY_COLOR="$GREEN" +if [ "$FAILED_COUNT" -gt 0 ]; then + SUMMARY_COLOR="$RED" fi -echo validating generated files -script/generate.sh --check || fail "failed validating generated files" +printf "%bLinting: issues found in %d module directories.%b\n" "$SUMMARY_COLOR" "$FAILED_COUNT" "$NC" +printf -- "--------------------------------------------\n" -exit "$EXIT_CODE" +exit "$EXIT_CODE" \ No newline at end of file From 662e7cc66b072bc91f5dcc8910f30a223ea20456 Mon Sep 17 00:00:00 2001 From: munlicode Date: Mon, 9 Mar 2026 16:25:25 +0500 Subject: [PATCH 2/2] fix: Apply consistent spacing and add empty line. --- script/lint.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/script/lint.sh b/script/lint.sh index 7f62405ad2f..dc507123cf2 100755 --- a/script/lint.sh +++ b/script/lint.sh @@ -41,7 +41,7 @@ trap 'rm -rf "$LOG_DIR"' EXIT # --- Helper Functions --- print_header() { - printf "${BOLD}%s${NC}\n\n" "$1" + printf "${BOLD}%s${NC}\n\n" "$1" } @@ -91,29 +91,29 @@ wait_pids if [ -n "$CHECK_GITHUB_OPENAPI" ]; then print_header "Validating openapi_operations.yaml" if script/metadata.sh update-openapi --validate; then - printf "${GREEN}✔ openapi_operations.yaml is valid${NC}\n" + printf "${GREEN}✔ openapi_operations.yaml is valid${NC}\n" else - printf "${RED}✘ openapi_operations.yaml validation failed${NC}\n" - fail + printf "${RED}✘ openapi_operations.yaml validation failed${NC}\n" + fail fi fi print_header "Validating generated files" if script/generate.sh --check; then - printf "${GREEN}✔ Generated files are up to date${NC}\n" + printf "${GREEN}✔ Generated files are up to date${NC}\n" else - printf "${RED}✘ Generated files out of sync${NC}\n" - fail + printf "${RED}✘ Generated files out of sync${NC}\n" + fail fi # --- Final Summary --- printf -- "----------------------------\n" SUMMARY_COLOR="$GREEN" if [ "$FAILED_COUNT" -gt 0 ]; then - SUMMARY_COLOR="$RED" + SUMMARY_COLOR="$RED" fi printf "%bLinting: issues found in %d module directories.%b\n" "$SUMMARY_COLOR" "$FAILED_COUNT" "$NC" printf -- "--------------------------------------------\n" -exit "$EXIT_CODE" \ No newline at end of file +exit "$EXIT_CODE"