Skip to content

Commit d91d8f9

Browse files
justin808claude
andcommitted
Fix critical bug: move map declarations before usage
CRITICAL FIX: The script was referencing JOB_VERSION_MAP before declaring it, which would cause "unbound variable" errors due to set -euo pipefail. Changes: - Moved both JOB_MAP and JOB_VERSION_MAP declarations before first usage - Added helper function get_version_info() to eliminate code duplication - Replaced 4 repeated linear searches with function calls - Fixed inconsistent string concatenation (added braces) - Added documentation comments linking to source of truth files This improves both correctness and maintainability. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 33e9398 commit d91d8f9

File tree

1 file changed

+25
-33
lines changed

1 file changed

+25
-33
lines changed

bin/ci-rerun-failures

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -173,21 +173,8 @@ if [ -z "$FAILED_CHECKS" ]; then
173173
exit 0
174174
fi
175175

176-
echo -e "${YELLOW}Failed CI jobs:${NC}"
177-
echo "$FAILED_CHECKS" | while read -r check; do
178-
# Try to get version info for the check
179-
version_info=""
180-
for job_name in "${!JOB_VERSION_MAP[@]}"; do
181-
if [[ "$check" == "$job_name"* ]]; then
182-
version_info=" (${JOB_VERSION_MAP[$job_name]})"
183-
break
184-
fi
185-
done
186-
echo -e "${RED}$check${version_info}${NC}"
187-
done
188-
echo ""
189-
190-
# Map CI job names to local commands with version info
176+
# Map CI job names to local commands
177+
# NOTE: Version numbers below must match .github/workflows/main.yml matrix configuration
191178
declare -A JOB_MAP
192179
JOB_MAP["lint-js-and-ruby"]="bundle exec rubocop && yarn run eslint --report-unused-disable-directives && yarn start format.listDifferent"
193180
JOB_MAP["rspec-package-tests"]="bundle exec rake run_rspec:gem"
@@ -196,11 +183,30 @@ JOB_MAP["dummy-app-integration-tests (3.4, 22, latest)"]="bundle exec rake run_r
196183
JOB_MAP["dummy-app-integration-tests (3.2, 20, minimum)"]="bundle exec rake run_rspec:all_dummy"
197184
JOB_MAP["examples"]="bundle exec rake run_rspec:shakapacker_examples"
198185

199-
# Map CI job names to human-readable versions
186+
# Map CI job names to human-readable versions (matches SWITCHING_CI_CONFIGS.md)
200187
declare -A JOB_VERSION_MAP
201188
JOB_VERSION_MAP["dummy-app-integration-tests (3.4, 22, latest)"]="Ruby 3.4, Node 22, Shakapacker 9.3.0, React 19"
202189
JOB_VERSION_MAP["dummy-app-integration-tests (3.2, 20, minimum)"]="Ruby 3.2, Node 20, Shakapacker 8.2.0, React 18"
203190

191+
# Helper function to get version info for a job name
192+
get_version_info() {
193+
local job_name="$1"
194+
for mapped_job_name in "${!JOB_VERSION_MAP[@]}"; do
195+
if [[ "$job_name" == "$mapped_job_name"* ]]; then
196+
echo " (${JOB_VERSION_MAP[$mapped_job_name]})"
197+
return
198+
fi
199+
done
200+
echo ""
201+
}
202+
203+
echo -e "${YELLOW}Failed CI jobs:${NC}"
204+
echo "$FAILED_CHECKS" | while read -r check; do
205+
version_info=$(get_version_info "$check")
206+
echo -e "${RED}$check${version_info}${NC}"
207+
done
208+
echo ""
209+
204210
# Track what we'll run (deduplicated)
205211
declare -A COMMANDS_TO_RUN
206212

@@ -232,14 +238,7 @@ fi
232238
echo -e "${BLUE}Will run the following commands:${NC}"
233239
for cmd in "${!COMMANDS_TO_RUN[@]}"; do
234240
job_name="${COMMANDS_TO_RUN[$cmd]}"
235-
# Try to get version info for the job
236-
version_info=""
237-
for mapped_job_name in "${!JOB_VERSION_MAP[@]}"; do
238-
if [[ "$job_name" == "$mapped_job_name"* ]]; then
239-
version_info=" (${JOB_VERSION_MAP[$mapped_job_name]})"
240-
break
241-
fi
242-
done
241+
version_info=$(get_version_info "$job_name")
243242
echo -e "${BLUE}$job_name${version_info}:${NC} $cmd"
244243
done
245244
echo ""
@@ -273,14 +272,7 @@ FAILED_COMMANDS=()
273272

274273
for cmd in "${!COMMANDS_TO_RUN[@]}"; do
275274
job_name="${COMMANDS_TO_RUN[$cmd]}"
276-
# Try to get version info for the job
277-
version_info=""
278-
for mapped_job_name in "${!JOB_VERSION_MAP[@]}"; do
279-
if [[ "$job_name" == "$mapped_job_name"* ]]; then
280-
version_info=" (${JOB_VERSION_MAP[$mapped_job_name]})"
281-
break
282-
fi
283-
done
275+
version_info=$(get_version_info "$job_name")
284276

285277
echo -e "${BLUE}▶ Running: $job_name${version_info}${NC}"
286278
echo -e "${BLUE}Command: $cmd${NC}"
@@ -294,7 +286,7 @@ for cmd in "${!COMMANDS_TO_RUN[@]}"; do
294286
else
295287
echo -e "${RED}$job_name${version_info} failed${NC}"
296288
echo ""
297-
FAILED_COMMANDS+=("$job_name$version_info")
289+
FAILED_COMMANDS+=("${job_name}${version_info}")
298290
fi
299291
done
300292

0 commit comments

Comments
 (0)