Created
July 26, 2021 16:28
-
-
Save benlmyers/b761c93ca8cc0afe69e738ef59b6e660 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
git=$(sh /etc/profile; which git) | |
number_of_commits=$("$git" rev-list HEAD --count) | |
git_release_version=$("$git" describe --tags --always --abbrev=0) | |
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $number_of_commits" "$INFOPLIST_FILE" | |
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString ${git_release_version#*v}" "$INFOPLIST_FILE" |
To use: Choose your Target in Xcode, then go to Build Phases. Click the + icon, then add a New Run Script Phase. Paste this code into the text editor, and rename the build phase to something like "Update Build". Finally, in your info.plist
, change Bundle version string (short) to some value like 0 (temporary), as well as Bundle version. Build your project, and these values will update in your info.plist
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script automatically updates an Xcode project's build number to the amount of Git commits and the project's short version string to the latest released tag.
This code is adapted from this article, however for some reason the script from the article couldn't find my
info.plist
. I modified the code so that it findsinfo.plist
in a simpler way.This code works with Xcode 12.5.