Skip to content

Commit 73fb860

Browse files
committed
fix(runner): stabilize --log-gha tests under parallel strict mode
- Optimize GHA message encoder: drop awk+sed pipeline, use Bash 3.0+ parameter expansion `${var//pat/repl}` for percent-encoding. - Acceptance tests: tolerate nonzero exit from inner bashunit run so `set -e` from --strict does not abort before assertions, and use a mktemp path to avoid filename collisions.
1 parent b07ae02 commit 73fb860

2 files changed

Lines changed: 20 additions & 13 deletions

File tree

src/reports.sh

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,15 @@ function bashunit::reports::generate_junit_xml() {
120120

121121
function bashunit::reports::__gha_encode() {
122122
local text="$1"
123-
# Strip ANSI escape sequences, then percent-encode reserved chars
124-
# (see GitHub Actions workflow-commands docs: %25, %0A, %0D)
125-
echo "$text" \
126-
| sed -e 's/\x1b\[[0-9;]*[a-zA-Z]//g' \
127-
| awk 'BEGIN{ORS=""} {gsub(/%/,"%25"); gsub(/\r/,"%0D"); print; if (NR>0) print "%0A"}' \
128-
| sed -e 's/%0A$//'
123+
# Strip ANSI escape sequences first (one sed call)
124+
text=$(printf '%s' "$text" | sed -e 's/\x1b\[[0-9;]*[a-zA-Z]//g')
125+
# Percent-encode reserved chars per GHA workflow-commands spec.
126+
# Bash 3.0+ parameter expansion avoids extra awk/sed calls.
127+
# Order matters: encode '%' first so the sequences we inject stay literal.
128+
text="${text//%/%25}"
129+
text="${text//$'\r'/%0D}"
130+
text="${text//$'\n'/%0A}"
131+
printf '%s' "$text"
129132
}
130133

131134
function bashunit::reports::generate_gha_log() {

tests/acceptance/bashunit_log_gha_test.sh

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,25 @@ function set_up_before_script() {
77

88
function test_bashunit_when_log_gha_option() {
99
local test_file=./tests/acceptance/fixtures/test_bashunit_when_log_junit.sh
10+
local log_file
11+
log_file=$(mktemp "${TMPDIR:-/tmp}/bashunit-gha-opt.XXXXXX")
1012

11-
./bashunit --no-parallel --env "$TEST_ENV_FILE" --log-gha custom.log "$test_file" >/dev/null
13+
# Inner suite has a failing test, so bashunit exits nonzero; tolerate it
14+
# so the acceptance test keeps running under --strict (set -e).
15+
./bashunit --no-parallel --env "$TEST_ENV_FILE" --log-gha "$log_file" "$test_file" >/dev/null || true
1216

13-
assert_file_exists custom.log
14-
assert_contains "::error file=$test_file" "$(cat custom.log)"
15-
assert_contains "title=Failure" "$(cat custom.log)"
16-
rm custom.log
17+
assert_file_exists "$log_file"
18+
assert_contains "::error file=$test_file" "$(cat "$log_file")"
19+
assert_contains "title=Failure" "$(cat "$log_file")"
20+
rm -f "$log_file"
1721
}
1822

1923
function test_bashunit_when_log_gha_env() {
2024
local test_file=./tests/acceptance/fixtures/test_bashunit_when_log_junit.sh
2125

22-
./bashunit --no-parallel --env "$TEST_ENV_FILE_BASHUNIT_LOG_GHA" "$test_file" >/dev/null
26+
./bashunit --no-parallel --env "$TEST_ENV_FILE_BASHUNIT_LOG_GHA" "$test_file" >/dev/null || true
2327

2428
assert_file_exists log-gha.txt
2529
assert_contains "::error" "$(cat log-gha.txt)"
26-
rm log-gha.txt
30+
rm -f log-gha.txt
2731
}

0 commit comments

Comments
 (0)