Repository navigation
fix(scripts): make deploy.sh exit on failure and honor no and skip answers - #303
Merged
aghassemlouei merged 3 commits intoOct 20, 2026
Merged
Conversation
…s.sh Move error_handler, handle_prompt, and handle_prompt_if from deploy.sh into common-functions.sh with unchanged bodies, so the shell unit tests can source and exercise them. This commit does not change behavior.
…swers - error_handler read $? after another command reset it, so deploy.sh exited 0 on every failure. The trap now passes $? and the handler captures the status before running anything else. - A missing config.env on the first run fired the ERR trap before the interactive config builder ran. load_config failures now log a warning. - When the operator declines the prerequisites setup, deploy.sh now stops if config.env is missing or lacks required values, instead of entering Stage 0 with empty values. - Answering "n" to the second bootstrap apply, the default project, and the providers download prompts fired the ERR trap. These calls now end in "|| true". - "s" took the yes branch of the old file cleanup, config.env overwrite, and providers.tf generation prompts. These use handle_prompt_if now. - Overwriting config.env skipped every prompt because the values were already sourced. Each prompt now shows the current value as a default. - The prefix prompt allowed 6 characters while the 0-bootstrap prefix validation allows 7, and the generated tfvars comment said 9. - setup_error_handling now installs the shared error_handler instead of defining a second handler with the same name. The new prompt_with_default helper lives in common-functions.sh. The shell unit tests cover the helpers and check the deploy.sh call sites.
15 of 26 tasks
aghassemlouei
approved these changes
Oct 20, 2026
aghassemlouei
left a comment
Member
There was a problem hiding this comment.
Verified that capturing $? before local variable declarations in error_handler preserves the failing exit status, handle_prompt_if prevents skip answers from entering yes branches, prompt_with_default re-prompts existing values when overwriting config.env, and all 49 shell unit tests pass.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The
scripts/deploy.shscript now exits with the failing command's status. It reaches the interactive config builder on the first run, and it treats "no" and "skip" answers as declines.error_handlerfunction read$?afterlocal line_no=$1reset it, so every failure exited with status 0. The ERR trap now passes$?, and the handler captures the status before it runs anything else.config.envfile on the first run madeload_configfire the ERR trap before the config builder ran. The script now logs a warning and continues to the prerequisites step that writes the file.config.envfile is missing or lacks required values. Before this change, a missing or incomplete file also stopped the run, but with status 0.|| truelike the other optional prompts.config.envoverwrite andproviders.tfgeneration prompts did the same. These prompts now callhandle_prompt_if, which takes the yes branch only for "y".config.envskipped every question because the sourced values satisfied eachwhile [[ -z ]]loop. Each question now runs once and shows the current value as a default that Enter keeps.prefixvalidation in thefast/stages-aw/0-bootstrap/variables.tffile and the Detailed Deployment Guide in thedocs/ddg.mdfile. The generatedterraform.tfvarscomment now says 7 instead of 9.scripts/README.mdfile now lists3-securityinstead of3-project-factoryas the last stage.The first commit moves
error_handler,handle_prompt, andhandle_prompt_iffrom thescripts/deploy.shscript into thescripts/common-functions.shlibrary with unchanged bodies. The move exists only so the new shell unit tests can source the helpers. It stays in its own commit sogit bisectseparates it from the fixes.The fix commit also makes these changes to the shared library.
prompt_with_defaulthelper serves the config builder.error_handlerkeeps writingLAST_FAILED_OPERATION=deployby default, and anOPERATION_NAMEvariable overrides it.SCRIPT_DIRis unset and ignores a failed state directory creation.setup_error_handlingfunction now installs the shared handler and keeps its cleanup function argument. It no longer defines a seconderror_handlerwith the same name. No script calls it today.The
scripts/destroy.shscript keeps its own copy oferror_handler, and that copy has the same$?defect. This PR leaves that script unchanged to keep the scope ondeploy.sh. A follow-up can switch it to the shared handler.Open PR #299 renames the
tests/scripts/test_common_functions.shsuite totests/test_common_functions.sh. Whichever PR merges second needs to carry the new test cases across that rename. Open PR #286 changes neither thescripts/directory nor thetests/directory, so it does not conflict.No tracking issue exists for these defects.
Type of Change
Deployment & Compliance Impact
Checklist
Code Quality & Reusability
modules/orfast/stages-aw/can be leveraged for this change.docs/naming-convention.md.Documentation
README.mdof the modified module or blueprint.Security
Testing
The inputs and outputs item stays unchecked because no Terraform variables or outputs change.
Testing Performed
bash tools/run_tests.shpasses. The Python unit tests, the shell suites, and the Python compile check all pass.bash tests/scripts/run_shell_tests.shpasses all 49 unit tests, including 30 new tests.error_handlertests check the exit status with and without the explicit$?argument, the state file record, and the cleanup call.setup_error_handlingtests check that it installs the shared handler and runs the named cleanup function.handle_prompt_if, and that theNON_INTERACTIVEdefaults stay unchanged.prompt_with_defaulttests check the default value, typed input, a final line without a newline, and a closed stdin.scripts/deploy.shassert that no yes branch callshandle_prompt, that every barehandle_promptcall ends in|| true, and that the ERR trap passes$?.mainpasses with 19 of 19 tests.error_handlerscenario exits 0 with the handler frommainand 7 with the fixed handler.handle_prompt_ifcall site, one|| truesuffix, or the trap argument inscripts/deploy.shfails the matching static check.scripts/deploy.shuse stubgcloudandterraformcommands onPATH, scripted answers, and placeholder values such asuser@example.com.config.envreaches the builder, rejects an 8-character prefix, accepts a 7-character prefix, and writes the file. The same run onmainstops atload_config, reports exit code 0, and writes no file.config.envbyte-identical.mainexits 0 at the same prompt.config.env, or with aconfig.envthat lacks required values, exits 1 before Stage 0.bash -npasses for every script in thescripts/directory.shellcheck -S warningreports the same warnings per file asmainfor the three changed shell files.pytest -qpasses all 66 tests.python3 tools/check_boilerplate.py scripts tests toolsreports the missing license header inscripts/deploy.shandscripts/destroy.sh. Both files lack the header onmaintoo, and this PR adds no new files.