-
-
Save oxodesign/0fa26ee49d485b1230a8d40305dc48d7 to your computer and use it in GitHub Desktop.
A script to automate merging of release branches
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
#!/usr/bin/env bash | |
# Assuming you have a master and dev branch, and that you make new | |
# release branches named as the version they correspond to, e.g. 1.0.3 | |
# Usage: ./release.sh 1.0.3 | |
# Get version argument and verify | |
version=$1 | |
if [ -z "$version" ]; then | |
echo "Please specify a version" | |
exit | |
fi | |
# Output | |
echo "Releasing version $version" | |
echo "-------------------------------------------------------------------------" | |
# Get current branch and checkout if needed | |
branch=$(git symbolic-ref --short -q HEAD) | |
if [ "$branch" != "$version" ]; then | |
git checkout $version | |
fi | |
# Ensure working directory in version branch clean | |
git update-index -q --refresh | |
if ! git diff-index --quiet HEAD --; then | |
echo "Working directory not clean, please commit your changes first" | |
exit | |
fi | |
# Checkout master branch and merge version branch into master | |
git checkout master | |
git merge $version --no-ff --no-edit | |
# Run version script, creating a version tag, and push commit and tags to remote | |
npm version $version | |
git push | |
git push --tags | |
# Checkout dev branch and merge master into dev (to ensure we have the version) | |
git checkout dev | |
git merge master --no-ff --no-edit | |
git push | |
# Delete version branch locally and on remote | |
git branch -D $version | |
git push origin --delete $version | |
# Success | |
echo "-------------------------------------------------------------------------" | |
echo "Release $version complete" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment