Skip to content

Instantly share code, notes, and snippets.

@dmongeau
Created January 6, 2016 14:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmongeau/e5c30f82c636392e715e to your computer and use it in GitHub Desktop.
Save dmongeau/e5c30f82c636392e715e to your computer and use it in GitHub Desktop.
Release script (Create a release branch, build, merge it and automatically tag to a new version)
#!/bin/zsh
LAST_VERSION=$(git tag -l | sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n | tail -n 1)
NEXT_VERSION=$(echo $LAST_VERSION | awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{if(length($NF+1)>length($NF))$(NF-1)++; $NF=sprintf("%0*d", length($NF), ($NF+1)%(10^length($NF))); print}')
VERSION=${1-${NEXT_VERSION}}
DEFAULT_MESSAGE="Release"
MESSAGE=${2-${DEFAULT_MESSAGE}}
RELEASE_BRANCH="release/$VERSION"
git add .
git commit -am $MESSAGE
git push
# Create release branch
git checkout -b $RELEASE_BRANCH develop
gulp build
git add .
git commit -am "Build $NEXT_VERSION"
git push origin $RELEASE_BRANCH
# Merge release branch in master
git checkout master
git merge $RELEASE_BRANCH
# Merge release branch in develop
git checkout develop
git merge $RELEASE_BRANCH
git push origin develop
# Tag and push master
git checkout master
git tag $VERSION
git push origin master --tags
# Remove release branch
git branch -d $RELEASE_BRANCH
# Return to develop
git checkout develop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment