Skip to content
Open
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
53 changes: 49 additions & 4 deletions hack/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ if [[ ${2:-} == "remove-dummy" ]]; then
rm -f cmd/repo-init/frontend/dist/dummy
fi

# BUILD_IMAGES is an allow-list: if set, only these binaries are built.
# SKIPPED_IMAGES is a deny-list: if set, these binaries are skipped.
# BUILD_IMAGES takes precedence over SKIPPED_IMAGES.
declare -A build_images_map
if [[ -n "${BUILD_IMAGES:-}" ]]; then
echo "Building only: ${BUILD_IMAGES}"
IFS=',' read -ra build_array <<< "${BUILD_IMAGES}"
for img in "${build_array[@]}"; do
build_images_map["${img}"]=1
done
fi

declare -A skipped_images_map
if [[ -n "${SKIPPED_IMAGES:-}" ]]; then
echo "Skipping images: ${SKIPPED_IMAGES}"
Expand All @@ -36,11 +48,44 @@ if [[ -n "${SKIPPED_IMAGES:-}" ]]; then
done
fi

for dir in $( find ./cmd/ -mindepth 1 -maxdepth 1 -type d -not \( -name '*ipi-deprovison*' \) ); do
MAX_PARALLEL="${MAX_PARALLEL:-4}"
pids=()
failures=()

for dir in $( find ./cmd/ -mindepth 1 -maxdepth 1 -type d -not \( -name '*ipi-deprovison*' \) | sort ); do
command="$( basename "${dir}" )"
if [[ -n "${skipped_images_map[${command}]:-}" ]]; then
echo "Skipping install for ${command} (in SKIPPED_IMAGES)"

# If BUILD_IMAGES is set, only build listed binaries
if [[ -n "${BUILD_IMAGES:-}" ]]; then
if [[ -z "${build_images_map[${command}]:-}" ]]; then
continue
fi
elif [[ -n "${skipped_images_map[${command}]:-}" ]]; then
echo "Skipping install for ${command} (in SKIPPED_IMAGES)"
continue
fi

echo "Building ${command}..."
go install -v $RACE_FLAG -ldflags "-X 'sigs.k8s.io/prow/pkg/version.Name=${command}' -X 'sigs.k8s.io/prow/pkg/version.Version=${version}'" "./cmd/${command}/..." &
pids+=($!)

# Throttle: wait for a slot when we hit the limit
if [[ ${#pids[@]} -ge $MAX_PARALLEL ]]; then
if ! wait "${pids[0]}"; then
failures+=("${pids[0]}")
fi
pids=("${pids[@]:1}")
fi
done

# Wait for remaining builds
for pid in "${pids[@]}"; do
if ! wait "$pid"; then
failures+=("$pid")
fi
go install -v $RACE_FLAG -ldflags "-X 'sigs.k8s.io/prow/pkg/version.Name=${command}' -X 'sigs.k8s.io/prow/pkg/version.Version=${version}'" "./cmd/${command}/..."
done

if [[ ${#failures[@]} -gt 0 ]]; then
echo "ERROR: ${#failures[@]} build(s) failed"
exit 1
fi
Comment on lines +68 to +91
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Failed builds are not identified by name, making debugging harder.

When a build fails, the error message only reports the count of failures. In CI logs with interleaved output from parallel builds, developers won't easily know which binary failed.

Consider tracking command names alongside PIDs for actionable error messages.

Suggested improvement
+declare -A pid_to_cmd
+
 for dir in $( find ./cmd/ -mindepth 1 -maxdepth 1 -type d -not \( -name '*ipi-deprovison*' \) | sort ); do
     command="$( basename "${dir}" )"
 
     # If BUILD_IMAGES is set, only build listed binaries
     if [[ ${`#build_images_map`[@]} -gt 0 ]]; then
       if [[ -z "${build_images_map[${command}]:-}" ]]; then
         continue
       fi
     elif [[ -n "${skipped_images_map[${command}]:-}" ]]; then
       echo "Skipping install for ${command} (in SKIPPED_IMAGES)"
       continue
     fi
 
     echo "Building ${command}..."
     go install -v $RACE_FLAG -ldflags "-X 'sigs.k8s.io/prow/pkg/version.Name=${command}' -X 'sigs.k8s.io/prow/pkg/version.Version=${version}'" "./cmd/${command}/..." &
-    pids+=($!)
+    pid=$!
+    pids+=($pid)
+    pid_to_cmd[$pid]="${command}"
 done
 
 # Wait for all parallel builds and collect failures
 for pid in "${pids[@]}"; do
     if ! wait "$pid"; then
-        failures+=("$pid")
+        failures+=("${pid_to_cmd[$pid]}")
     fi
 done
 
 if [[ ${`#failures`[@]} -gt 0 ]]; then
-    echo "ERROR: ${`#failures`[@]} build(s) failed"
+    echo "ERROR: ${`#failures`[@]} build(s) failed: ${failures[*]}"
     exit 1
 fi
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@hack/install.sh` around lines 67 - 82, The script currently tracks only PIDs
(pids array) and counts failures (failures array) so failing builds aren't
named; change the launch loop to record the mapping of PID to command (e.g.,
declare -A pid_to_cmd and after starting each go install put
pid_to_cmd[$!]="$command"), then in the wait loop use that map to capture the
failed command name (retrieve pid_to_cmd[$pid]) and append the command name (not
just PID) to failures; finally, print the failing command names when reporting
errors. Ensure an associative array is declared before use and that you still
collect PIDs in pids for wait.