-
Notifications
You must be signed in to change notification settings - Fork 4
/
build_opts_check.sh
executable file
·36 lines (30 loc) · 1.14 KB
/
build_opts_check.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env bash
set -euo pipefail
# Expected env vars:
# SQUASH_INPUT_VALUE
# BUILD_OPTS
# 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 [[ "${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 [[ "${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