Last active
November 3, 2020 18:31
-
-
Save rav94/13f7afbcd6feb447244b54d0a8b6c4d3 to your computer and use it in GitHub Desktop.
Release a branch from master + updating maven POM file version to new version for multi module project.
This file contains 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 | |
# current Git branch | |
branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,') | |
# current project name | |
projectName=$(git config --local remote.origin.url|sed -n 's#.*/\([^.]*\)\.git#\1#p') | |
# establish master branch name variables | |
masterBranch=$branch | |
# checkout to master branch, this will break if the user has uncommited changes | |
git checkout $masterBranch | |
# master branch validation | |
if [ $branch = "master" ]; then | |
echo "Enter the release version number" | |
read versionNumber | |
# v1.0.0, v1.7.8, etc.. | |
versionLabel=v$versionNumber | |
# establish branch and tag name variables | |
releaseBranch=$versionNumber | |
tagName=$versionLabel | |
echo "Started releasing $versionLabel for $projectName ....." | |
# pull the latest version of the code from master | |
git pull | |
# create empty commit from master branch | |
git commit --allow-empty -m "Creating Branch $releaseBranch" | |
# create tag for new version from -master | |
git tag $tagName | |
# push commit to remote origin | |
git push | |
# push tag to remote origin | |
git push --tags origin | |
# create the release branch from the -master branch | |
git checkout -b $releaseBranch $masterBranch | |
# push local releaseBranch to remote | |
git push -u origin $releaseBranch | |
echo "$versionLabel is successfully released for $projectName ...." | |
echo "Checking out into $masterBranch again, where it all started...... :)" | |
# checkout to master branch | |
git checkout $masterBranch | |
# pull the latest version of the code from master | |
git pull | |
echo "Enter new version number for $projectName" | |
read newVersionNumer | |
# Update Maven version to next release number | |
mvn versions:set -DnewVersion=$newVersionNumer -DgenerateBackupPoms=false | |
# Commit setting new master branch version | |
git commit -a -m "Setting master branch version to $newVersionNumer" | |
# push commit to remote origin | |
git push | |
echo "Maven POM File Version is set to new version $newVersionNumer" | |
echo "Bye!" | |
else | |
echo "Please make sure you are on master branch and come back!" | |
echo "Bye!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can comment lines from line number 54 to 72 if Maven version update part is not necessary.