Add release script 94/198994/2
authorZofia Grzelewska <z.abramowska@samsung.com>
Tue, 29 Jan 2019 14:56:05 +0000 (15:56 +0100)
committerZofia Grzelewska <z.abramowska@samsung.com>
Thu, 31 Jan 2019 15:17:26 +0000 (16:17 +0100)
Add script helping in creating release commit:
* update version in all CMakeLists.txt files
* update version in all *.spec files
* update changelog
* generate commit message

Change-Id: Idc86879ed1ab64414f5a4f3b9855f013aeb55bed

release.sh [new file with mode: 0755]

diff --git a/release.sh b/release.sh
new file mode 100755 (executable)
index 0000000..b08014e
--- /dev/null
@@ -0,0 +1,120 @@
+#!/bin/bash
+# Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+#
+#    Licensed under the Apache License, Version 2.0 (the "License");
+#    you may not use this file except in compliance with the License.
+#    You may obtain a copy of the License at
+#
+#        http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS,
+#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#    See the License for the specific language governing permissions and
+#    limitations under the License.
+#
+# @file        release.sh
+# @author      Zofia Grzelewska <z.abramowska@samsung.com>
+# @brief       Helper script for preparing release commit
+#
+
+echo "Alfa-version of release script. Use on your own responsibility ;)"
+
+CURRENT_MAJOR=($(cat packaging/cynara.spec | grep Version | awk -F ":" '{print $2}' | awk -F "." '{print $2}'))
+CURRENT_MINOR=($(cat packaging/cynara.spec | grep Version | awk -F ":" '{print $2}' | awk -F "." '{print $3}'))
+CURRENT_VERSION="$CURRENT_MAJOR.$CURRENT_MINOR"
+
+# A POSIX variable
+OPTIND=1         # Reset in case getopts has been used previously in the shell.
+
+# Initialize our own variables:
+UPDATE_MAJOR=0
+
+while getopts "h?m" opt; do
+    case "$opt" in
+    h)
+       echo "Release script for updating cynara version (default: minor version is updated)"
+        echo "Usage: $0 [-m Update major option instead of minor]"
+        exit 0
+        ;;
+    \?)
+        echo "Invalid option: -$OPTARG" >&2
+        exit 1
+        ;;
+    m)  UPDATE_MAJOR=1
+        ;;
+    esac
+done
+
+if ((UPDATE_MAJOR))
+then
+    NEW_MAJOR=$((CURRENT_MAJOR + 1))
+    NEW_MINOR=0
+else
+    NEW_MAJOR=$CURRENT_MAJOR
+    NEW_MINOR=$((CURRENT_MINOR + 1))
+fi
+
+NEW_VERSION="$NEW_MAJOR.$NEW_MINOR"
+
+read -p "Update cynara release from $CURRENT_VERSION to $NEW_VERSION? [y/n]" -n 1 -r
+echo
+
+
+if [[ $REPLY =~ ^[Yy]$ ]]
+then
+    echo "Updating CMakeLists.txt files..."
+    find . -name "CMakeLists.txt" -type f -print0 | xargs -0 sed -i "s/${CURRENT_VERSION}/${NEW_VERSION}/g"
+    echo "Updating spec files..."
+    find . -name "*.spec" -type f -print0 | xargs -0 sed -i "s/${CURRENT_VERSION}/${NEW_VERSION}/g"
+
+    echo "Checking left files..."
+    left_files=($(git grep "${CURRENT_VERSION}" | awk -F ":" '{print $1}' | sort -u))
+
+    CHANGELOG_FILE="changelog"
+    if [ ${#left_files[*]} -ne 1 ]
+    then
+        echo "WARNING! Unexpected files left with old version still present :"
+        echo "${left_files[*]}"
+    fi
+
+    if [ "${left_files}" != "${CHANGELOG_FILE}" ]
+    then
+        echo "WARNING! Unexpected file left with old version still present : ${left_files}"
+    fi
+
+    echo "Updating changelog..."
+
+    RELEASE_COMMIT=`git log --pretty=oneline --abbrev-commit | grep "Release.*${CURRENT_VERSION}" | awk {'print $1'}`
+    IFS=$'\n'
+    COMMIT_LIST=($(git log --pretty=oneline --abbrev-commit ${RELEASE_COMMIT}..HEAD | awk {'first = $1; $1=""; print $0'}|sed 's/^ //g'))
+#COMMIT_LIST=`git log --pretty=oneline --abbrev-commit ${RELEASE_COMMIT}..HEAD | awk {'first = $1; $1=""; print $0'}|sed 's/^ //g'`
+    COMMIT_TITLE="Release 0.${NEW_VERSION}"
+    DATE=`date +%Y.%m.%d`
+
+    echo "Release: 0.${NEW_VERSION}
+Date:   ${DATE}
+Name:   ${COMMIT_TITLE}
+Description:
+${COMMIT_LIST[*]}
+
+###############################
+
+$(cat ${CHANGELOG_FILE})" > ${CHANGELOG_FILE}
+
+    echo "Generating commit msg..."
+    NEWLINE=$'\n'
+    COMMIT_MSG="${COMMIT_TITLE}${NEWLINE}"
+    for COMMIT in ${COMMIT_LIST[@]}
+    do
+        COMMIT_MSG="${COMMIT_MSG}${NEWLINE}* ${COMMIT}"
+    done
+
+    git commit "*CMakeLists.txt" "*spec" "changelog" -m "${COMMIT_MSG}"
+    unset IFS
+
+fi
+
+
+exit
+