This repository has been archived by the owner on Oct 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion.sh
executable file
·44 lines (35 loc) · 1.89 KB
/
version.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/sh
# This script automatically sets the version and short version string of
# an Xcode project from the Git repository containing the project.
#
# To use this script in Xcode 4, add the contents to a "Run Script" build
# phase for your application target.
#set -o errexit
#set -o nounset
INFO_PLIST="${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Info"
# Get git tag and hash in the FullVersion
FULL_VERSION=$(git --git-dir="${PROJECT_DIR}/.git" --work-tree="${PROJECT_DIR}/" describe --dirty | sed -e 's/^v//' -e 's/g//')
if [ $? -ne 0 ]; then
FULL_VERSION=$(defaults read $INFO_PLIST CFBundleShortVersionString)
fi
# Use the latest tag for short version (You'll have to make sure that all your tags are of the format 0.0.0,
# this is to satisfy Apple's rule that short version be three integers separated by dots)
SHORT_VERSION=$(git --git-dir="${PROJECT_DIR}/.git" --work-tree="${PROJECT_DIR}/" describe --abbrev=0)
if [ $? -ne 0 ]; then
SHORT_VERSION=$(defaults read $INFO_PLIST CFBundleShortVersionString)
fi
# I'd like to use the Git commit hash for CFBundleVersion.
HASH_VERSION=$(git --git-dir="${PROJECT_DIR}/.git" --work-tree="${PROJECT_DIR}" rev-parse --short HEAD)
# But Apple wants this value to be a monotonically increasing integer, so
# instead use the number of commits on the master branch. If you like to
# play fast and loose with your Git history, this may cause you problems.
# Thanks to @amrox for pointing out the issue and fix.
VERSION=$(git --git-dir="${PROJECT_DIR}/.git" --work-tree="${PROJECT_DIR}/" rev-list master --count)
defaults write $INFO_PLIST CFBundleShortVersionString $SHORT_VERSION
defaults write $INFO_PLIST CFBundleVersion $VERSION
defaults write $INFO_PLIST HashVersion $HASH_VERSION
defaults write $INFO_PLIST FullVersion $FULL_VERSION
echo "VERSION: ${VERSION}"
echo "HASH_VERSION: ${HASH_VERSION}"
echo "SHORT_VERSION: ${SHORT_VERSION}"
echo "FULL_VERSION: ${FULL_VERSION}"