-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutomaticBundleVersioning.sh
More file actions
executable file
·115 lines (73 loc) · 2.96 KB
/
AutomaticBundleVersioning.sh
File metadata and controls
executable file
·115 lines (73 loc) · 2.96 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
set -o nounset
oldPath="${PWD}"
cd "$(git rev-parse --show-toplevel)"
# * * *.
commitSHA1=$(git rev-parse HEAD)
echo "Commit SHA1: ${commitSHA1}"
# * * *.
commitsCount=$(git rev-list --count HEAD 2>/dev/null)
echo "Commits count: ${commitsCount}"
# * * *.
versionTagOrNil=$(git describe --abbrev=0 --match 'v[0-9]*.[0-9]*.[0-9]*' HEAD 2>/dev/null)
echo "Version tag: ${versionTagOrNil}"
# * * *.
versionTagWithoutPrefixOrNil=${versionTagOrNil##v}
echo "Version tag without prefix: ${versionTagWithoutPrefixOrNil}"
# * * *.
if [ $versionTagOrNil ]; then
commitsSinceLastTag=$(git rev-list --count ${versionTagOrNil}..)
else
commitsSinceLastTag=$commitsCount
fi
echo "Commits since last tag: ${commitsSinceLastTag}"
# * * *.
test -z "$(git status --untracked-files=normal --porcelain)"
isWorkingCopyDirty="${?}"
if [ $isWorkingCopyDirty -eq 1 ]; then
message="${commitSHA1}-dirty"
else
message="$commitSHA1"
fi
echo "isDirty: ${isWorkingCopyDirty}"
# * * *.
branchName=$(git rev-parse --symbolic-full-name --verify "$(git name-rev --name-only --no-undefined HEAD 2>/dev/null)" 2>/dev/null | sed -e 's:refs/heads/::' | sed -e 's:refs/::')
echo "Branch name: ${branchName}"
# * * *.
/usr/libexec/PlistBuddy -c "Delete :ABVGitCommitSHA1" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
/usr/libexec/PlistBuddy -c "Add :ABVGitCommitSHA1 string $message" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
# * * *.
function setBundleVersion()
{
/usr/libexec/PlistBuddy -c "Delete :CFBundleVersion" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
/usr/libexec/PlistBuddy -c "Add :CFBundleVersion string $1" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
if [ "$DEBUG_INFORMATION_FORMAT" == "dwarf-with-dsym" ]; then
/usr/libexec/PlistBuddy -c "Delete :CFBundleVersion" "${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}/Contents/Info.plist"
/usr/libexec/PlistBuddy -c "Add :CFBundleVersion string $1" "${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}/Contents/Info.plist"
fi
}
setBundleVersion $commitsCount
# * * *.
function setBundleShortVersionString
{
local fullString
if [ $2 -gt 0 ]; then
fullString="$1+$2"
else
fullString="$1"
fi
/usr/libexec/PlistBuddy -c "Delete :CFBundleShortVersionString" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
/usr/libexec/PlistBuddy -c "Add :CFBundleShortVersionString string $fullString" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
if [ "$DEBUG_INFORMATION_FORMAT" == "dwarf-with-dsym" ]; then
/usr/libexec/PlistBuddy -c "Delete :CFBundleShortVersionString" "${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}/Contents/Info.plist"
/usr/libexec/PlistBuddy -c "Add :CFBundleShortVersionString string $fullString" "${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}/Contents/Info.plist"
fi
}
if [ $versionTagWithoutPrefixOrNil ]; then
setBundleShortVersionString $versionTagWithoutPrefixOrNil $commitsSinceLastTag
else
setBundleShortVersionString 0.0.0 $commitsCount
fi
# * * *.
echo "AutomaticBundleVersioning: success."
cd "${oldPath}"