2020-09-10 11:11:57 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
mydir="$(dirname "$(realpath "$0")")"
|
|
|
|
|
|
|
|
source "$mydir/merge_helpers.sh"
|
|
|
|
|
2020-11-05 15:46:48 +01:00
|
|
|
if [ "$1" = "preview" ]; then
|
|
|
|
preview=1
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
preview=0
|
|
|
|
require_clean_git
|
|
|
|
fi
|
|
|
|
|
2020-09-10 11:11:57 +02:00
|
|
|
|
2020-11-05 15:06:00 +01:00
|
|
|
if [ "$1" = "test" ]; then
|
|
|
|
release_type="test"
|
|
|
|
previousTestVersionCode="$2"
|
|
|
|
else
|
|
|
|
release_type="normal"
|
|
|
|
fi
|
|
|
|
|
2020-09-10 11:11:57 +02:00
|
|
|
|
|
|
|
pushd "$mydir" > /dev/null
|
|
|
|
|
|
|
|
last_tag=`downstream_latest_tag`
|
|
|
|
|
|
|
|
build_gradle="vector/build.gradle"
|
|
|
|
|
|
|
|
get_prop() {
|
|
|
|
local prop="$1"
|
|
|
|
cat "$build_gradle" | grep "$prop = " | sed "s|$prop = ||"
|
|
|
|
}
|
|
|
|
set_prop() {
|
|
|
|
local prop="$1"
|
|
|
|
local value="$2"
|
|
|
|
if grep -q "$prop =" "$build_gradle"; then
|
|
|
|
local equals="= "
|
|
|
|
local not_equals=""
|
|
|
|
else
|
|
|
|
local equals=""
|
|
|
|
# Don't touch lines that have an equals in it, but not for this prop
|
|
|
|
local not_equals="/=/! "
|
|
|
|
fi
|
|
|
|
sed -i "$not_equals""s|\($prop $equals\).*|\1$value|g" "$build_gradle"
|
|
|
|
}
|
|
|
|
|
2020-11-05 14:15:41 +01:00
|
|
|
calculate_version_code() {
|
|
|
|
echo "(($versionMajor * 10000 + $versionMinor * 100 + $versionPatch + $scVersion) + 4000000) * 10" | bc
|
|
|
|
}
|
|
|
|
|
2020-09-10 11:11:57 +02:00
|
|
|
|
|
|
|
#
|
|
|
|
# Increase version
|
|
|
|
#
|
|
|
|
|
|
|
|
versionMajor=`get_prop ext.versionMajor`
|
|
|
|
versionMinor=`get_prop ext.versionMinor`
|
|
|
|
versionPatch=`get_prop ext.versionPatch`
|
|
|
|
scVersion=`get_prop ext.scVersion`
|
|
|
|
|
2020-11-05 14:15:41 +01:00
|
|
|
previousVersionCode=`grep '^ versionCode ' "$build_gradle" | sed 's|^ versionCode ||'`
|
|
|
|
versionCode=`calculate_version_code`
|
2020-11-05 15:06:00 +01:00
|
|
|
if [ "$release_type" = "test" ]; then
|
|
|
|
if [ ! -z "$previousTestVersionCode" ]; then
|
|
|
|
previousVersionCode=$((previousVersionCode > previousTestVersionCode ? previousVersionCode : previousTestVersionCode))
|
|
|
|
fi
|
|
|
|
versionCode=$((previousVersionCode + 1))
|
|
|
|
elif [ "$versionCode" = "$previousVersionCode" ]; then
|
2020-11-05 14:15:41 +01:00
|
|
|
((scVersion++))
|
|
|
|
echo "Increase downstream version to $scVersion"
|
|
|
|
versionCode=`calculate_version_code`
|
|
|
|
else
|
|
|
|
echo "Upstream version upgrade, no need to change downstream version"
|
|
|
|
fi
|
2020-09-10 11:11:57 +02:00
|
|
|
|
|
|
|
version="$versionMajor.$versionMinor.$versionPatch.sc.$scVersion"
|
2020-11-05 15:46:48 +01:00
|
|
|
|
|
|
|
if [ "$release_type" = "test" ]; then
|
|
|
|
version="$version-test"
|
|
|
|
fi
|
|
|
|
|
2020-09-30 10:52:45 +02:00
|
|
|
new_tag="sc_v$version"
|
2020-09-10 11:11:57 +02:00
|
|
|
|
2020-11-05 15:46:48 +01:00
|
|
|
if ((preview)); then
|
|
|
|
echo "versionCode $versionCode"
|
|
|
|
echo "versionName $version"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2020-09-10 11:11:57 +02:00
|
|
|
set_prop "ext.scVersion" "$scVersion"
|
|
|
|
set_prop "versionCode" "$versionCode"
|
|
|
|
set_prop "versionName" "\"$version\""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Generate changelog
|
|
|
|
#
|
|
|
|
|
|
|
|
changelog_dir=fastlane/metadata/android/en-US/changelogs
|
|
|
|
changelog_file="$changelog_dir/$versionCode.txt"
|
|
|
|
mkdir -p "$changelog_dir"
|
2020-12-20 09:20:18 +01:00
|
|
|
echo "Automatic changelog from commit history:" > "$changelog_file"
|
|
|
|
git log --reverse --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|" \
|
|
|
|
| grep -v "Automatic color correction" \
|
|
|
|
| grep -v "Automatic upstream merge postprocessing" \
|
|
|
|
| grep -v "Automatic SchildiChat string correction" \
|
|
|
|
| grep -v 'merge_helpers\|README\|increment_version' \
|
|
|
|
>> "$changelog_file"
|
2020-11-05 15:06:00 +01:00
|
|
|
if [ "$release_type" != "test" ]; then
|
|
|
|
$EDITOR "$changelog_file" || true
|
|
|
|
read -p "Press enter when changelog is done"
|
|
|
|
fi
|
2020-09-10 11:11:57 +02:00
|
|
|
|
|
|
|
git add -A
|
2020-11-05 15:06:00 +01:00
|
|
|
if [ "$release_type" = "test" ]; then
|
|
|
|
git commit -m "Test version $versionCode"
|
|
|
|
else
|
|
|
|
git commit -m "Increment version"
|
|
|
|
git tag "$new_tag"
|
|
|
|
fi
|
2020-09-10 11:11:57 +02:00
|
|
|
|
|
|
|
popd > /dev/null
|