Repository navigation
CI and docs: keep shell scripts bash 3.2 compatible - #286
Merged
Merged
Conversation
Add a macos-latest job that runs /bin/bash -n over every tracked .sh. The Go syntax test runs on Ubuntu, where /bin/bash is bash 5, so it could not catch the 5.45.1 db-pull regression that only 3.2 rejects.
macOS /bin/bash is Apple's 3.2 and Homebrew bash is opt-in, so shipped scripts must parse and run on 3.2. AGENTS.md lists the constructs to avoid and switches the validation step from bash -n to /bin/bash -n, since plain bash is Homebrew's 5.x on a dev Mac. CLAUDE.md carries the same rule; the READMEs note the built-in bash is enough.
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.
Summary
Adds a
bash32-syntaxjob to.github/workflows/go-build.yml. It runs/bin/bash -nover every tracked.shon amacos-latestrunner, where/bin/bashis bash 3.2. That's the same bash wp-ops runs scripts with on macOS.Why
TestShellScriptsParseWithSystemBash(added in 5.45.2) runs in the existingbuildjob onubuntu-latest. There/bin/bashis bash 5, which accepts syntax that 3.2 rejects. So it passes even with a bug like the 5.45.1db-pullregression (case … ;;inside a heredoc inside$( … )), which failed for every macOS user. This job checks with the real 3.2 parser on every PR that touches the workflow's existing paths.Why bash 3.2
/bin/bashis Apple's bash 3.2.57, the last GPLv2 release. Bash moved to GPLv3 with 4.0, and Apple doesn't ship GPLv3 software (anti-tivoization, DRM and patent terms), so bash 4+ will never be the macOS default. macOS's default login shell is zsh, but zsh never runs these scripts; each script runs under the bash its shebang names.brew install bash, and even then a#!/bin/bashscript still gets 3.2. Of the 54 scripts, 29 use#!/bin/bashand 25 use#!/usr/bin/env bash, which gets 3.2 on any Mac without Homebrew bash.depends_on formula: "bash"in the cask) would add a dependency just to allow newer syntax.Documentation
AGENTS.md: a bash 3.2 compatibility rule under Coding Style, listing the constructs to avoid (declare -A,${var,,},mapfile,&>>, negative indexes, heredocs inside$( … )) and theread -r -d ''alternative. The validation steps now use/bin/bash -ninstead ofbash -n, because plainbashis Homebrew's 5.x on a dev Mac, which is how 5.45.1 slipped through. It also explains the two automated guards and what they don't catch.CLAUDE.md: the same rule under Notes for AI Assistants.README.md(Requirements) andscripts/README.md(Prerequisites): the built-in bash 3.2 is enough, and Homebrew bash isn't needed.Notes
${var,,},mapfile) still get through.::error file=…annotations, and the job prints how many scripts it checked.Testing
/bin/bash3.2: 54 scripts checked, exit 0.buildandbash32-syntax.