Skip to content

Instantly share code, notes, and snippets.

@adamreisnz
Last active April 13, 2024 17:01
Show Gist options
  • Star 23 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
  • Save adamreisnz/9bc7b1f88fd2741293bb6a29ea65dfa9 to your computer and use it in GitHub Desktop.
Save adamreisnz/9bc7b1f88fd2741293bb6a29ea65dfa9 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"
@MithunDN1
Copy link

is anybody check this script yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment