Skip to content

Commit 3f338c3

Browse files
committed
bundle-script.sh: Add --exit parameter
1 parent 00b9618 commit 3f338c3

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
bundle_dir="$(mktemp -d)"
1717
for script in ./*.sh; do
1818
bash ./bundle-script.sh --gzip --check '--help' "$script" "$bundle_dir/$script" ./lib/parse_args.sh \
19-
|| bash ./bundle-script.sh --gzip --check '--help' "$script" "$bundle_dir/$script" ./lib/parse_args_v2.sh || exit 1
19+
|| bash ./bundle-script.sh --gzip --check '--help' --exit 50 "$script" "$bundle_dir/$script" ./lib/parse_args_v2.sh || exit 1
2020
assets+=("-a" "$bundle_dir/$script")
2121
done
2222
tag_name="${GITHUB_REF##*/}"

bundle-script.sh

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ USAGE="bundle-script.sh [OPTIONS] input output [dependency [dependency [...]]]
1111
Options:
1212
--check, -c If provided, the bundled script will be called with the given arguments to
1313
check if it works (i.e. returns with exit code 0).
14-
--gzip, -z Use additional gzip compression for bundled scripts"
14+
--gzip, -z Use additional gzip compression for bundled scripts
15+
--exit, -e The expected exit code if the script is working (requires --check)"
1516

1617
. "$(dirname "$BASH_SOURCE")/lib/parse_args.sh"
1718
REQUIRED=("input" "output")
18-
KEYWORDS=("--check" "-c" "--gzip;bool" "-z;bool")
19+
KEYWORDS=("--check" "-c" "--exit" "-e" "--gzip;bool" "-z;bool")
1920
set_trap 1
2021
parse_args __USAGE "$USAGE" __DESCRIPTION "$DESCRIPTION" "$@"
2122

@@ -82,10 +83,15 @@ done < "$input_script"
8283
check_args="${KW_ARGS['--check']-${KW_ARGS['-c']}}"
8384
if [[ -n "$check_args" ]]
8485
then
85-
bash "$output_script" $check_args || true
86-
bash "$output_script" $check_args > /dev/null 2>&1 || {
86+
rc=0
87+
expected="${KW_ARGS['-e']:-0}"
88+
expected="${KW_ARGS['--exit']-$expected}"
89+
90+
bash "$output_script" $check_args > /dev/null 2>&1 || rc=$?
91+
if [[ $rc -ne $expected ]]
92+
then
8793
echo "ERROR: The bundled script doesn't seem to work ('bash \"$output_script\" $check_args' terminated with exit code $?)!" >&2
8894
exit 2
89-
}
95+
fi
9096
fi
9197

0 commit comments

Comments
 (0)