-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
docker-entrypoint.sh
51 lines (46 loc) · 1.52 KB
/
docker-entrypoint.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env bash
# Parameters are normalized to ensure Dockerfile can be called using:
# 1. Double quoted parameter value chains
# E.g. "--parameter value" "--parameter2 value"
# Designed for GitHub actions as action.yml args is sent this way.
# Parameter value chains are parsed to send in unquoted format
# 2. Parameter value chain
# This is the normal usage, parameters are sent through as they are
# E.g. --parameter value --parameter2 value
# See ./tests/docker-entrypoint for testing it locally
main() {
parameters=()
for part in "$@"
do
if is_parameter_name_and_value_in_same_arg "$part"; then # Called by GitHub actions
name=${part%% *} # Before first whitespace
value=${part#* } # After first whitespace
parameters+=("$name" "$value")
else # Not by GitHub actions, send the parameters as they are
parameters+=("$part")
fi
done
echo "[docker-entrypoint.sh] Parameters:" "${parameters[@]}"
local -r current_directory=$(dirname "$0")
bash "$current_directory"/scripts/bump-everywhere.sh "${parameters[@]}"
}
is_parameter_name_and_value_in_same_arg() {
local -r value="$1"
if starts_with "$value" '--' && \
includes "$value" ' '; then
return 0
else
return 1
fi
}
starts_with() {
local -r value="$1"
local -r prefix="$2"
[[ $value = $prefix* ]]
}
includes() {
local -r value="$1"
local -r pattern="$2"
[[ $value =~ $pattern ]]
}
main "$@"