Skip to content

Instantly share code, notes, and snippets.

@benlmyers
Created July 26, 2021 16:28
Show Gist options
  • Save benlmyers/b761c93ca8cc0afe69e738ef59b6e660 to your computer and use it in GitHub Desktop.
Save benlmyers/b761c93ca8cc0afe69e738ef59b6e660 to your computer and use it in GitHub Desktop.
#!/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"
@benlmyers
Copy link
Author

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 finds info.plist in a simpler way.

This code works with Xcode 12.5.

@benlmyers
Copy link
Author

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