Skip to content

Instantly share code, notes, and snippets.

@markusfisch
Last active June 29, 2019 00:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save markusfisch/8b909ded3d7afa174c9f156c093bad76 to your computer and use it in GitHub Desktop.
Save markusfisch/8b909ded3d7afa174c9f156c093bad76 to your computer and use it in GitHub Desktop.
Add, commit, tag and push in one go
#!/usr/bin/env bash
# Add, commit, tag and push
tag_and_push()
{
# find version (x.x.x) in uncommitted changes
local VERSION=''
VERSION=$(git diff -U0 |
grep -E "^\+.*([0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2})")
# cut out version if between double quotes
VERSION=${VERSION#*\"}
VERSION=${VERSION%\"*}
# cut out version if between single quotes
VERSION=${VERSION#*\'}
VERSION=${VERSION%\'*}
if [ -z "$VERSION" ]
then
echo "error: there's no version change" >&2
return 1
fi
[ -r $(git rev-parse --show-cdup)/CHANGELOG.* ] && {
git diff --name-only | grep 'CHANGELOG[\.md]*$' &>/dev/null || {
read -r -n 1 -p "CHANGELOG not changed! Proceed? (y/n) "
echo
case "$REPLY" in
y)
;;
*)
return 2
;;
esac
}
}
read -r -n 1 -p "Do you want to tag $VERSION? (y/n) "
echo
case "$REPLY" in
''|y)
git add --all &&
git commit -m "Advanced version number to $VERSION" &&
git tag -a "$VERSION" -m "Version $VERSION" &&
git push origin master &&
git push origin "$VERSION"
;;
esac
}
if [ "$0" == "$BASH_SOURCE" ]
then
tag_and_push "$@"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment