Skip to content

Instantly share code, notes, and snippets.

@markusfisch markusfisch/avup.sh
Last active Jun 29, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.