update_android_version.sh 854 Bytes
Newer Older
Lorenz Meier's avatar
Lorenz Meier committed
1
#!/usr/bin/env bash
2

Daniel Agar's avatar
Daniel Agar committed
3
# this requires `origin/master` in the git tree
4

5 6
MANIFEST_FILE=android/AndroidManifest.xml

Daniel Agar's avatar
Daniel Agar committed
7
VERSIONCODE=`git rev-list origin/master --first-parent --count`
8 9
VERSIONNAME=`git describe --always --tags | sed -e 's/^v//'`

10 11 12 13 14
# increment the versionCode past master for tagged releases
if [ "${TRAVIS_TAG}" ]; then
	let VERSIONCODE=${VERSIONCODE}+1
fi

15 16
if [ -n "$VERSIONCODE" ]; then
	sed -i -e "s/android:versionCode=\"[0-9][0-9]*\"/android:versionCode=\"$VERSIONCODE\"/" $MANIFEST_FILE
Lorenz Meier's avatar
Lorenz Meier committed
17
	echo "Android version: ${VERSIONCODE}"
18 19
else
	echo "Error versionCode empty"
20
	exit 0 # don't cause the build to fail
21 22 23 24
fi

if [ -n "$VERSIONNAME" ]; then
	sed -i -e 's/versionName *= *"[^"]*"/versionName="'$VERSIONNAME'"/' $MANIFEST_FILE
Lorenz Meier's avatar
Lorenz Meier committed
25
	echo "Android name: ${VERSIONNAME}"
26 27
else
	echo "Error versionName empty"
28
	exit 0 # don't cause the build to fail
29
fi