-
Notifications
You must be signed in to change notification settings - Fork 229
/
version
executable file
·123 lines (90 loc) · 2.84 KB
/
version
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
116
117
118
119
120
121
122
123
#!/bin/bash
# version - Version number management.
# Edward Smith, December 2016.
set -euo pipefail
function usage() {
cat <<USAGE
version - Print or increment a version number.
Usage: version [ -hiMmp ]
With no options given, \`version\` simply prints the current version number.
Version numbers are: Major.Minor.Patch
Options:
-h Print this usage info.
-i Increment the version number. By default this increments the patch number.
-u Update all source files for the update. The '-i' version implies this option.
Updates version numbers in files:
Branch version: ../Branch-SDK/Branch-SDK/BNCConfig.m
Podspec version: ../Branch.podspec
Carthage version: ../carthage-files/Info.plist
-M Print or increment the \`major\` version number.
-m Print or increment the \`minor\` version number.
-p Print or increment the \`patch\` version number.
USAGE
}
version=0.29.3
if (( $# == 0 )); then
echo $version
exit 0
fi
scriptfile="$( cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
scriptfile="${scriptfile}"/$(basename "$0")
cd $(dirname "$scriptfile")
IFS=$'.' read M m p < <(echo "$version")
major=
minor=
patch=
increment=
update=
while getopts ":hiMmpvu" option; do
case "$option" in
h) usage; exit 0 ;;
i) increment=true; update=true ;;
M) major=true ;;
m) minor=true ;;
p) patch=true ;;
u) update=true ;;
v) ;;
?) echo ">>> Error: Unknown option '-$OPTARG'." 1>&2; exit 1 ;;
esac
done
if [[ $increment ]]; then
if [[ $major ]]; then
let M=M+1
m=0
p=0
elif [[ $minor ]]; then
let m=m+1
p=0
else
let p=p+1
fi
version="$M.$m.$p"
echo "$version"
else
# Print the version or parts
if [[ $major ]]; then
echo $M
elif [[ $minor ]]; then
echo $m
elif [[ $patch ]]; then
echo $p
else
echo "$version"
fi
fi
if [[ $update ]]; then
# Update the SDK version:
sed -i '' -e "/BNC_SDK_VERSION/ {s/\".*\"/\"$version\"/; }" ../Branch-SDK/Branch-SDK/BNCConfig.m
# Update the Podspec version:
sed -i '' -e "/^[[:space:]]*s\.version/ {s/\".*\"/\"$version\"/; }" ../Branch.podspec
# Update the Carthage version:
plutil -replace CFBundleVersion -string "$version" ../carthage-files/Info.plist
plutil -replace CFBundleShortVersionString -string "$version" ../carthage-files/Info.plist
# Update the Carthage version:
plutil -replace CFBundleVersion -string "$version" ../Branch-TestBed/Framework-Info.plist
plutil -replace CFBundleShortVersionString -string "$version" ../Branch-TestBed/Framework-Info.plist
fi
if [[ $increment ]]; then
# Update our version (Do this last. Updating a running bash script has undefined results.)
sed -i '' -e "s/^version=.*$/version=$version/" "$scriptfile"; exit 0
fi