Skip to content

Commit

Permalink
bundle-script.sh: Add --exit parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
theCalcaholic committed Aug 16, 2021
1 parent 00b9618 commit 3f338c3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
bundle_dir="$(mktemp -d)"
for script in ./*.sh; do
bash ./bundle-script.sh --gzip --check '--help' "$script" "$bundle_dir/$script" ./lib/parse_args.sh \
|| bash ./bundle-script.sh --gzip --check '--help' "$script" "$bundle_dir/$script" ./lib/parse_args_v2.sh || exit 1
|| bash ./bundle-script.sh --gzip --check '--help' --exit 50 "$script" "$bundle_dir/$script" ./lib/parse_args_v2.sh || exit 1
assets+=("-a" "$bundle_dir/$script")
done
tag_name="${GITHUB_REF##*/}"
Expand Down
16 changes: 11 additions & 5 deletions bundle-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ USAGE="bundle-script.sh [OPTIONS] input output [dependency [dependency [...]]]
Options:
--check, -c If provided, the bundled script will be called with the given arguments to
check if it works (i.e. returns with exit code 0).
--gzip, -z Use additional gzip compression for bundled scripts"
--gzip, -z Use additional gzip compression for bundled scripts
--exit, -e The expected exit code if the script is working (requires --check)"

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

Expand Down Expand Up @@ -82,10 +83,15 @@ done < "$input_script"
check_args="${KW_ARGS['--check']-${KW_ARGS['-c']}}"
if [[ -n "$check_args" ]]
then
bash "$output_script" $check_args || true
bash "$output_script" $check_args > /dev/null 2>&1 || {
rc=0
expected="${KW_ARGS['-e']:-0}"
expected="${KW_ARGS['--exit']-$expected}"

bash "$output_script" $check_args > /dev/null 2>&1 || rc=$?
if [[ $rc -ne $expected ]]
then
echo "ERROR: The bundled script doesn't seem to work ('bash \"$output_script\" $check_args' terminated with exit code $?)!" >&2
exit 2
}
fi
fi

0 comments on commit 3f338c3

Please sign in to comment.