forked from duckduckgo/iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepare_release.sh
executable file
Β·196 lines (168 loc) Β· 4.92 KB
/
prepare_release.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/bash
set -eo pipefail
mute=">/dev/null 2>&1"
version="$1"
release_branch_parent="develop"
hotfix_branch_parent="main"
#
# Output passed arguments to stderr and exit.
#
die() {
cat >&2 <<< "$*"
exit 1
}
assert_ios_directory() {
cwd="$(dirname "${BASH_SOURCE[0]}")"
if [[ ${cwd} != "." ]]; then
die "π₯ Error: Run the script from a top-level directory in the iOS project"
fi
}
assert_fastlane_installed() {
if ! command -v bundle &> /dev/null; then
die "π₯ Error: Bundle is not installed. See: https://app.asana.com/0/1202500774821704/1203766784006610/f"
fi
if ! bundle show fastlane &> /dev/null; then
die "π₯ Error: Fastlane is not installed. See: https://app.asana.com/0/1202500774821704/1203766784006610/f"
fi
}
assert_gh_installed_and_authenticated() {
if ! command -v gh &> /dev/null; then
die "π₯ Error: GitHub CLI is not installed. See: https://app.asana.com/0/1202500774821704/1203791243007683/f"
fi
if ! gh auth status 2>&1 | grep -q "β Logged in to github.com"; then
echo "π₯ Error: GitHub CLI is not authenticated. See: https://app.asana.com/0/1202500774821704/1203791243007683/f"
fi
}
print_usage_and_exit() {
local reason=$1
cat <<- EOF
Usage:
$ $(basename "$0") <version> [-h] [-v]
Current version: $(cut -d' ' -f3 < Configuration/Version.xcconfig)
Options:
-h Make hotfix release
-v Enable verbose mode
EOF
die "${reason}"
}
read_command_line_arguments() {
local regexp="^[0-9]+(\.[0-9]+)*$"
if [[ ! "$1" =~ $regexp ]]; then
print_usage_and_exit "π₯ Error: Wrong app version specified"
fi
shift 1
while getopts 'hv' option; do
case "${option}" in
h)
is_hotfix=1
;;
v)
mute=
;;
*)
print_usage_and_exit "π₯ Error: Unknown option '${option}'"
;;
esac
done
shift $((OPTIND-1))
[[ $is_hotfix ]] && branch_name="hotfix" || branch_name="release"
release_branch="${branch_name}/${version}"
changes_branch="${release_branch}-changes"
}
stash() {
printf '%s' "Stashing your changes ... "
eval git stash "$mute"
echo "β
"
}
assert_clean_state() {
if git show-ref --quiet "refs/heads/${release_branch}"; then
die "π₯ Error: Branch ${release_branch} already exists"
fi
if git show-ref --quiet "refs/heads/${changes_branch}"; then
die "π₯ Error: Branch ${changes_branch} already exists"
fi
}
create_release_branch() {
if [[ ${is_hotfix} ]]; then
printf '%s' "Creating hotfix branch ... "
eval git checkout ${hotfix_branch_parent} "$mute"
else
printf '%s' "Creating release branch ... "
eval git checkout ${release_branch_parent} "$mute"
fi
eval git pull "$mute"
eval git checkout -b "${release_branch}" "$mute"
eval git checkout -b "${changes_branch}" "$mute"
echo "β
"
}
update_marketing_version() {
printf '%s' "Setting app version ... "
./set_version.sh "${version}"
git add Configuration/Version.xcconfig \
DuckDuckGo/Settings.bundle/Root.plist
eval git commit -m \"Update version number\" "$mute"
echo "β
"
}
update_build_version() {
echo "Setting build version ..."
local username
username="$(git config user.email 2>&1)"
bundle exec fastlane increment_build_number_for_version version:"${version}" username:"$username"
git add DuckDuckGo.xcodeproj/project.pbxproj
if [[ "$(git diff --cached)" ]]; then
eval git commit -m \"Update build number\" "$mute"
echo "Setting build version ... β
"
else
printf "\nNo changes to build number β
\n"
fi
}
update_embedded_files() {
printf '%s' "Updating embedded files ... "
eval ./update_embedded.sh "$mute"
git add Core/AppTrackerDataSetProvider.swift \
Core/trackerData.json \
Core/AppPrivacyConfigurationDataProvider.swift \
Core/ios-config.json
if [[ "$(git diff --cached)" ]]; then
eval git commit -m \"Update embedded files\" "$mute"
echo "β
"
else
printf "\nNo changes to embedded files β
\n"
fi
}
update_release_notes() {
local release_notes_path="fastlane/metadata/default/release_notes.txt"
echo "Please update release notes and save the file."
eval open -a TextEdit "${release_notes_path}" "$mute"
read -r -p "Press \`Enter\` when you're done to continue ..."
git add "${release_notes_path}"
if [[ "$(git diff --cached)" ]]; then
eval git commit -m \"Update release notes\" "$mute"
echo "Release notes updated β
"
else
echo "No changes to release notes β
"
fi
}
create_pull_request() {
printf '%s' "Creating PR ... "
eval git push origin "${release_branch}" "$mute"
eval git push origin "${changes_branch}" "$mute"
eval gh pr create --title \"Release "${version}"\" --base "${release_branch}" --assignee @me "$mute" --body-file "./scripts/assets/prepare-release-description"
eval gh pr view --web "$mute"
echo "β
"
}
main() {
assert_ios_directory
assert_fastlane_installed
assert_gh_installed_and_authenticated
read_command_line_arguments "$@"
stash
assert_clean_state
create_release_branch
update_marketing_version
update_build_version
update_embedded_files
update_release_notes
create_pull_request
}
main "$@"