Skip to content

Instantly share code, notes, and snippets.

@nischal-subedi
Forked from willvincent/hotfix.sh
Created January 7, 2022 14:29
Show Gist options
  • Save nischal-subedi/97f880ee55c3597f8dcd8916cf75c43e to your computer and use it in GitHub Desktop.
Save nischal-subedi/97f880ee55c3597f8dcd8916cf75c43e to your computer and use it in GitHub Desktop.
Cherry-pick and execute a hotfix release
#!/bin/bash
set -e
# Important note: this will add a new patch release AND deploy
if [ $# -lt 2 ]; then
git fetch --all --tags
# Interactively get info
LATEST=$(git describe --tags production)
read -e -p "Enter the version to patch, or press return for default [$LATEST]: " VERSION
[ -z "$VERSION" ] && VERSION=$LATEST
COMMITS=""
echo -e "Enter a single commit to cherry-pick (you'll be able to enter more): \c"
while read -r COMMIT
do
[ -z $COMMIT ] && break
COMMITS="$COMMITS$COMMIT "
echo -e "Another commit (or ENTER if you're done): \c"
done
else
VERSION=$1
COMMITS=${@:2}
fi
if [[ $VERSION != v* ]]; then
echo "Version should be in the format vX.Y.Z"
exit 1
fi
set -x
git checkout $VERSION
# Cherry-pick the bugfix commit to this version
git cherry-pick $COMMITS
# Version bump, update CHANGELOG
yarn standard-version -r patch
# Get the new patch version, push tags
NEW_VERSION=$(git describe)
git push --follow-tags origin $NEW_VERSION
# Move the production branch to this new release
git branch -f production $NEW_VERSION
# Push production (trigger deploy on Netlify)
git push -f origin production
git checkout master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment