Skip to content

Instantly share code, notes, and snippets.

@oxodesign
Forked from adamreisnz/release.sh
Created March 27, 2020 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oxodesign/0fa26ee49d485b1230a8d40305dc48d7 to your computer and use it in GitHub Desktop.
Save oxodesign/0fa26ee49d485b1230a8d40305dc48d7 to your computer and use it in GitHub Desktop.
A script to automate merging of release branches
#!/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