Skip to content

fix(cr-ci): make deploy scripts compatible with macOS bash 3.2 - #5798

Open
ptone wants to merge 2 commits into
GoogleCloudPlatform:mainfrom
ptone:scion/ci-speed-bash32
Open

ptone wants to merge 2 commits into
GoogleCloudPlatform:mainfrom
ptone:scion/ci-speed-bash32

Conversation

@ptone

@ptone ptone commented Nov 28, 2026

Copy link
Copy Markdown
Member

Part of ptone#9170
Staging PR: ptone#9789

  • Remove bash 4+ constructs (declare -g/-A, local -A, [[ -v ... ]], ${var,,}/${var^^}, mapfile, bash >= 4 gate) across all 10 cr-ci/scripts/*.sh scripts so deploy/ops scripts run on macOS /bin/bash 3.2.
  • Update cr-ci/scripts/README.md and cr-ci/docs/gcp-setup.md to bash >= 3.2.
  • Add static regression test TestScriptsBash32Compatible in cr-ci/scripts/bash32_test.go.
  • Verified on GNU bash 3.2.57 (all cr-ci/scripts and mediator parity tests pass).

@google-cla

google-cla Bot commented Nov 28, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the cr-ci deployment scripts to ensure compatibility with Bash 3.2 (the default on macOS), removing the dependency on Bash 4+. This is achieved by replacing associative arrays with indirect variable expansion helpers and introducing a Go static analysis test to prevent the future introduction of Bash 4+ constructs. The review feedback identifies critical issues with the compatibility implementation: specifically, combining indirect expansion with parameter expansion operators (such as ${!_var+x}) causes a 'bad substitution' runtime error in Bash, which can be resolved using eval. Additionally, a variable shadowing bug in crci_cfg_into was flagged where the local variable _var could conflict with the caller's variable during printf -v operations.

Comment thread cr-ci/scripts/lib.sh
Comment on lines +68 to +72
crci_is_known_key() {
[[ $1 =~ ^[A-Z][A-Z0-9_]*$ ]] || return 1
local _var="CRCI_DEFAULT_$1"
[[ -n ${!_var+x} ]]
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Combining indirect expansion with parameter expansion operators (such as ${!_var+x}) is not supported in Bash and results in a bad substitution runtime error. To check if an indirect variable is set in a way that is compatible with Bash 3.2 and newer, use eval with a standard parameter expansion check.

Suggested change
crci_is_known_key() {
[[ $1 =~ ^[A-Z][A-Z0-9_]*$ ]] || return 1
local _var="CRCI_DEFAULT_$1"
[[ -n ${!_var+x} ]]
}
crci_is_known_key() {
[[ $1 =~ ^[A-Z][A-Z0-9_]*$ ]] || return 1
local _var="CRCI_DEFAULT_$1"
eval "[[ -n \${$_var+x} ]]"
}

Comment thread cr-ci/scripts/lib.sh
Comment on lines +308 to +309
local _seen="CRCI_SEEN_$key"
[[ -n ${!_seen+x} ]] && crci_die "$CRCI_CONFIG:$n: $key is set twice"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Similar to crci_is_known_key, combining indirect expansion with alternative value testing (such as ${!_seen+x}) causes a bad substitution runtime error in Bash. Use eval to safely perform this check in a compatible manner.

Suggested change
local _seen="CRCI_SEEN_$key"
[[ -n ${!_seen+x} ]] && crci_die "$CRCI_CONFIG:$n: $key is set twice"
local _seen="CRCI_SEEN_$key"
eval "[[ -n \${$_seen+x} ]]" && crci_die "$CRCI_CONFIG:$n: $key is set twice"

Comment thread cr-ci/scripts/lib.sh
Comment on lines +59 to +62
crci_cfg_into() {
local _var="CRCI_CFG_$2"
printf -v "$1" '%s' "${!_var}"
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

If a caller passes a variable named _var to crci_cfg_into (e.g., crci_cfg_into _var "KEY"), the local variable _var inside crci_cfg_into will shadow the caller's variable, causing printf -v to write to the local variable instead of the caller's. Renaming the local variable to a highly unique name (like __cfg_var) prevents this shadowing bug.

Suggested change
crci_cfg_into() {
local _var="CRCI_CFG_$2"
printf -v "$1" '%s' "${!_var}"
}
crci_cfg_into() {
local __cfg_var="CRCI_CFG_$2"
printf -v "$1" '%s' "${!__cfg_var}"
}

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant