Fix static analysis issues
[platform/core/security/askuser.git] / release.sh
1 #!/bin/bash
2 # Copyright (c) 2019-2020 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 CURRENT_VERSION_RE="\\<$CURRENT_MAJOR\\.$CURRENT_MINOR\\>"
27
28 # A POSIX variable
29 OPTIND=1         # Reset in case getopts has been used previously in the shell.
30
31 # Initialize our own variables:
32 UPDATE_MAJOR=0
33
34 while getopts "h?m" opt; do
35     case "$opt" in
36     h)
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]"
39         exit 0
40         ;;
41     \?)
42         echo "Invalid option: -$OPTARG" >&2
43         exit 1
44         ;;
45     m)  UPDATE_MAJOR=1
46         ;;
47     esac
48 done
49
50 if ((UPDATE_MAJOR))
51 then
52     NEW_MAJOR=$((CURRENT_MAJOR + 1))
53     NEW_MINOR=0
54 else
55     NEW_MAJOR=$CURRENT_MAJOR
56     NEW_MINOR=$((CURRENT_MINOR + 1))
57 fi
58
59 NEW_VERSION="$NEW_MAJOR.$NEW_MINOR"
60
61 read -p "Update askuser release from $CURRENT_VERSION to $NEW_VERSION? [y/n]" -n 1 -r
62 echo
63
64
65 if [[ $REPLY =~ ^[Yy]$ ]]
66 then
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"
71
72     echo "Checking left files..."
73     left_files=($(git grep -I "${CURRENT_VERSION_RE}" | awk -F ":" '{print $1}' | sort -u))
74
75     CHANGELOG_FILE="packaging/askuser.changes"
76     if [ ${#left_files[*]} -ne 1 ]
77     then
78         echo "WARNING! Unexpected files left with old version still present :"
79         echo "${left_files[*]}"
80     fi
81
82     if [ "${left_files}" != "${CHANGELOG_FILE}" ]
83     then
84         echo "WARNING! Unexpected file left with old version still present : ${left_files}"
85     fi
86
87     echo "Updating changelog..."
88
89     AUTHOR_NAME=`git config user.name`
90     AUTHOR_EMAIL=`git config user.email`
91
92     COMMIT_DATE=`LC_ALL=C date "+%a %b %d %Y"`
93
94     RELEASE_COMMIT=`git log --pretty=oneline --abbrev-commit | grep "Release.*${CURRENT_VERSION}" | awk {'print $1'}`
95     IFS=$'\n'
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'`
98
99     COMMIT_TITLE="Release version 0.${NEW_VERSION}"
100     COMMIT_MSG_LIST=""
101     NEWLINE=$'\n'
102     for COMMIT in ${COMMIT_LIST[@]}
103     do
104         COMMIT_MSG_LIST="${COMMIT_MSG_LIST}- ${COMMIT}${NEWLINE}"
105     done
106
107     echo "${COMMIT_DATE} ${AUTHOR_NAME} <${AUTHOR_EMAIL}>
108 ${COMMIT_TITLE}
109 ${COMMIT_MSG_LIST}
110 $(cat ${CHANGELOG_FILE})" > ${CHANGELOG_FILE}
111
112     echo "Generating commit msg..."
113     COMMIT_MSG="${COMMIT_TITLE}${NEWLINE}${NEWLINE}${COMMIT_MSG_LIST}"
114
115     git commit "*CMakeLists.txt" "*spec" $CHANGELOG_FILE -m "${COMMIT_MSG}"
116
117     unset IFS
118
119 fi
120
121 exit
122