ClickHouse/release_lib.sh

156 lines
5.3 KiB
Bash
Raw Normal View History

2017-08-30 15:20:59 +00:00
set +e
2018-07-17 11:15:14 +00:00
function gen_version_string {
if [ -n "$TEST" ]; then
VERSION_STRING="$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH.$VERSION_REVISION"
else
VERSION_STRING="$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH"
fi
}
function get_version {
BASEDIR=$(dirname "${BASH_SOURCE[0]}")
2018-07-17 11:15:14 +00:00
VERSION_REVISION=`grep "set(VERSION_REVISION" ${BASEDIR}/dbms/cmake/version.cmake | sed 's/^.*VERSION_REVISION \(.*\)$/\1/' | sed 's/[) ].*//'`
VERSION_MAJOR=`grep "set(VERSION_MAJOR" ${BASEDIR}/dbms/cmake/version.cmake | sed 's/^.*VERSION_MAJOR \(.*\)/\1/' | sed 's/[) ].*//'`
VERSION_MINOR=`grep "set(VERSION_MINOR" ${BASEDIR}/dbms/cmake/version.cmake | sed 's/^.*VERSION_MINOR \(.*\)/\1/' | sed 's/[) ].*//'`
VERSION_PATCH=`grep "set(VERSION_PATCH" ${BASEDIR}/dbms/cmake/version.cmake | sed 's/^.*VERSION_PATCH \(.*\)/\1/' | sed 's/[) ].*//'`
VERSION_PREFIX="${VERSION_PREFIX:-v}"
2018-07-20 22:31:21 +00:00
VERSION_POSTFIX_TAG="${VERSION_POSTFIX:--testing}"
2018-07-17 11:15:14 +00:00
gen_version_string
2017-02-01 14:05:03 +00:00
}
function get_author {
AUTHOR=$(git config --get user.name || echo ${USER})
echo $AUTHOR
2016-02-07 21:58:58 +00:00
}
2017-05-07 20:25:26 +00:00
# Generate revision number.
# set environment variables REVISION, AUTHOR
2016-02-07 21:58:58 +00:00
function gen_revision_author {
2018-07-17 11:15:14 +00:00
TYPE=$1
get_version
if [[ $STANDALONE != 'yes' ]]; then
git fetch --tags
succeeded=0
attempts=0
max_attempts=1000
while [ $succeeded -eq 0 ] && [ $attempts -le $max_attempts ]; do
attempts=$(($attempts + 1))
2018-07-17 11:15:14 +00:00
if [ "$TYPE" == "major" ]; then
VERSION_REVISION=$(($VERSION_REVISION + 1))
VERSION_MAJOR=$(($VERSION_MAJOR + 1))
2018-07-20 00:34:15 +00:00
VERSION_MINOR=1
2018-07-17 11:15:14 +00:00
VERSION_PATCH=0
elif [ "$TYPE" == "minor" ] || [ "$TYPE" == "" ]; then
VERSION_REVISION=$(($VERSION_REVISION + 1))
VERSION_MINOR=$(($VERSION_MINOR + 1))
VERSION_PATCH=0
elif [ "$TYPE" == "patch" ] || [ "$TYPE" == "bugfix" ]; then
# VERSION_REVISION not incremented in new scheme.
if [ "$VERSION_MAJOR" -eq "1" ] && [ "$VERSION_MINOR" -eq "1" ]; then
VERSION_REVISION=$(($VERSION_REVISION + 1))
fi
2018-07-17 11:15:14 +00:00
VERSION_PATCH=$(($VERSION_PATCH + 1))
else
echo "Unknown version type $TYPE"
exit 1
fi
gen_version_string
2018-07-20 22:31:21 +00:00
git_tag_grep=`git tag | grep "$VERSION_PREFIX$VERSION_STRING$VERSION_POSTFIX_TAG"`
if [ "$git_tag_grep" == "" ]; then
succeeded=1
fi
done
if [ $succeeded -eq 0 ]; then
2018-07-17 11:15:14 +00:00
echo "Fail to create revision up to $VERSION_REVISION"
exit 1
fi
2017-04-18 10:05:14 +00:00
auto_message="Auto version update to"
2017-08-30 15:20:59 +00:00
git_log_grep=`git log --oneline --max-count=1 | grep "$auto_message"`
2017-04-18 10:05:14 +00:00
if [ "$git_log_grep" == "" ]; then
2018-07-20 22:31:21 +00:00
tag="$VERSION_PREFIX$VERSION_STRING$VERSION_POSTFIX_TAG"
2017-04-20 12:42:18 +00:00
# First tag for correct git describe
echo -e "\nTrying to create tag: $tag"
2017-08-30 15:20:59 +00:00
git tag -a "$tag" -m "$tag"
2017-04-20 12:50:00 +00:00
git_describe=`git describe`
2018-04-13 12:42:35 +00:00
git_hash=`git rev-parse HEAD`
2018-07-17 11:15:14 +00:00
sed -i -e "s/set(VERSION_REVISION [^) ]*/set(VERSION_REVISION $VERSION_REVISION/g;" \
-e "s/set(VERSION_DESCRIBE [^) ]*/set(VERSION_DESCRIBE $git_describe/g;" \
-e "s/set(VERSION_GITHASH [^) ]*/set(VERSION_GITHASH $git_hash/g;" \
-e "s/set(VERSION_MAJOR [^) ]*/set(VERSION_MAJOR $VERSION_MAJOR/g;" \
-e "s/set(VERSION_MINOR [^) ]*/set(VERSION_MINOR $VERSION_MINOR/g;" \
-e "s/set(VERSION_PATCH [^) ]*/set(VERSION_PATCH $VERSION_PATCH/g;" \
-e "s/set(VERSION_STRING [^) ]*/set(VERSION_STRING $VERSION_STRING/g;" \
dbms/cmake/version.cmake
2018-07-17 11:50:17 +00:00
gen_changelog "$VERSION_STRING" "" "$AUTHOR" ""
git commit -m "$auto_message [$VERSION_STRING] [$VERSION_REVISION]" dbms/cmake/version.cmake debian/changelog
2018-07-17 11:15:14 +00:00
git push
2017-04-20 12:50:00 +00:00
# Second tag for correct version information in version.cmake inside tag
if git tag --force -a "$tag" -m "$tag"
then
echo -e "\nTrying to push tag to origin: $tag"
git push origin "$tag"
if [ $? -ne 0 ]
then
git tag -d "$tag"
2017-04-18 10:05:14 +00:00
echo "Fail to create tag"
exit 1
fi
fi
else
2018-07-17 11:15:14 +00:00
get_version
echo reusing old version $VERSION_STRING
fi
fi
AUTHOR=$(git config --get user.name || echo ${USER})
export AUTHOR
2016-02-07 21:58:58 +00:00
}
2017-03-16 15:35:50 +00:00
function get_revision_author {
2018-07-17 11:15:14 +00:00
get_version
AUTHOR=$(get_author)
export AUTHOR
2017-03-16 15:35:50 +00:00
}
2017-05-07 20:25:26 +00:00
# Generate changelog from changelog.in.
2016-02-07 21:58:58 +00:00
function gen_changelog {
2018-07-17 11:15:14 +00:00
VERSION_STRING="$1"
CHDATE="$2"
AUTHOR="$3"
CHLOG="$4"
2018-07-17 11:15:14 +00:00
if [ -z "$VERSION_STRING" ] ; then
get_revision_author
fi
2017-08-18 01:32:52 +00:00
if [ -z "$CHLOG" ] ; then
CHLOG=debian/changelog
fi
if [ -z "$CHDATE" ] ; then
CHDATE=$(LC_ALL=C date -R | sed -e 's/,/\\,/g') # Replace comma to '\,'
fi
sed \
2018-07-17 11:15:14 +00:00
-e "s/[@]VERSION_STRING[@]/$VERSION_STRING/g" \
-e "s/[@]DATE[@]/$CHDATE/g" \
-e "s/[@]AUTHOR[@]/$AUTHOR/g" \
-e "s/[@]EMAIL[@]/$(whoami)@yandex-team.ru/g" \
< $CHLOG.in > $CHLOG
2016-02-07 21:58:58 +00:00
}