Make policy changes affect always entire package
[platform/core/security/askuser.git] / release.sh
1 #!/bin/bash
2 # Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
3 #
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
7 #
8 #        http://www.apache.org/licenses/LICENSE-2.0
9 #
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.
15 #
16 # @file        release.sh
17 # @author      Zofia Grzelewska <z.abramowska@samsung.com>
18 # @brief       Helper script for preparing release commit
19 #
20
21 echo "Alfa-version of release script. Use on your own responsibility ;)"
22
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
27 # A POSIX variable
28 OPTIND=1         # Reset in case getopts has been used previously in the shell.
29
30 # Initialize our own variables:
31 UPDATE_MAJOR=0
32
33 while getopts "h?m" opt; do
34     case "$opt" in
35     h)
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]"
38         exit 0
39         ;;
40     \?)
41         echo "Invalid option: -$OPTARG" >&2
42         exit 1
43         ;;
44     m)  UPDATE_MAJOR=1
45         ;;
46     esac
47 done
48
49 if ((UPDATE_MAJOR))
50 then
51     NEW_MAJOR=$((CURRENT_MAJOR + 1))
52     NEW_MINOR=0
53 else
54     NEW_MAJOR=$CURRENT_MAJOR
55     NEW_MINOR=$((CURRENT_MINOR + 1))
56 fi
57
58 NEW_VERSION="$NEW_MAJOR.$NEW_MINOR"
59
60 read -p "Update askuser release from $CURRENT_VERSION to $NEW_VERSION? [y/n]" -n 1 -r
61 echo
62
63
64 if [[ $REPLY =~ ^[Yy]$ ]]
65 then
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"
70
71     echo "Checking left files..."
72     left_files=($(git grep -IF "${CURRENT_VERSION}" | awk -F ":" '{print $1}' | sort -u))
73
74     CHANGELOG_FILE="packaging/askuser.changes"
75     if [ ${#left_files[*]} -ne 1 ]
76     then
77         echo "WARNING! Unexpected files left with old version still present :"
78         echo "${left_files[*]}"
79     fi
80
81     if [ "${left_files}" != "${CHANGELOG_FILE}" ]
82     then
83         echo "WARNING! Unexpected file left with old version still present : ${left_files}"
84     fi
85
86     echo "Updating changelog..."
87
88     AUTHOR_NAME=`git config user.name`
89     AUTHOR_EMAIL=`git config user.email`
90     COMMIT_DATE=`date "+%a %b %d %Y"`
91
92     RELEASE_COMMIT=`git log --pretty=oneline --abbrev-commit | grep "Release.*${CURRENT_VERSION}" | awk {'print $1'}`
93     IFS=$'\n'
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'`
96
97     COMMIT_TITLE="Release version 0.${NEW_VERSION}"
98     COMMIT_MSG_LIST=""
99     NEWLINE=$'\n'
100     for COMMIT in ${COMMIT_LIST[@]}
101     do
102         COMMIT_MSG_LIST="${COMMIT_MSG_LIST}- ${COMMIT}${NEWLINE}"
103     done
104
105     echo "${COMMIT_DATE} ${AUTHOR_NAME} <${AUTHOR_EMAIL}>
106 ${COMMIT_TITLE}
107 ${COMMIT_MSG_LIST}
108 $(cat ${CHANGELOG_FILE})" > ${CHANGELOG_FILE}
109
110     echo "Generating commit msg..."
111     COMMIT_MSG="${COMMIT_TITLE}${NEWLINE}${NEWLINE}${COMMIT_MSG_LIST}"
112
113     git commit "*CMakeLists.txt" "*spec" $CHANGELOG_FILE -m "${COMMIT_MSG}"
114
115     unset IFS
116
117 fi
118
119 exit
120