Release 1.8.16
[platform/core/security/security-manager.git] / release.sh
1 #!/bin/bash
2
3 #
4 # Copyright (c) 2019-2020 Samsung Electronics Co., Ltd. All rights reserved.
5 #
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
9 # details.
10 #
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
14 #
15 #     http://www.apache.org/licenses/LICENSE-2.0
16 #
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.
22 #
23
24 # @file        release.sh
25 # @author      Zofia Grzelewska <z.abramowska@samsung.com>
26 # @brief       Helper script for preparing release commit
27 #
28
29 echo "Alfa-version of release script. Use on your own responsibility ;)"
30
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"
35
36 # A POSIX variable
37 OPTIND=1         # Reset in case getopts has been used previously in the shell.
38
39 # Initialize our own variables:
40 UPDATE_MAJOR=0
41
42 while getopts "h?m" opt; do
43     case "$opt" in
44     h)
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]"
47         exit 0
48         ;;
49     \?)
50         echo "Invalid option: -$OPTARG" >&2
51         exit 1
52         ;;
53     m)  UPDATE_MAJOR=1
54         ;;
55     esac
56 done
57
58 if ((UPDATE_MAJOR))
59 then
60     NEW_MAJOR=$((CURRENT_MAJOR + 1))
61     NEW_MINOR=0
62 else
63     NEW_MAJOR=$CURRENT_MAJOR
64     NEW_MINOR=$((CURRENT_MINOR + 1))
65 fi
66
67 NEW_VERSION="$CURRENT_TOP.$NEW_MAJOR.$NEW_MINOR"
68
69 read -p "Update security-manager release from $CURRENT_VERSION to $NEW_VERSION? [y/n]" -n 1 -r
70 echo
71
72
73 if [[ $REPLY =~ ^[Yy]$ ]]
74 then
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"
79
80     echo "Checking left files..."
81     left_files=($(git grep "${CURRENT_VERSION}" | awk -F ":" '{print $1}' | sort -u))
82
83     CHANGELOG_FILE="packaging/security-manager.changes"
84     if [ ${#left_files[*]} -ne 1 ]
85     then
86         echo "WARNING! Unexpected files left with old version still present :"
87         echo "${left_files[*]}"
88     fi
89
90     if [ "${left_files}" != "${CHANGELOG_FILE}" ]
91     then
92         echo "WARNING! Unexpected file left with old version still present : ${left_files}"
93     fi
94
95     echo "Updating changelog..."
96
97     RELEASE_COMMIT=`git log --pretty=oneline --abbrev-commit | grep "Release.*${CURRENT_VERSION}" | awk {'print $1'}`
98     IFS=$'\n'
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`
103
104     echo "Release: ${NEW_VERSION}
105 Date:    ${DATE}
106 Name:    ${COMMIT_TITLE}
107 Description:
108 ${COMMIT_LIST[*]}
109
110 ###############################
111
112 $(cat ${CHANGELOG_FILE})" > ${CHANGELOG_FILE}
113
114     echo "Generating commit msg..."
115     NEWLINE=$'\n'
116     COMMIT_MSG="${COMMIT_TITLE}${NEWLINE}"
117     for COMMIT in ${COMMIT_LIST[@]}
118     do
119         COMMIT_MSG="${COMMIT_MSG}${NEWLINE}* ${COMMIT}"
120     done
121
122     git commit "*pc.in" "*spec" ${CHANGELOG_FILE} -m "${COMMIT_MSG}"
123     unset IFS
124
125 fi
126
127
128 exit