Last active
January 7, 2019 07:43
-
-
Save mekya/7d2bce84903c64ddc9c0778bfe7f7e6f to your computer and use it in GitHub Desktop.
Prepare for release
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Usage | |
#First parameter is the version name either release or snapshot works | |
#if release version, create and checkout branch, update version, commit, tag and push are done | |
# ./release 1.6.1 | |
#if snapshot version, update the version, commit and push are done. After that it should be merged with master | |
#./release 1.6.2-SNAPSHOT | |
check() { | |
OUT=$1 | |
if [ $OUT -ne 0 ]; then | |
echo "There is a problem in releasing. Please check the log above" | |
exit $OUT | |
fi | |
} | |
#Creates a new branch, update version | |
#commit, tag and push | |
update_version_and_push() | |
{ | |
NEW_VERSION=$1 | |
BRANCH_NAME=release/$NEW_VERSION | |
TAG_NAME=release-$NEW_VERSION | |
#create and checkout branch | |
if [[ ! $NEW_VERSION =~ .*SNAPSHOT$ ]]; | |
then | |
echo "Checking out $BRANCH_NAME" | |
if [ ! `git branch --list $BRANCH_NAME` ] | |
then | |
echo "$BRANCH_NAME branch is being created." | |
git branch $BRANCH_NAME | |
fi | |
git checkout $BRANCH_NAME | |
fi | |
check $? | |
if [ "$2" = "self" ] | |
then | |
#project's own version is updated | |
mvn versions:set -DnewVersion=$NEW_VERSION | |
else | |
#project's parent is updated | |
mvn versions:update-parent -DparentVersion=$NEW_VERSION | |
fi | |
check $? | |
#add change pom.xml | |
git add pom.xml | |
check $? | |
#commit pom.xml | |
git commit -m "Update version to $NEW_VERSION" | |
check $? | |
#push branch to remote | |
git push -u origin $BRANCH_NAME | |
check $? | |
if [[ ! $NEW_VERSION =~ .*SNAPSHOT$ ]]; | |
then | |
#tag branch | |
git tag $TAG_NAME | |
check $? | |
#push tags | |
git push origin --tags | |
check $? | |
fi | |
} | |
CURRENT_PATH=`pwd` | |
declare -a arr=( | |
"Ant-Media-Server-Common" | |
"Ant-Media-Server-Service" | |
"Ant-Media-Server" | |
"Ant-Media-Enterprise" | |
"ManagementConsole_WebApp" | |
"SampleApp" | |
"WebRTCApp" | |
"WebRTCApp4Enterprise" | |
) | |
VERSION=$1 | |
PARENT_PATH=$CURRENT_PATH/Ant-Media-Server-Parent | |
cd $PARENT_PATH | |
update_version_and_push $VERSION self | |
mvn install -Dgpg.skip=true | |
## loop through the array | |
for i in "${arr[@]}" | |
do | |
echo "Entering $i" | |
cd $CURRENT_PATH/$i | |
update_version_and_push $VERSION | |
done | |
if [[ $VERSION =~ .*SNAPSHOT$ ]]; | |
then | |
echo "Make Pull Request to master branch for all projects below" | |
else | |
echo "Check that all projects below have passed CI/CD" | |
fi | |
echo "Ant-Media-Server-Parent" | |
for i in "${arr[@]}" | |
do | |
echo "$i" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment