Skip to content

Instantly share code, notes, and snippets.

@tadija
Last active August 11, 2022 19:55
Show Gist options
  • Save tadija/7247e57e89187c0e9c1d to your computer and use it in GitHub Desktop.
Save tadija/7247e57e89187c0e9c1d to your computer and use it in GitHub Desktop.
Xcode Semi-Automatic Versioning | Bump Build Number | Bump Version Number

Xcode Semi-Automatic Versioning

Instructions:

First Things First

In order for agvtool to work properly you must first set
Project Settings / Build Settings / Versioning / Versioning System to Apple Generic.

Bump Build Number

  1. Create new shared scheme 'Bump Build Number'
  2. Add Build / Pre-Actions / Run Script action
  3. Paste code from given bump-build.sh script

Now, each time project is built with Bump Build Number scheme, build number will increase for all targets.
Also, automatically generated commit message will wait ready inside clipboard.

Bump Version Number

  1. Create new shared scheme 'Bump Version Number'
  2. Add Build / Pre-Actions / Run Script action
  3. Paste code from given bump-version.sh script

Now, each time project is built with Bump Version Number scheme, version number will be set to one from the script (change it there manually when needed) and build number will be reset to 1 - for all targets.

PROJECT_DIRECTORY=$(dirname "${WORKSPACE_PATH}")
cd $PROJECT_DIRECTORY
OLD_VERSION=$(agvtool what-marketing-version -terse1)
OLD_BUILD=$(agvtool what-version -terse)
OLD_BUILD_NUMBER="${OLD_BUILD##*.}"
NEW_BUILD_NUMBER="$(($OLD_BUILD_NUMBER+1))"
agvtool new-version -all "${OLD_VERSION//./}.$NEW_BUILD_NUMBER"
NEW_BUILD=$(agvtool what-version -terse)
COMMIT_MESSAGE="Bumped build from $OLD_BUILD to $NEW_BUILD [Version: $OLD_VERSION Build: $NEW_BUILD]"
echo $COMMIT_MESSAGE | pbcopy
PROJECT_DIRECTORY=$(dirname "${WORKSPACE_PATH}")
cd $PROJECT_DIRECTORY
OLD_VERSION=$(agvtool what-marketing-version -terse1)
agvtool new-marketing-version "2.1.8"
NEW_VERSION=$(agvtool what-marketing-version -terse1)
agvtool new-version -all "${NEW_VERSION//./}.1"
NEW_BUILD=$(agvtool what-version -terse)
COMMIT_MESSAGE="Bumped version from $OLD_VERSION to $NEW_VERSION [Version: $NEW_VERSION Build: $NEW_BUILD]"
echo $COMMIT_MESSAGE | pbcopy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment