Created
January 7, 2022 03:21
-
-
Save willvincent/5c087aea60cedc82f4f5516a17756e83 to your computer and use it in GitHub Desktop.
Cherry-pick and execute a hotfix release
This file contains hidden or 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
#!/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
There are several assumptions made here, namely that your master branch is in fact named master, that you have a production branch named production, and that you're utilizing standard version, though you could pretty easily alter all of that to retain the underlying functionality in a different situation.
You can either specify the version and commit sha(s) to cherry pick when executing, or just run the script and use the interactive prompts to define commit(s) to include in your hotfix.