forked from apter-tech/junit5-robolectric-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bumpVersion.sh
executable file
·32 lines (29 loc) · 1.11 KB
/
bumpVersion.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
#!/usr/bin/env bash
function incrementVersion() {
local version="$1"
if [ -z "$2" ]; then
local rgx='^((?:[0-9]+\.)*)([0-9]+)($)'
else
local rgx='^((?:[0-9]+\.){'$(($2-1))'})([0-9]+)(\.|$)'
for (( p=$(grep -o "\."<<<".$version"|wc -l); p<$2; p++)); do
version+=.0
done;
fi
local -r val=$(echo -e "$version" | perl -pe 's/^.*'$rgx'.*$/$2/')
echo "$version" | perl -pe s/$rgx.*$'/${1}'$(printf "%0${#val}s" $((val+1)))/
}
function bumpVersion() {
local -r baseDir=$(dirname "$0")
local -r propertiesFile="${baseDir}/gradle.properties"
local -r currentVersion=$(cat < "$propertiesFile" | grep tech.apter.junit5.robolectric.extension.version | cut -d'=' -f2)
if [[ "$1" == "" ]]; then
local -r versionSuffix="-SNAPSHOT"
local -r newVersion=$(incrementVersion "$(echo "$currentVersion" | cut -d'-' -f1)")"$versionSuffix"
else
local -r newVersion="$1"
fi
sed -i'.bak' "s/^tech\.apter\.junit5\.robolectric\.extension\.version=.*/tech.apter.junit5.robolectric.extension.version=${newVersion}/" "$propertiesFile"
rm -rf "${propertiesFile}.bak"
echo "$newVersion"
}
bumpVersion "$@"