2 # Copyright (c) 2019 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"
28 OPTIND=1 # Reset in case getopts has been used previously in the shell.
30 # Initialize our own variables:
33 while getopts "h?m" opt; do
36 echo "Release script for updating askuser-notification version (default: minor version is updated)"
37 echo "Usage: $0 [-m Update major option instead of minor]"
41 echo "Invalid option: -$OPTARG" >&2
51 NEW_MAJOR=$((CURRENT_MAJOR + 1))
54 NEW_MAJOR=$CURRENT_MAJOR
55 NEW_MINOR=$((CURRENT_MINOR + 1))
58 NEW_VERSION="$NEW_MAJOR.$NEW_MINOR"
60 read -p "Update askuser release from $CURRENT_VERSION to $NEW_VERSION? [y/n]" -n 1 -r
64 if [[ $REPLY =~ ^[Yy]$ ]]
66 echo "Updating CMakeLists.txt files..."
67 find . -name "CMakeLists.txt" -type f -print0 | xargs -0 sed -i "s/${CURRENT_VERSION}/${NEW_VERSION}/g"
68 echo "Updating spec files..."
69 find . -name "*.spec" -type f -print0 | xargs -0 sed -i "s/${CURRENT_VERSION}/${NEW_VERSION}/g"
71 echo "Checking left files..."
72 left_files=($(git grep -IF "${CURRENT_VERSION}" | awk -F ":" '{print $1}' | sort -u))
74 CHANGELOG_FILE="packaging/askuser.changes"
75 if [ ${#left_files[*]} -ne 1 ]
77 echo "WARNING! Unexpected files left with old version still present :"
78 echo "${left_files[*]}"
81 if [ "${left_files}" != "${CHANGELOG_FILE}" ]
83 echo "WARNING! Unexpected file left with old version still present : ${left_files}"
86 echo "Updating changelog..."
88 AUTHOR_NAME=`git config user.name`
89 AUTHOR_EMAIL=`git config user.email`
90 COMMIT_DATE=`date "+%a %b %d %Y"`
92 RELEASE_COMMIT=`git log --pretty=oneline --abbrev-commit | grep "Release.*${CURRENT_VERSION}" | awk {'print $1'}`
94 COMMIT_LIST=($(git log --pretty=oneline --abbrev-commit ${RELEASE_COMMIT}..HEAD | awk {'first = $1; $1=""; print $0'}|sed 's/^ //g'))
95 #COMMIT_LIST=`git log --pretty=oneline --abbrev-commit ${RELEASE_COMMIT}..HEAD | awk {'first = $1; $1=""; print $0'}|sed 's/^ //g'`
97 COMMIT_TITLE="Release version 0.${NEW_VERSION}"
100 for COMMIT in ${COMMIT_LIST[@]}
102 COMMIT_MSG_LIST="${COMMIT_MSG_LIST}- ${COMMIT}${NEWLINE}"
105 echo "${COMMIT_DATE} ${AUTHOR_NAME} <${AUTHOR_EMAIL}>
108 $(cat ${CHANGELOG_FILE})" > ${CHANGELOG_FILE}
110 echo "Generating commit msg..."
111 COMMIT_MSG="${COMMIT_TITLE}${NEWLINE}${NEWLINE}${COMMIT_MSG_LIST}"
113 git commit "*CMakeLists.txt" "*spec" $CHANGELOG_FILE -m "${COMMIT_MSG}"