Skip to content

Instantly share code, notes, and snippets.

@ianmariano
Last active January 28, 2017 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ianmariano/7bd3092b92bea2323dd1c6dc702f3681 to your computer and use it in GitHub Desktop.
Save ianmariano/7bd3092b92bea2323dd1c6dc702f3681 to your computer and use it in GitHub Desktop.
Quick and dirty tag and release notes git plugin. Put in path and chmod +x it. git tagrelease -h for instructions.
#!/bin/bash
VERSION="20170125"
OUTPUT_FILE="./RELEASE_NOTES.md"
usage() {
cat << __EOF
git tagrelease usage:
git tagrelease [options]
Where [options] include:
-f|--from TAG When generating release notes, start from
this tag
-t|--to TAG When generating release notes, end at
this tag
-n|--name NAME Tag name
-o|--output FILE Output to this file, default $OUTPUT_FILE
-d|--dry-run Do a dry run
-i|--ignoredirty Ignore dirty index (uncommitted changes)
-h|--help Show this help
If a -t tag is not specified, release note generation will be from the
tag specified using -f. If both or only -t are specified, TAG_NAME will be
ignored and not used to commit the new release notes and tag the
commit. If -i is specified, anything staged for commit will be committed
with the new release notes.
__EOF
exit 1
}
FROM_TAG=""
TO_TAG=""
TAG_NAME=""
DRY_RUN=""
IGNORE_DIRTY=""
while [ $# -ge 1 ]; do
key="$1"
shift
case $key in
-f|--from)
FROM_TAG="$1"
shift
;;
-t|--to)
TO_TAG="$1"
shift
;;
-n|--name)
TAG_NAME="$1"
shift
;;
-o|--output)
OUTPUT_FILE="$1"
shift
;;
-d|--dry-run)
DRY_RUN="1"
;;
-i|--ignoredirty)
IGNORE_DIRTY="1"
;;
-h|--help)
usage
;;
*)
if [ -z $TAG_NAME ]; then
$TAG_NAME=$key
else
usage
fi
;;
esac
done
if ! [ -z $FROM_TAG ] && ! [ -z $TO_TAG ]; then
TAG_NAME=""
fi
if [ -z $TAG_NAME ] && [ -z $FROM_TAG ] && [ -z $TO_TAG ]; then
usage
fi
if [ -z $IGNORE_DIRTY ]; then
if output=$(git status --untracked-files=no --porcelain) && [ -z "$output" ]; then
echo "Working directory is clean."
else
echo "You have uncommitted changes."
exit 1
fi
fi
if ! [ -z $DRY_RUN ]; then
if ! [ -z $FROM_TAG ] && ! [ -z $TO_TAG ]; then
echo "## $TO_TAG"
git log $FROM_TAG..$TO_TAG --no-merges --format=" - %s"
elif ! [ -z $TO_TAG ]; then
echo "## $TO_TAG"
git log $TO_TAG --no-merges --format=" - %s"
elif [ -z $TAG_NAME ]; then
echo "Missing tag name, aborting."
exit 1
else
echo "## $TAG_NAME"
git log $FROM_TAG.. --no-merges --format=" - %s"
fi
echo ""
else
tmpfile=$(mktemp "/tmp/$(basename $0).XXXXXX")
echo "Generating $OUTPUT_FILE"
if ! [ -z $FROM_TAG ] && ! [ -z $TO_TAG ]; then
echo "## $TO_TAG" >> $tmpfile
git log $FROM_TAG..$TO_TAG --no-merges --format=" - %s" >> $tmpfile
elif ! [ -z $TO_TAG ]; then
echo "## $TO_TAG" >> $tmpfile
git log $TO_TAG --no-merges --format=" - %s" >> $tmpfile
elif [ -z $TAG_NAME ]; then
echo "Missing tag name, aborting."
exit 1
else
echo "## $TAG_NAME" >> $tmpfile
git log $FROM_TAG.. --no-merges --format=" - %s" >> $tmpfile
fi
echo "" >> $tmpfile
if [ -f "$OUTPUT_FILE" ]; then
mv -f "$OUTPUT_FILE" "$OUTPUT_FILE.old"
cat $tmpfile "$OUTPUT_FILE.old" >> "$OUTPUT_FILE"
rm -f "$OUTPUT_FILE.old"
else
cp $tmpfile "$OUTPUT_FILE"
fi
rm -f "$tmpfile"
if ! [ -z $TAG_NAME ]; then
echo "Committing $OUTPUT_FILE and tagging release."
git add "$OUTPUT_FILE"
git commit -am "Release $TAG_NAME"
git tag "$TAG_NAME" -m "Release $TAG_NAME"
fi
fi
echo "Done."
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment