forked from mozilla-mobile/firefox-ios
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbump.sh
executable file
·171 lines (151 loc) · 4.95 KB
/
bump.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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/bin/bash
# The goal of this script is to bump the current project version
# Final values
bumpingToVersionNumber=
bumpingToBuildNumber=
# Current values
versionNumber=$(git for-each-ref --sort='-authordate' | grep '.*refs/remotes/origin/delivery/bump-' | head -1 | rev | cut -d'-' -f 1-2 | rev | cut -d'-' -f 1)
buildNumber=$(git for-each-ref --sort='-authordate' | grep '.*refs/remotes/origin/delivery/bump-' | head -1 | rev | cut -d'-' -f 1-2 | rev | cut -d'-' -f 2)
# Ensure it's run from the correct path
# Falls back to exiting in case it is not executed from the correct path
check_script_execution_path() {
cd firefox-ios
plist="Client/Info.plist"
if [ ! -f "$plist" ]; then
echo "[x] Please run this script from the root of the project with ./bump.sh"
exit 0
fi
}
# Checks whether the git status is clean.
# Proceeds in case it is clean.
# Asks to stash all in case it is not.
# Falls back to exiting in case the user says he does not want to stash.
git_clean_or_stash() {
if [ -z "$(git status --porcelain)" ]; then
echo "[i] Git status clean, proceeding"
else
echo "[x] Git status not clean, shall we stash? [Yy/Nn]"
stash=
while [[ $stash = "" ]]; do
read stash
if [ "$stash" = "Y" ] || [ "$stash" = "y" ]; then
echo "[v] Stashing..."
git stash -u
else
echo "[v] Ok bye."
exit 0
fi
done
fi
}
# Perform a quick bump, with calculated values.
# Infinite user input loop until anything is typed.
# Falls back to interactive bump in case the user says he does not want to do a quick bump.
quick_bump() {
incrementedBuildNumber=$((buildNumber+1))
echo "[?] Do you want to bump from $versionNumber($buildNumber) to $versionNumber($incrementedBuildNumber)? [Yy/Nn]"
quickBump=
while [[ $quickBump = "" ]]; do
read quickBump
done
if [ "$quickBump" = "Y" ] || [ "$quickBump" = "y" ]; then
bumpingToVersionNumber=$versionNumber
bumpingToBuildNumber=$incrementedBuildNumber
echo "[v] Bumping to $versionNumber($incrementedBuildNumber)!"
else
interactive_bump
fi
}
# Perform an interactive bump, allows to input custom values.
# Infinite user input loops until a correct value is typed.
# Falls back to exiting in case the user says he does not want to do an interactive bump.
interactive_bump() {
echo "[?] The version number is $versionNumber, what is the new value? [xxx.yy.zz]"
interactiveVersionNumber=
while [[ $interactiveVersionNumber = "" ]]; do
read interactiveVersionNumber
if [[ ! $interactiveVersionNumber =~ ^[0-9]+(\.[0-9]+){2}$ ]]; then
echo "[x] Wrong format. Try again. [xxx.yy.zz]"
interactiveVersionNumber=
fi
done
echo "[?] The build number is $buildNumber, what is the new value? [v]"
interactiveBuildNumber=
while [[ $interactiveBuildNumber = "" ]]; do
read interactiveBuildNumber
if [[ ! $interactiveBuildNumber =~ ^[0-9]+$ ]]; then
echo "[x] Wrong format. Try again. [v]"
interactiveBuildNumber=
fi
done
echo "[?] Do you want to bump from $versionNumber($buildNumber) to $interactiveVersionNumber($interactiveBuildNumber)? [Yy/Nn]"
bump=
while [[ $bump = "" ]]; do
read bump
done
if [ "$bump" = "Y" ] || [ "$bump" = "y" ]; then
bumpingToVersionNumber=$interactiveVersionNumber
bumpingToBuildNumber=$interactiveBuildNumber
echo "[v] Bumping to $interactiveVersionNumber($interactiveBuildNumber)!"
else
echo "[v] Ok bye."
exit 0
fi
}
# Determine the base branch to bump from.
# Infinite user input loop until a correct value is typed.
define_bump_base_branch() {
echo "[?] From which base branch? [1/2/3]"
echo "1. $(git rev-parse --abbrev-ref HEAD) [current branch]"
echo "2. qwant-develop"
echo "3. qwant-main"
baseBranch=
baseBranchOption=
while [[ $baseBranchOption = "" ]]; do
read baseBranchOption
if [ "$baseBranchOption" = "1" ]; then
baseBranch=
elif [ "$baseBranchOption" = "2" ]; then
baseBranch="qwant-develop"
elif [ "$baseBranchOption" = "3" ]; then
baseBranch="qwant-main"
else
echo "[x] Wrong format. Try again. [1/2/3]"
baseBranchOption=
fi
done
}
# Creates the bump branch
# Sets the correct agv version
# Commit and push
bump_and_push() {
branchName="delivery/bump-$bumpingToVersionNumber-$bumpingToBuildNumber"
if [ ! -z "$baseBranch" ]; then
git checkout $baseBranch
git pull
fi
git checkout -b "$branchName"
agvtool new-marketing-version $bumpingToVersionNumber
agvtool new-version -all $bumpingToBuildNumber
git add *
git commit -m "[Qwant] Bump version to $bumpingToVersionNumber-$bumpingToBuildNumber"
git push origin -u "$branchName"
}
ensure_vpn_is_up() {
git ls-remote &>/dev/null || vpn_alert
}
vpn_alert() {
any=
echo "[x] Please connect to the VPN before going any further"
read any
}
# Script start
clear
check_script_execution_path
ensure_vpn_is_up
git_clean_or_stash
quick_bump
define_bump_base_branch
bump_and_push
echo "[v] All done, bye!"
# Script end