-
Notifications
You must be signed in to change notification settings - Fork 0
/
bump_version.sh
executable file
·40 lines (31 loc) · 1014 Bytes
/
bump_version.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
#!/bin/bash
###
# EXIT CODES
# 0 - success
# 1 - parameter error
###
# Sample environment variables
# BUMP_TAG="s/(.*pavics\/canarieapi:).*/\\1NEW_TAG_VALUE/"
# NEW_TAG_VALUE="0.3.6"
# BUMP_FILE="birdhouse/docker-compose.yml"
REQUIRED_ENV_VARS='
BUMP_TAG
NEW_TAG_VALUE
BUMP_FILE
'
# args parsing
for env_var in $REQUIRED_ENV_VARS
do
if [[ ! -v "${env_var}" ]]; then
echo "[ERROR] [$0] Missing ${env_var} environment variable. Exiting."
exit 1
fi
done
PARSED_BUMP_TAG_EXPRESSION=${BUMP_TAG//NEW_TAG_VALUE/$NEW_TAG_VALUE}
# hack, to make sure regex expression is unsanitized
# conditional since calling bump_version.sh directly doesn't require this extra step, since not using JSON string escaping. like in config.test.json
if [[ "$PARSED_BUMP_TAG_EXPRESSION" == *"\\\\"* ]]; then
PARSED_BUMP_TAG_EXPRESSION=$(printf "%b" $PARSED_BUMP_TAG_EXPRESSION)
fi
echo "[INFO] Using expression [$PARSED_BUMP_TAG_EXPRESSION]"
sed -E -i'' $PARSED_BUMP_TAG_EXPRESSION $BUMP_FILE