Skip to content

Commit d7bc978

Browse files
committed
fix(compat): ensure Bash 3.0+ compatibility in parallel optimizations
Changes for Bash 3.0+ compliance: - Replace [[ ]] with [ ] test operators in runner.sh - Replace == with = for string comparisons - Add fallback from tar to cp+rm for portability - Fix indentation to pass EditorConfig linting The tar pipe optimization now gracefully falls back to the traditional cp + rm approach on systems without tar or with limited tar support, ensuring maximum portability while maintaining performance gains on systems with modern tar implementations.
1 parent 76b3a50 commit d7bc978

5 files changed

Lines changed: 21 additions & 18 deletions

File tree

release.sh

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -375,15 +375,21 @@ function release::sandbox::create() {
375375
release::log_info "Creating sandbox at: $SANDBOX_DIR"
376376

377377
# Copy repo content excluding .git, .release-state, node_modules
378-
# Use tar pipe for faster copying and built-in exclusions
379-
tar --exclude='.git' \
380-
--exclude='.release-state' \
381-
--exclude='node_modules' \
382-
--exclude='.tasks' \
383-
--exclude='tmp' \
384-
-cf - . | tar -xf - -C "$SANDBOX_DIR"
385-
386-
release::log_verbose "Copied project files to sandbox"
378+
# Try tar pipe first (faster), fallback to cp + rm for portability
379+
if tar --exclude='.git' \
380+
--exclude='.release-state' \
381+
--exclude='node_modules' \
382+
--exclude='.tasks' \
383+
--exclude='tmp' \
384+
-cf - . 2>/dev/null | tar -xf - -C "$SANDBOX_DIR" 2>/dev/null; then
385+
release::log_verbose "Copied project files to sandbox (tar)"
386+
else
387+
# Fallback: traditional cp + rm for maximum portability
388+
cp -r . "$SANDBOX_DIR/"
389+
rm -rf "$SANDBOX_DIR/.git" "$SANDBOX_DIR/.release-state" \
390+
"$SANDBOX_DIR/node_modules" "$SANDBOX_DIR/.tasks" "$SANDBOX_DIR/tmp"
391+
release::log_verbose "Copied project files to sandbox (cp)"
392+
fi
387393
}
388394

389395
function release::sandbox::setup_git() {

src/runner.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,8 @@ function bashunit::runner::call_test_functions() {
368368
done <<<"$(bashunit::helper::get_provider_data "$fn_name" "$script")"
369369

370370
# No data provider found
371-
if [[ "$provider_data_count" -eq 0 ]]; then
372-
if bashunit::parallel::is_enabled && [[ "$allow_test_parallel" == true ]]; then
371+
if [ "$provider_data_count" -eq 0 ]; then
372+
if bashunit::parallel::is_enabled && [ "$allow_test_parallel" = true ]; then
373373
bashunit::runner::run_test "$script" "$fn_name" &
374374
else
375375
bashunit::runner::run_test "$script" "$fn_name"
@@ -385,11 +385,11 @@ function bashunit::runner::call_test_functions() {
385385
parsed_data_count=0
386386
local line
387387
while IFS= read -r line; do
388-
[[ -z "$line" ]] && continue
388+
[ -z "$line" ] && continue
389389
parsed_data[parsed_data_count]="$(bashunit::helper::decode_base64 "${line}")"
390390
parsed_data_count=$((parsed_data_count + 1))
391391
done <<<"$(bashunit::runner::parse_data_provider_args "$data")"
392-
if bashunit::parallel::is_enabled && [[ "$allow_test_parallel" == true ]]; then
392+
if bashunit::parallel::is_enabled && [ "$allow_test_parallel" = true ]; then
393393
bashunit::runner::run_test "$script" "$fn_name" ${parsed_data+"${parsed_data[@]}"} &
394394
else
395395
bashunit::runner::run_test "$script" "$fn_name" ${parsed_data+"${parsed_data[@]}"}
@@ -399,7 +399,7 @@ function bashunit::runner::call_test_functions() {
399399
done
400400

401401
# Wait for all parallel tests within this file to complete
402-
if bashunit::parallel::is_enabled && [[ "$allow_test_parallel" == true ]]; then
402+
if bashunit::parallel::is_enabled && [ "$allow_test_parallel" = true ]; then
403403
wait
404404
fi
405405
}

tests/unit/release_sandbox_test.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ if [[ "${BASH_VERSINFO[0]}" -eq 3 ]] && [[ "${BASH_VERSINFO[1]}" -lt 1 ]]; then
88
fi
99

1010
RELEASE_SCRIPT_DIR=""
11-
FIXTURES_DIR=""
1211

1312
function set_up_before_script() {
1413
RELEASE_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
15-
FIXTURES_DIR="$(dirname "${BASH_SOURCE[0]}")/fixtures/release"
1614

1715
# Source release.sh to get access to functions
1816
# shellcheck source=/dev/null

tests/unit/release_update_test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ function test_dry_run_logs_what_would_happen() {
243243
cd "$temp_dir" || return
244244
release::update_bashunit_version "0.31.0" 2>&1
245245
)
246+
# shellcheck disable=SC2034
246247
DRY_RUN=false
247248

248249
assert_contains "DRY-RUN" "$output"

tests/unit/release_validation_test.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ if [[ "${BASH_VERSINFO[0]}" -eq 3 ]] && [[ "${BASH_VERSINFO[1]}" -lt 1 ]]; then
88
fi
99

1010
RELEASE_SCRIPT_DIR=""
11-
FIXTURES_DIR=""
1211

1312
function set_up_before_script() {
1413
RELEASE_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
15-
FIXTURES_DIR="$(dirname "${BASH_SOURCE[0]}")/fixtures/release"
1614

1715
# Source release.sh to get access to functions
1816
# shellcheck source=/dev/null

0 commit comments

Comments
 (0)