-
Notifications
You must be signed in to change notification settings - Fork 83
/
tag_release.sh
executable file
·72 lines (55 loc) · 1.53 KB
/
tag_release.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
set -e
# ----- Help
help_message() {
cat <<- _EOF_
Bump versionCode and versionName
Usage: $SCRIPT_NAME versionName [-h|--help]
Options:
-h, --help Display this help message and exit
_EOF_
exit 0
}
# ----- Vars
GRADLE_BUILD_FILE='green/build.gradle.kts'
# --- Argument handling
# https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-h | --help)
help_message ;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]:-}" # restore positional parameters
if [ -n "${1:-}" ]
then
VERSION_NAME=${1}
else
printf "You have to provide the VersionName eg. 1.3.5\n"
exit 1
fi
# Pre-requisites
function check_command() {
command -v $1 >/dev/null 2>&1 || { echo >&2 "$1 not found, exiting."; exit 1; }
}
# --- Check
check_command curl
check_command sed
# --- Execution
printf "\nUpdating versionCode & VersionName...\n\n"
currentVersionCode=`awk '/ versionCode = / {print $3}' $GRADLE_BUILD_FILE`
newVersionCode=$(($currentVersionCode + 1))
sed -i '' -e "s/versionCode = .*/versionCode = ${newVersionCode}/" $GRADLE_BUILD_FILE`
sed -i '' -e "s/versionName = .*/versionName = \"${VERSION_NAME}\"/" $GRADLE_BUILD_FILE`
printf "* versionCode: \t${newVersionCode}\n"
printf "* versionName: \t${VERSION_NAME}\n"
printf "\nCreating git commit...\n"
git add $GRADLE_BUILD_FILE
git commit -m "Increment to version ${VERSION_NAME}"