Skip to content

Instantly share code, notes, and snippets.

@justinmklam
Last active February 6, 2020 06:41
Show Gist options
  • Save justinmklam/0ca55e80c098db0b1a4eecdafa60503d to your computer and use it in GitHub Desktop.
Save justinmklam/0ca55e80c098db0b1a4eecdafa60503d to your computer and use it in GitHub Desktop.
Bash script to generate a changelog
#!/usr/bin/env bash
# Generates a changelog between tagged releases. Collects commits of pull requests, major, and bugfix tags
repository_url="https://bitbucket.org/MYPROJECT/MYREPO"
function generate_changelog() {
previous_tag=0
for current_tag in $(git tag --sort=-creatordate)
do
if [ "$previous_tag" != 0 ];then
tag_date=$(git log -1 --pretty=format:'%ad' --date=short ${previous_tag})
printf "## ${previous_tag} (${tag_date})\n\n"
git log ${current_tag}...${previous_tag} --pretty=format:"* %s [View](${repository_url}/commits/%H)" | grep -E "pull request|major|bugfix"
printf "\n\n"
fi
previous_tag=${current_tag}
done
# Show initial release for first tag
tag_date=$(git log -1 --pretty=format:'%ad' --date=short ${current_tag})
printf "## ${current_tag} (${tag_date})\n\n"
printf "* Initial release"
}
generate_changelog > CHANGELOG.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment