Last active
September 28, 2021 18:17
-
-
Save willeccles/ae3ecb38099433c19e87ffc9d497f1eb to your computer and use it in GitHub Desktop.
Generate markdown changelogs from git tags and the commits between them
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/sh | |
set -e | |
# For each tag in the repository (sorted in reverse chronological order), print | |
# something like the following: | |
# | |
# ## Version <TAG> | |
# <Tag body, if it has one, but not the body of the pointed-to commit> | |
# | |
# ### Included changes | |
# - abc1234: <commit subject> | |
# - abc2345: <commit subject> | |
# | |
# The commits are listed in chronological order (older commits first). The | |
# "Included changes" section is not present for the first commit. | |
git tag --list --sort=-creatordate | while IFS= read -r tag; do | |
prev="$(git describe --tags --abbrev=0 "${tag}^" 2>/dev/null)" || true | |
printf "## Version %s\n" "$tag" | |
git for-each-ref "refs/tags/$tag" \ | |
--format='%(if:equals=tag)%(objecttype)%(then)%(contents:body)%(end)' | |
if [ -n "$prev" ]; then | |
printf "### Included changes\n" | |
git log "${prev}..${tag}" --reverse --pretty='tformat:- %h: %s' | |
printf "\n" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment