4 # Copyright (c) 2019-2020 Samsung Electronics Co., Ltd. All rights reserved.
6 # This file is licensed under the terms of MIT License or the Apache License
7 # Version 2.0 of your choice. See the LICENSE.MIT file for MIT license details.
8 # See the LICENSE file or the notice below for Apache License Version 2.0
11 # Licensed under the Apache License, Version 2.0 (the "License");
12 # you may not use this file except in compliance with the License.
13 # You may obtain a copy of the License at
15 # http://www.apache.org/licenses/LICENSE-2.0
17 # Unless required by applicable law or agreed to in writing, software
18 # distributed under the License is distributed on an "AS IS" BASIS,
19 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 # See the License for the specific language governing permissions and
21 # limitations under the License.
25 # @author Zofia Grzelewska <z.abramowska@samsung.com>
26 # @brief Helper script for preparing release commit
29 echo "Alfa-version of release script. Use on your own responsibility ;)"
31 CURRENT_TOP=($(cat packaging/security-manager.spec | grep Version | awk -F ":" '{print $2}' | awk -F "." '{print $1}'))
32 CURRENT_MAJOR=($(cat packaging/security-manager.spec | grep Version | awk -F ":" '{print $2}' | awk -F "." '{print $2}'))
33 CURRENT_MINOR=($(cat packaging/security-manager.spec | grep Version | awk -F ":" '{print $2}' | awk -F "." '{print $3}'))
34 CURRENT_VERSION="$CURRENT_TOP.$CURRENT_MAJOR.$CURRENT_MINOR"
37 OPTIND=1 # Reset in case getopts has been used previously in the shell.
39 # Initialize our own variables:
42 while getopts "h?m" opt; do
45 echo "Release script for updating security-manager version (default: minor version is updated)"
46 echo "Usage: $0 [-m Update major option instead of minor]"
50 echo "Invalid option: -$OPTARG" >&2
60 NEW_MAJOR=$((CURRENT_MAJOR + 1))
63 NEW_MAJOR=$CURRENT_MAJOR
64 NEW_MINOR=$((CURRENT_MINOR + 1))
67 NEW_VERSION="$CURRENT_TOP.$NEW_MAJOR.$NEW_MINOR"
69 read -p "Update security-manager release from $CURRENT_VERSION to $NEW_VERSION? [y/n]" -n 1 -r
73 if [[ $REPLY =~ ^[Yy]$ ]]
75 echo "Updating *.spec files..."
76 find . -name "*.spec" -type f -print0 | xargs -0 sed -i "s/${CURRENT_VERSION}/${NEW_VERSION}/g"
77 echo "Updating pc.in files..."
78 find . -name "*.pc.in" -type f -print0 | xargs -0 sed -i "s/${CURRENT_VERSION}/${NEW_VERSION}/g"
80 echo "Checking left files..."
81 left_files=($(git grep "${CURRENT_VERSION}" | awk -F ":" '{print $1}' | sort -u))
83 CHANGELOG_FILE="packaging/security-manager.changes"
84 if [ ${#left_files[*]} -ne 1 ]
86 echo "WARNING! Unexpected files left with old version still present :"
87 echo "${left_files[*]}"
90 if [ "${left_files}" != "${CHANGELOG_FILE}" ]
92 echo "WARNING! Unexpected file left with old version still present : ${left_files}"
95 echo "Updating changelog..."
97 RELEASE_COMMIT=`git log --pretty=oneline --abbrev-commit | grep "Release.*${CURRENT_VERSION}" | awk {'print $1'}`
99 COMMIT_LIST=($(git log --pretty=oneline --abbrev-commit ${RELEASE_COMMIT}..HEAD | awk {'first = $1; $1=""; print $0'}|sed 's/^ //g'))
100 #COMMIT_LIST=`git log --pretty=oneline --abbrev-commit ${RELEASE_COMMIT}..HEAD | awk {'first = $1; $1=""; print $0'}|sed 's/^ //g'`
101 COMMIT_TITLE="Release ${NEW_VERSION}"
102 DATE=`date +%Y.%m.%d`
104 echo "Release: ${NEW_VERSION}
106 Name: ${COMMIT_TITLE}
110 ###############################
112 $(cat ${CHANGELOG_FILE})" > ${CHANGELOG_FILE}
114 echo "Generating commit msg..."
116 COMMIT_MSG="${COMMIT_TITLE}${NEWLINE}"
117 for COMMIT in ${COMMIT_LIST[@]}
119 COMMIT_MSG="${COMMIT_MSG}${NEWLINE}* ${COMMIT}"
122 git commit "*pc.in" "*spec" ${CHANGELOG_FILE} -m "${COMMIT_MSG}"