Skip to content

Instantly share code, notes, and snippets.

@adsahay
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save adsahay/2134535119d842d67ed0 to your computer and use it in GitHub Desktop.

Select an option

Save adsahay/2134535119d842d67ed0 to your computer and use it in GitHub Desktop.
Cordova/Phonegap - bump version in config.xml as a pre-commit hook
!/bin/sh
# post-commit hook that updates version using semver.
# this one stores versions in the form 1.0.abc123 where the last component is the (short) commit
SEMVER=`which semver`
CONFIG='config.xml'
if [ -s $SEMVER ]; then
# replace last part of the version by commit id.
commit_head=`git rev-parse --short HEAD`
semver special $commit_head
new_version=`semver tag`
if [ -e $CONFIG ]; then
# sed to replace version in config.xml
sed -i '' -e"s/\(widget.*version=\"[0-9]\.[0-9]\.\)[^\"]*\"/\1$commit_head\"/" config.xml
git add $CONFIG
echo "Updated $CONFIG with version $new_version"
exit 0
else
echo 'Could not find config.xml'
exit 1
fi
else
echo "semver is not installed, could not update version"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment