Skip to content

Commit be5cb78

Browse files
committed
Update build script to update version numbers on the fly
1 parent 9781e7c commit be5cb78

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

travis-build.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,56 @@ EOL
1414
chmod 600 $HOME/.netrc
1515
}
1616

17+
getVersion() {
18+
gradle properties -q | grep "version:" | grep -v "kotlin_version:" | awk '{print $2}' | tr -d '[:space:]'
19+
}
20+
21+
removeSnapshots() {
22+
sed -i 's/-SNAPSHOT//' gradle.properties
23+
}
24+
25+
commitRelease() {
26+
local APP_VERSION=$(getVersion)
27+
git commit -a -m "Update version for release"
28+
git tag -a "v${APP_VERSION}" -m "Tag release version"
29+
}
30+
31+
bumpVersion() {
32+
echo "Bump version number"
33+
local APP_VERSION=$(getVersion | xargs)
34+
local SEMANTIC_REGEX='^([0-9]+)\.([0-9]+)(\.([0-9]+))?$'
35+
if [[ ${APP_VERSION} =~ ${SEMANTIC_REGEX} ]]; then
36+
if [[ ${BASH_REMATCH[4]} ]]; then
37+
nextVersion=$((BASH_REMATCH[4] + 1))
38+
nextVersion="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${nextVersion}-SNAPSHOT"
39+
else
40+
nextVersion=$((BASH_REMATCH[2] + 1))
41+
nextVersion="${BASH_REMATCH[1]}.${nextVersion}-SNAPSHOT"
42+
fi
43+
44+
echo "Next version: ${nextVersion}"
45+
sed -i -E "s/^version(\s)?=.*/version=${nextVersion}/" gradle.properties
46+
else
47+
echo "No semantic version and therefore cannot publish to maven repository: '${APP_VERSION}'"
48+
fi
49+
}
50+
51+
commitNextVersion() {
52+
git commit -a -m "Update version for release"
53+
}
54+
1755
if [ "${TRAVIS_PULL_REQUEST}" = "false" ] && [ "${TRAVIS_BRANCH}" = "master" ]; then
1856
if [ "${RELEASE}" = "true" ]; then
1957
echo "Deploying release to Bintray"
2058
saveGitCredentials
59+
removeSnapshots
60+
2161
./gradlew clean assemble && ./gradlew check --info && ./gradlew bintrayUpload -x check --info
62+
63+
commitRelease
64+
bumpVersion
65+
commitNextVersion
66+
git push --follow-tags
2267
else
2368
echo "Deploying snapshot"
2469
saveGitCredentials

0 commit comments

Comments
 (0)