Created
November 29, 2019 01:51
-
-
Save phuochau/2dde07b5b91e95ca98c121aa87f93b4f to your computer and use it in GitHub Desktop.
Bash script to auto create release_x_x_x GIT branch with x.x.x is the version in package.json
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 | |
PACKAGE_VERSION=$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]') | |
NEW_PACKAGE_VERSION="${PACKAGE_VERSION//./_}" | |
BRANCH_NAME="release_${NEW_PACKAGE_VERSION}" | |
if [ `git branch -ra | egrep "remotes/origin/${BRANCH_NAME}$"` ] | |
then | |
echo "Branch name $BRANCH_NAME already exists!" | |
git checkout $BRANCH_NAME | |
git pull | |
git merge master | |
git add -A | |
git commit -m "[ci skip] Updated $BRANCH_NAME" | |
git push | |
else | |
echo "Branch name $BRANCH_NAME doesn't exists!" | |
git checkout master | |
git checkout -b $BRANCH_NAME | |
git push -u origin $BRANCH_NAME | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment