forked from element-hq/element-android
-
Notifications
You must be signed in to change notification settings - Fork 60
/
increment_version.sh
executable file
·202 lines (166 loc) · 6.57 KB
/
increment_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
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
197
198
199
200
201
202
#!/bin/bash
set -e
mydir="$(dirname "$(realpath "$0")")"
source "$mydir/merge_helpers.sh"
# https://f-droid.org/en/docs/All_About_Descriptions_Graphics_and_Screenshots/
max_changelog_len=500
should_merge_translations_for_release=0
if [ "$1" = "preview" ]; then
preview=1
shift
else
preview=0
require_clean_git
fi
if [ "$1" = "test" ]; then
release_type="test"
previousTestVersionCode="$2"
else
release_type="normal"
fi
pushd "$mydir" > /dev/null
do_translation_pull=0
if ((should_merge_translations_for_release)); then
if [ "$release_type" = "normal" ] && [ "$preview" != 1 ]; then
if git remote get-url weblate > /dev/null; then
echo "Pulling translations..."
translation commit && do_translation_pull=1 || echo "translation tool not found, skipping forced commit"
git fetch weblate
git merge weblate/sc --no-edit
else
echo "WARN: remote weblate not found, not updating translations"
fi
fi
fi
last_tag=`downstream_latest_tag`
# Legacy versioning, based on Element's version codes
#calculate_version_code() {
# echo "(($versionMajor * 10000 + $versionMinor * 100 + $versionPatch + $scVersion) + 4000000) * 10" | bc
#}
#
# Increase version
#
versionMajor=`get_prop ext.versionMajor`
versionMinor=`get_prop ext.versionMinor`
versionPatch=`get_prop ext.versionPatch`
scVersion=`get_prop ext.scVersion`
previousVersionCode=`grep '^ versionCode ' "$build_gradle" | sed 's|^ versionCode ||'`
# Legacy versioning, based on Element's version codes
#versionCode=`calculate_version_code`
#if [ "$release_type" = "test" ]; then
# if [ ! -z "$previousTestVersionCode" ]; then
# previousVersionCode=$((previousVersionCode > previousTestVersionCode ? previousVersionCode : previousTestVersionCode))
# fi
# versionCode=$((previousVersionCode + 1))
#elif [ "$versionCode" = "$previousVersionCode" ]; then
# ((scVersion++))
# echo "Increase downstream version to $scVersion"
# versionCode=`calculate_version_code`
#else
# echo "Upstream version upgrade, no need to change downstream version"
#fi
# New versioning: versionCode incremented independently of versionName, and always increment scVersion
((scVersion++))
if [ "$release_type" = "test" ]; then
if [ ! -z "$previousTestVersionCode" ]; then
testVersionCount=$((previousVersionCode > previousTestVersionCode ? 1 : (previousTestVersionCode - previousVersionCode + 1)))
previousVersionCode=$((previousVersionCode > previousTestVersionCode ? previousVersionCode : previousTestVersionCode))
else
testVersionCount=1
fi
versionCode=$((previousVersionCode + 1))
else
versionCode=$((previousVersionCode + 10))
# Ensure the new version code is higher than the one of the last test version
if [ -f "$HOME/fdroid/sm/data/metadata/de.spiritcroc.riotx.x.yml" ]; then
lastTestVersionCode="$(cat "$HOME/fdroid/sm/data/metadata/de.spiritcroc.riotx.x.yml"|grep versionCode|tail -n 1|sed 's|.*: ||')"
else
read -p "Enter versionCode of last test version: " lastTestVersionCode
fi
while [ "$lastTestVersionCode" -ge "$versionCode" ]; do
versionCode=$((versionCode + 10))
done
fi
version="$versionMajor.$versionMinor.$versionPatch.sc$scVersion"
if [ "$release_type" = "test" ]; then
version="$version-test$testVersionCount"
fi
new_tag="sc_v$version"
if ((preview)); then
echo "versionCode $versionCode"
echo "versionName $version"
exit 0
fi
set_prop "ext.scVersion" "$scVersion"
set_prop "versionCode" "$versionCode"
set_prop "versionName" "\"$version\""
#
# Generate changelog
#
git_changelog() {
git_args="$1"
git log $git_args --pretty=format:"- %s" "$last_tag".. --committer="$(git config user.name)" \
| grep -v 'Automatic revert to unchanged upstream strings' \
| grep -v 'Automatic upstream merge preparation' \
| sed "s|Merge tag '\\(.*\\)' into sc.*|Update codebase to Element \1|" \
| sed "s|Merge tag '\\(.*\\)' into merge.*|Update codebase to Element \1|" \
| grep -v "Merge .*branch" \
| grep -v "Automatic color correction" \
| grep -v "Automatic upstream merge postprocessing" \
| grep -v "Automatic SchildiChat string correction" \
| grep -v 'merge_helpers\|README\|increment_version' \
| grep -v "\\.sh" \
| grep -v "\\.md" \
| grep -v "Update string correction" \
| grep -v "Added translation using Weblate" \
| grep -v "Translated using Weblate" \
| grep -v "weblate/sc" \
| grep -v "\\[.*merge.*\\]" \
| grep -v "Disable Android Auto supports" \
| grep -v "Switch to alternative Schil" \
| grep -v "\\[gplay-release\\]" \
|| echo "No significant changes since the last stable release"
}
changelog_dir=fastlane/metadata/android/en-US/changelogs
changelog_file="$changelog_dir/$versionCode.txt"
mkdir -p "$changelog_dir"
if [ "$release_type" = "test" ]; then
git_changelog > "$changelog_file"
# Automated changelog is usually too long for F-Droid changelog
if [ "$(wc -m "$changelog_file"|sed 's| .*||')" -gt "$max_changelog_len" ]; then
current_commit="$(git rev-parse HEAD)"
changelog_add="$(echo -e "- ...\n\nAll changes: https://github.com/SchildiChat/SchildiChat-android/commits/$current_commit")"
addlen="$(expr length "$changelog_add")"
# - 3: probably not necessary, but I don't want to risk a broken link because of some miscalculation
allow_len=$((max_changelog_len - addlen - 3))
while [ "$(wc -m "$changelog_file"|sed 's| .*||')" -gt "$allow_len" ]; do
content_shortened="$(head -n -1 "$changelog_file")"
echo "$content_shortened" > "$changelog_file"
done
echo "$changelog_add" >> "$changelog_file"
fi
else
git_changelog --reverse > "$changelog_file"
fi
if [ "$release_type" != "test" ]; then
echo "Opening changelog for manual revision..."
await_edit "$changelog_file" || true
fi
while [ "$(wc -m "$changelog_file"|sed 's| .*||')" -gt "$max_changelog_len" ]; do
echo "Your changelog is too long, only $max_changelog_len characters allowed!"
echo "Currently: $(wc -m "$changelog_file")"
read -p "Press enter when changelog is done"
done
git add -A
if [ "$release_type" = "test" ]; then
git commit -m "Test version $versionCode"
else
git commit -m "Increment version"
git tag "$new_tag" -m "Version $version ($versionCode)
$(cat "$changelog_file")"
fi
if ((do_translation_pull)); then
echo "Updating weblate repo..."
translation pull
fi
popd > /dev/null