2 # Copyright (c) 2019-2020 Samsung Electronics Co., Ltd. All rights reserved
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
17 # @author Zofia Grzelewska <z.abramowska@samsung.com>
18 # @brief Helper script for preparing release commit
21 echo "Alfa-version of release script. Use on your own responsibility ;)"
23 CURRENT_MAJOR=($(cat packaging/askuser-notification.spec | grep Version | awk -F ":" '{print $2}' | awk -F "." '{print $2}'))
24 CURRENT_MINOR=($(cat packaging/askuser-notification.spec | grep Version | awk -F ":" '{print $2}' | awk -F "." '{print $3}'))
25 CURRENT_VERSION="$CURRENT_MAJOR.$CURRENT_MINOR"
26 CURRENT_VERSION_RE="\\<$CURRENT_MAJOR\\.$CURRENT_MINOR\\>"
29 OPTIND=1 # Reset in case getopts has been used previously in the shell.
31 # Initialize our own variables:
34 while getopts "h?m" opt; do
37 echo "Release script for updating askuser-notification version (default: minor version is updated)"
38 echo "Usage: $0 [-m Update major option instead of minor]"
42 echo "Invalid option: -$OPTARG" >&2
52 NEW_MAJOR=$((CURRENT_MAJOR + 1))
55 NEW_MAJOR=$CURRENT_MAJOR
56 NEW_MINOR=$((CURRENT_MINOR + 1))
59 NEW_VERSION="$NEW_MAJOR.$NEW_MINOR"
61 read -p "Update askuser release from $CURRENT_VERSION to $NEW_VERSION? [y/n]" -n 1 -r
65 if [[ $REPLY =~ ^[Yy]$ ]]
67 echo "Updating CMakeLists.txt files..."
68 find . -name "CMakeLists.txt" -type f -print0 | xargs -0 sed -i "s/${CURRENT_VERSION_RE}/${NEW_VERSION}/g"
69 echo "Updating spec files..."
70 find . -name "*.spec" -type f -print0 | xargs -0 sed -i "s/${CURRENT_VERSION_RE}/${NEW_VERSION}/g"
72 echo "Checking left files..."
73 left_files=($(git grep -I "${CURRENT_VERSION_RE}" | awk -F ":" '{print $1}' | sort -u))
75 CHANGELOG_FILE="packaging/askuser.changes"
76 if [ ${#left_files[*]} -ne 1 ]
78 echo "WARNING! Unexpected files left with old version still present :"
79 echo "${left_files[*]}"
82 if [ "${left_files}" != "${CHANGELOG_FILE}" ]
84 echo "WARNING! Unexpected file left with old version still present : ${left_files}"
87 echo "Updating changelog..."
89 AUTHOR_NAME=`git config user.name`
90 AUTHOR_EMAIL=`git config user.email`
92 COMMIT_DATE=`LC_ALL=C date "+%a %b %d %Y"`
94 RELEASE_COMMIT=`git log --pretty=oneline --abbrev-commit | grep "Release.*${CURRENT_VERSION}" | awk {'print $1'}`
96 COMMIT_LIST=($(git log --pretty=oneline --abbrev-commit ${RELEASE_COMMIT}..HEAD | awk {'first = $1; $1=""; print $0'}|sed 's/^ //g'))
97 #COMMIT_LIST=`git log --pretty=oneline --abbrev-commit ${RELEASE_COMMIT}..HEAD | awk {'first = $1; $1=""; print $0'}|sed 's/^ //g'`
99 COMMIT_TITLE="Release version 0.${NEW_VERSION}"
102 for COMMIT in ${COMMIT_LIST[@]}
104 COMMIT_MSG_LIST="${COMMIT_MSG_LIST}- ${COMMIT}${NEWLINE}"
107 echo "${COMMIT_DATE} ${AUTHOR_NAME} <${AUTHOR_EMAIL}>
110 $(cat ${CHANGELOG_FILE})" > ${CHANGELOG_FILE}
112 echo "Generating commit msg..."
113 COMMIT_MSG="${COMMIT_TITLE}${NEWLINE}${NEWLINE}${COMMIT_MSG_LIST}"
115 git commit "*CMakeLists.txt" "*spec" $CHANGELOG_FILE -m "${COMMIT_MSG}"