Last active
June 13, 2022 16:42
-
-
Save bgreenlee/791817 to your computer and use it in GitHub Desktop.
Automatic project versioning for Xcode using git commits & tags #xcode #git
This file contains 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/sh | |
# Versioning.sh | |
# | |
# https://gist.github.com/791352 by Marc Hedlund | |
# | |
# Found at http://kswizz.com/post/2686511526/git-xcode-versioning and slightly | |
# modified. | |
# To install: | |
# * Copy this script to "Other Sources" or wherever is appropriate in your | |
# project. Make sure it is executable. | |
# * Project -> New Target... -> MaccOS X -> Other -> Shell Script Target | |
# * Name the target "Versioning" or something. | |
# * Open the Versioning target and click on the "Run Script" build phase | |
# and select File -> Get Info | |
# * Leave 'shell' as '/bin/sh' and under 'script' enter: | |
# | |
# $SOURCE_ROOT/Other\ Sources/Versioning.sh | |
# | |
# * Click on another build target, choose Get Info, and in General add | |
# the Versioning target as one of the Direct Dependencies. | |
# * Do the same for any other target where you care about the Git version. | |
# * Modify the final 'touch' command in the script as needed. | |
# * Now go to the Info.plist for your executable. Use "GIT_TAG" and | |
# "GIT_COMMIT" for any field. I use GIT_TAG for "Bundle version" (and make | |
# sure my tags are always #.#.#), and GIT_COMMIT for | |
# "Bundle versions string, short." (These are preprocessor defines, not | |
# shell variables, so don't use "${}" around GIT_TAG or GIT_COMMIT.) | |
# * In the project’s main build settings, turn on "Preprocess Info.plist" | |
# and set "Info.plist Preprocessor Prefix File" to | |
# $PROJECT_TEMP_DIR/revision.prefix. | |
GIT=`which git` | |
cd "$PROJECT_DIR" | |
GIT_TAG=`$GIT describe --tags --abbrev=0` | |
GIT_COMMIT=`$GIT rev-parse --short HEAD` | |
cd "$PROJECT_TEMP_DIR" | |
echo "#define GIT_TAG $GIT_TAG" > revision.prefix | |
echo "#define GIT_COMMIT $GIT_COMMIT" >> revision.prefix | |
echo "Versions found: GIT_TAG = $GIT_TAG; GIT_COMMIT = $GIT_COMMIT" | |
touch "$PROJECT_DIR"/*Info.plist |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment