Skip to content

Instantly share code, notes, and snippets.

@piyushchauhan2011
Forked from adamreisnz/release.sh
Created November 14, 2021 11:16
Show Gist options
  • Save piyushchauhan2011/5584923f9ffc15d27386c304976b973d to your computer and use it in GitHub Desktop.
Save piyushchauhan2011/5584923f9ffc15d27386c304976b973d 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