diff --git a/build_opts_check.sh b/build_opts_check.sh index 4e35767..098b8a0 100755 --- a/build_opts_check.sh +++ b/build_opts_check.sh @@ -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