Created
January 9, 2023 12:11
-
-
Save bhimsur/b5346f372d1b8bb5fe28092f61bd3fef to your computer and use it in GitHub Desktop.
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 | |
cd $1 | |
tag_repo() { | |
git tag -a "$1" -m "$2" | |
} | |
push_tag() { | |
git ls-remote -q --exit-code $1 | |
if [[ $? == 0 ]]; then | |
git push $1 --tags | |
echo "New Release tagged and pushed to remote $1." | |
else | |
echo "Remote $1 does not exist" | |
fi | |
} | |
CURRENT_DATE=`date +"%Y-%m-%d"` | |
CURRENT_VERSION=`mvn help:evaluate -Dexpression=project.version -q -DforceStdout` | |
CURRENT_REMOTE=`git for-each-ref --format='%(upstream:remotename)' $(git symbolic-ref -q HEAD)` | |
REFLOG_MESSAGE=`git log -1 --pretty=%B` | |
TAG_NAME=${CURRENT_VERSION}-${CURRENT_DATE} | |
echo "Tagging $TAG_NAME with last commit message $REFLOG_MESSAGE" | |
CHECK_TAG=`git tag -l $TAG_NAME` | |
# checking tag if exists | |
if [ $(git tag -l "$TAG_NAME") ]; then | |
echo "Deleting exising tag $TAG_NAME" | |
git push -d $CURRENT_REMOTE $TAG_NAME | |
git tag -d $TAG_NAME | |
else | |
echo "Creating new tag $TAG_NAME" | |
fi | |
tag_repo $TAG_NAME $REFLOG_MESSAGE | |
push_tag $CURRENT_REMOTE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment