Last active
August 18, 2017 16:28
-
-
Save timshadel/07eb324520c66fcd6ef04429dfd8ad4e to your computer and use it in GitHub Desktop.
iOS automatic version script
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 | |
### | |
# Version: $Major.$Minor.$Commit | |
# | |
# How it works: | |
# 1. To roll minor number, tag each App Store release with a message. | |
# 2. To roll major number, create an additional tag on the last App Store | |
# release (e.g. "2.17.9") with new major number (e.g. "3"). | |
# 3. `Release` builds require a clean working directory. | |
# 4. Non-`Release` builds have a commit number of '0'. | |
# | |
# Where it goes: | |
# 1. Pass no arguments to write to the target's derived Info.plist | |
# 2. Pass 'print marketing' or 'print build' to echo that version number to stdout | |
# 3. Pass 'pch' to write to a project-level PCH file for Info.plist preprocessing | |
### | |
# Calculate version numbers | |
build=`git describe | sed -e "s/^[^0-9]*//" | awk '{split($0,d,"-"); split(d[1],v,"."); print v[1] "." ((v[2] == "") ? "0" : (v[2] + 1)) "." d[2]}'` | |
marketing=`echo $build | awk '{split($0,v,"."); print v[1] "." v[2]}'` | |
# Send status using stderr | |
status() { >&2 echo $1; } | |
# Fix numbers for Release vs Non-Release builds | |
if [ "Release" = "${CONFIGURATION}" ]; then | |
if [[ -n $(git status --porcelain 2> /dev/null | tail -n1) ]]; then | |
status "error: The git working directory is dirty. Release version number is calculated for clean builds only." | |
exit 1 | |
else | |
status "note: Setting the marketing version to $marketing and the build version to $build." | |
fi | |
else | |
status "warning: Changing version from $build to $marketing.0." | |
build="$marketing.0" | |
fi | |
# Output | |
if [ "print" = "$1" ]; then | |
if [ "marketing" = "$2" ]; then | |
echo $marketing | |
else | |
echo $build | |
fi | |
elif [ "pch" = "$1" ]; then | |
# Write version numbers to a project-wide Info.plist preprocessor PCH file | |
echo "#define VERSION_BUILD $build" > $PROJECT_TEMP_DIR/VersionNumbers.pch | |
echo "#define VERSION_MARKETING $marketing" >> $PROJECT_TEMP_DIR/VersionNumbers.pch | |
status "note: Wrote version values to project-level PCH preprocessor file." | |
else | |
# Write version numbers to the target's build-time Info.plist | |
plist="$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH" | |
`defaults write "$plist" CFBundleShortVersionString "$marketing"` | |
`defaults write "$plist" CFBundleVersion "$build"` | |
status "note: Wrote version values to target's generated Info.plist." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment