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

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