Skip to content

Instantly share code, notes, and snippets.

@julien1619
Forked from rob-murray/set_agv_ver.sh
Last active August 28, 2015 08:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julien1619/5672496ec97c13626c05 to your computer and use it in GitHub Desktop.
Save julien1619/5672496ec97c13626c05 to your computer and use it in GitHub Desktop.
Use agvtool to set Xcode project build number
#!/bin/bash
#
# Use agvtool to set Xcode project version number, bump build number and create git tag
# Note: requires Xcode project configured to use Apple Generic Versioning and git
#
# Usage: set_agv_ver.sh 1.1.0
#
# src: https://gist.github.com/julien1619/5672496ec97c13626c05
# forked from: https://gist.github.com/rob-murray/8644974
#
NOTE="'set_agv_ver.sh' will set version number of Xcode project"
# just increment the version
function bump_build_version() {
# bump the version number
$(agvtool next-version -all &> /dev/null)
}
# set Xcode project to version passed as argument
function set_marketing_version() {
local _version="$1"
if [[ -z "$_version" ]]
then
echo "Marketing version is empty."
exit
fi
# bump the version number
$(agvtool new-marketing-version $_version &> /dev/null)
}
function getAgvMarketingVersion() {
agvtool what-marketing-version -terse1
}
function getAgvBuildVersion() {
agvtool what-version -terse
}
# function git_tag(label, message)
function git_tag() {
local _label="$1"
local _message="$2"
if [[ -z "$_label" ]]
then
echo "Param label is empty."
exit
fi
if [[ -z $_message ]]
then
echo "Param message is empty."
exit
fi
git tag -a $_label -m "$_message"
git push --tags
}
# entry
if [ $# -lt 1 ]
then
echo "Usage: $0 version_id"
exit
fi
VERSION="$1"
echo "$NOTE"
set_marketing_version $VERSION
bump_build_version
# grab the marketing and build versions
marketing_version=`getAgvMarketingVersion`
build_version=`getAgvBuildVersion`
# will tag in this format; e.g. {marketing_version}.{build_version} 2.1.4.68
version_id="$marketing_version.$build_version"
# commit changes and tag
git_tag $version_id "Version $marketing_version - build $build_version"
echo "Set Xcode project to marketing version $marketing_version, build version $build_version and tagged with label $version_id"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment