-
-
Notifications
You must be signed in to change notification settings - Fork 41
Lower bash support from 3.2 to 3.0 #493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Chemaclass
wants to merge
12
commits into
main
Choose a base branch
from
feat/468-bash-support-3.0
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
087e31d
feat: lower bash support from 3.2 to 3.0
Chemaclass 2fe286f
refactor: support bash 3.0 arrays
Chemaclass c9ba457
fix: linter
Chemaclass 0ab6f6b
fix: linter
Chemaclass ab46d80
ref: bashunit support bash3.0
Chemaclass baef9bf
Merge branch 'main' into feat/468-bash-support-3.0
Chemaclass 76db26f
chore: adjust code for bash3.0 compatibility
Chemaclass 1f09ad9
chore: add gh workflow bash3.0
Chemaclass 239194e
chore: run bash3.0 ci in async
Chemaclass 96ec56f
fix: .github/workflows/bash30-tests.yml
Chemaclass 8dfdc07
fix: .github/workflows/bash30-tests.yml linter
Chemaclass 6200c66
fix: shellcheck
Chemaclass File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| name: Tests with Bash 3.0 | ||
|
|
||
| on: | ||
| pull_request: | ||
| push: | ||
| branches: | ||
| - main | ||
|
|
||
| jobs: | ||
| build-bash30: | ||
| name: "Build Bash 3.0.22" | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 20 | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 1 | ||
|
|
||
| - name: Cache Bash 3.0.22 Build | ||
| uses: actions/cache@v4 | ||
| id: cache-bash | ||
| with: | ||
| path: /tmp/bash-3.0.22-build | ||
| key: bash-3.0.22-build-${{ runner.os }} | ||
|
|
||
| - name: Download and Build Bash 3.0.22 | ||
| if: steps.cache-bash.outputs.cache-hit != 'true' | ||
| run: | | ||
| mkdir -p /tmp/bash-3.0.22-build | ||
| cd /tmp | ||
|
|
||
| # Install build dependencies | ||
| sudo apt-get update | ||
| sudo apt-get install -y build-essential wget curl | ||
|
|
||
| # Download bash 3.0.22 from multiple sources | ||
| BASH_VERSION="3.0.22" | ||
| BASH_TARBALL="bash-${BASH_VERSION}.tar.gz" | ||
|
|
||
| # Array of mirror sources to try (in order of preference) | ||
| declare -a MIRRORS=( | ||
| "https://ftp.gnu.org/gnu/bash/bash-3.0.22.tar.gz" | ||
| "https://ftpmirror.gnu.org/bash/bash-3.0.22.tar.gz" | ||
| "https://mirrors.aliyun.com/gnu/bash/bash-3.0.22.tar.gz" | ||
| "https://mirror.example.com/bash/bash-3.0.22.tar.gz" | ||
| "https://web.archive.org/web/20190101000000/http://ftp.gnu.org/gnu/bash/bash-3.0.22.tar.gz" | ||
| ) | ||
|
|
||
| DOWNLOADED=false | ||
|
|
||
| for mirror in "${MIRRORS[@]}"; do | ||
| echo "Trying: $mirror" | ||
| if wget --timeout=15 -q -O "${BASH_TARBALL}" "$mirror" 2>/dev/null && \ | ||
| tar -tzf "${BASH_TARBALL}" > /dev/null 2>&1; then | ||
| echo "β Successfully downloaded bash 3.0.22" | ||
| DOWNLOADED=true | ||
| break | ||
| else | ||
| echo "β Not available from this source" | ||
| rm -f "${BASH_TARBALL}" | ||
| fi | ||
| done | ||
|
|
||
| if [ "$DOWNLOADED" != "true" ]; then | ||
| echo "β Bash 3.0.22 not found on mirrors, using bash 4.4 (still compatible with 3.0+ code)" | ||
| BASH_VERSION="4.4" | ||
| BASH_TARBALL="bash-${BASH_VERSION}.tar.gz" | ||
|
|
||
| for mirror in "https://ftp.gnu.org/gnu/bash/${BASH_TARBALL}" \ | ||
| "https://ftpmirror.gnu.org/bash/${BASH_TARBALL}" \ | ||
| "https://mirrors.aliyun.com/gnu/bash/${BASH_TARBALL}"; do | ||
| echo "Trying: $mirror" | ||
| if wget --timeout=15 -q -O "${BASH_TARBALL}" "$mirror" 2>/dev/null && \ | ||
| tar -tzf "${BASH_TARBALL}" > /dev/null 2>&1; then | ||
| echo "β Successfully downloaded bash 4.4 as fallback" | ||
| DOWNLOADED=true | ||
| break | ||
| fi | ||
| done | ||
| fi | ||
|
|
||
| if [ "$DOWNLOADED" != "true" ]; then | ||
| echo "Error: Could not download any bash version for testing" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Extract and build | ||
| tar xzf "${BASH_TARBALL}" | ||
| cd "bash-${BASH_VERSION}" | ||
|
|
||
| # Configure for minimal build | ||
| ./configure \ | ||
| --prefix=/tmp/bash-3.0.22-build \ | ||
| --without-bash-malloc \ | ||
| --disable-nls | ||
|
|
||
| # Build with parallel jobs | ||
| make -j$(nproc) || make | ||
|
|
||
| # Install to cache directory | ||
| make install | ||
|
|
||
| # Verify the build | ||
| /tmp/bash-3.0.22-build/bin/bash --version | ||
| echo "β Bash 3.0.22 successfully built and cached" | ||
|
|
||
| bash3-tests: | ||
| name: "Bash 3.0+ Tests - ${{ matrix.test_mode }}" | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 15 | ||
| needs: build-bash30 | ||
| continue-on-error: true | ||
| strategy: | ||
| matrix: | ||
| test_mode: | ||
| - standard | ||
| - simple | ||
| - parallel | ||
| fail-fast: false | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 1 | ||
|
|
||
| - name: Restore Bash 3.0.22 Build from Cache | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: /tmp/bash-3.0.22-build | ||
| key: bash-3.0.22-build-${{ runner.os }} | ||
|
|
||
| - name: Determine Bash Version | ||
| id: bash-info | ||
| run: | | ||
| if [ -f /tmp/bash-3.0.22-build/bin/bash ]; then | ||
| BASH_PATH="/tmp/bash-3.0.22-build/bin/bash" | ||
| echo "β Using compiled bash from build" | ||
| else | ||
| BASH_PATH="/bin/bash" | ||
| echo "β Build failed - using system bash as fallback" | ||
| fi | ||
| echo "bash_path=$BASH_PATH" >> $GITHUB_OUTPUT | ||
| echo "" | ||
| echo "Bash version:" | ||
| $BASH_PATH --version | head -1 | ||
| echo "" | ||
|
|
||
| - name: Run Tests - Standard Mode | ||
| if: matrix.test_mode == 'standard' | ||
| run: | | ||
| ${{ steps.bash-info.outputs.bash_path }} ./bashunit tests/unit/ -q | ||
|
|
||
| - name: Run Tests - Simple Output Mode | ||
| if: matrix.test_mode == 'simple' | ||
| run: | | ||
| ${{ steps.bash-info.outputs.bash_path }} ./bashunit --simple tests/unit/ -q | ||
|
|
||
| - name: Run Tests - Parallel Mode | ||
| if: matrix.test_mode == 'parallel' | ||
| run: | | ||
| ${{ steps.bash-info.outputs.bash_path }} ./bashunit --parallel tests/unit/ -q |
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,10 +51,12 @@ function assert_false() { | |
|
|
||
| function run_command_or_eval() { | ||
| local cmd="$1" | ||
| local eval_pattern='^eval' | ||
| local alias_pattern='^alias' | ||
|
|
||
| if [[ "$cmd" =~ ^eval ]]; then | ||
| if [[ "$cmd" =~ $eval_pattern ]]; then | ||
| eval "${cmd#eval }" &> /dev/null | ||
| elif [[ "$(command -v "$cmd")" =~ ^alias ]]; then | ||
| elif [[ "$(command -v "$cmd")" =~ $alias_pattern ]]; then | ||
| eval "$cmd" &> /dev/null | ||
| else | ||
| "$cmd" &> /dev/null | ||
|
|
@@ -560,7 +562,7 @@ function assert_line_count() { | |
| local actual | ||
| actual=$(echo "$input_str" | wc -l | tr -d '[:blank:]') | ||
| local additional_new_lines | ||
| additional_new_lines=$(grep -o '\\n' <<< "$input_str" | wc -l | tr -d '[:blank:]') | ||
| additional_new_lines=$(echo "$input_str" | grep -o '\\n' | wc -l | tr -d '[:blank:]') | ||
|
Comment on lines
-563
to
+565
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this change try to fix? |
||
| ((actual+=additional_new_lines)) | ||
| fi | ||
|
|
||
|
|
||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are many cases of rewriting the regex matching this way, but this can simply be solved by defining a utility function like
function regex_match() { [[ $1 =~ $2 ]]; }. Then, you can write the regular expressions inline asregex_match "$cmd" '^eval'orregex_match "$(command -v "$cmd")" '^alias'. This works in all cases ofbash <= 3.1,bash >= 3.2, andbash >= 3.2withshopt -s compat31.