Skip to content

Commit

Permalink
fix: Check for user-provided build_opts (#71)
Browse files Browse the repository at this point in the history
* fix: Check for user-provided `build_opts`

* chore: Simplify checking for build_opts

* chore: Some style fix

* chore: Further explain how to use `check_build_opts` function
  • Loading branch information
fiftydinar authored Dec 11, 2024
1 parent 0658135 commit b22398a
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions build_opts_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,32 @@ set -euo pipefail
# SQUASH_INPUT_VALUE
# BUILD_OPTS

if [ "$SQUASH_INPUT_VALUE" != "true" ]; then
if grep -qE '(-B)|(--build-driver)' <<< "$BUILD_OPTS"; then
echo 'Cannot provide --build-driver in build_opts while squash is set to true.'
exit 1
fi
# check_build_opts "option1" "option2" "error_message"
# If you have only 1 option to provide, provide '---' string as 2nd placeholder option
# check_build_opts "option1" --- "error_message"
check_build_opts() {
local option1="${1}"
local option2="${2}"
local error_message="${3}"

if grep -qE '(-s)|(--squash)' <<< "$BUILD_OPTS"; then
echo 'Cannot provide --squash in build_opts while squash is set to true.'
exit 1
fi
fi
if [[ "${2}" == "---" ]]; then
if [[ -n "$(awk '/(^|\s)('${option1}')($|\s)/' <<< "${BUILD_OPTS}")" ]]; then
echo "${error_message}"
exit 1
fi
elif [[ -n "${2}" ]]; then
if [[ -n "$(awk '/(^|\s)('${option1}'|'${option2}')($|\s)/' <<< "${BUILD_OPTS}")" ]]; then
echo "${error_message}"
exit 1
fi
fi
}

if grep -qE '(-p)|(--push)' <<< "$BUILD_OPTS"; then
echo 'Please do not add --push to build_opts, as the action already provides that argument.'
exit 1
if [[ "${SQUASH_INPUT_VALUE}" != "true" ]]; then
check_build_opts "-B" "--build-driver" "Cannot provide '--build-driver' in build_opts while 'squash' is set to true."
check_build_opts "-s" "--squash" "Cannot provide '--squash' in build_opts while 'squash' is set to true."
fi

check_build_opts "-p" "--push" "Please do not add '--push' to build_opts, as the action already provides that argument."

exit 0

0 comments on commit b22398a

Please sign in to comment.