Skip to content

Instantly share code, notes, and snippets.

@waleedsamy
Last active December 8, 2016 11:33
Show Gist options
  • Save waleedsamy/6a8a214ade791a4df60777336328206f to your computer and use it in GitHub Desktop.
Save waleedsamy/6a8a214ade791a4df60777336328206f to your computer and use it in GitHub Desktop.
merge and push branches - designed to release nodejs applications
#!/usr/bin/env bash
###
## install: curl https://gist.githubusercontent.com/waleedsamy/6a8a214ade791a4df60777336328206f/raw/5fd0d9bbdcc2deaf3d023fcf8b682ea24350baa6/release.sh > ~/release.sh && chmod +x ~/release.sh
## usage: ~/release.sh
## usage: ~/release.sh master stable
## depends on: https://gist.github.com/waleedsamy/921294a0e5bdd49cf4c4
###
usage(){
echo usage release.sh branch another_branch
return 1
}
if [[ $# -eq 1 || $# -gt 2 ]]
then
usage
exit $?
fi
FROM=${1:-master}
TO=${2:-stable}
export GIT_MERGE_AUTOEDIT=no
PACKAGE_VERSION=$(cat package.json \
| grep version \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g' \
| tr -d '[[:space:]]')
echo Releasing version $PACKAGE_VERSION from $FROM to $TO
~/regit.sh $FROM && \
~/regit.sh $TO
git branch -D release-$PACKAGE_VERSION || true
git checkout $FROM && git checkout -b release-$PACKAGE_VERSION
git checkout $TO && git merge release-$PACKAGE_VERSION && \
git tag -d v$PACKAGE_VERSION || true && \
git tag -a v$PACKAGE_VERSION -m "version $PACKAGE_VERSION" && \
git checkout $FROM && git merge release-$PACKAGE_VERSION
git push origin $TO && \
git push origin $FROM && \
git push origin v$PACKAGE_VERSION -f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment