2022-12-15 13:41:30 +00:00
#!/usr/bin/env bash
# Usage: ./generate_release_notes.sh --old-version <old version> --new-version <new version> --ref <ref>
#
# Example: ./generate_release_notes.sh --old-version v0.13.0 --new-version v0.13.1 --ref 1e6b244c
#
# This script generates release notes for the given version. It will generate
# release notes for all commits between the old version and the new version.
#
# Ref must be set to the commit that the new version will be tagget at. This
# is used to determine the commits that are included in the release. If the
# commit is already tagged, ref can be set to the tag name.
set -euo pipefail
# shellcheck source=scripts/lib.sh
2022-12-15 14:31:57 +00:00
source " $( dirname " $( dirname " ${ BASH_SOURCE [0] } " ) " ) /lib.sh "
2022-12-15 13:41:30 +00:00
old_version =
new_version =
ref =
2024-04-24 19:43:11 +00:00
mainline = 1
2022-12-15 13:41:30 +00:00
2024-04-24 19:43:11 +00:00
args = " $( getopt -o '' -l old-version:,new-version:,ref:,mainline,stable -- " $@ " ) "
eval set -- " ${ args } "
2022-12-15 13:41:30 +00:00
while true; do
case " $1 " in
--old-version)
old_version = " $2 "
shift 2
; ;
--new-version)
new_version = " $2 "
shift 2
; ;
--ref)
ref = " $2 "
shift 2
; ;
2024-04-24 19:43:11 +00:00
--mainline)
mainline = 1
shift
; ;
--stable)
mainline = 0
shift
; ;
2022-12-15 13:41:30 +00:00
--)
shift
break
; ;
*)
error " Unrecognized option: $1 "
; ;
esac
done
# Check dependencies.
dependencies gh sort
2024-04-30 16:36:12 +00:00
# Authticate gh CLI
gh_auth
2024-04-24 19:43:11 +00:00
if [ [ -z ${ old_version } ] ] ; then
2022-12-15 13:41:30 +00:00
error "No old version specified"
fi
2024-04-24 19:43:11 +00:00
if [ [ -z ${ new_version } ] ] ; then
2022-12-15 13:41:30 +00:00
error "No new version specified"
fi
2024-04-24 19:43:11 +00:00
if [ [ ${ new_version } != v* ] ] ; then
2023-07-21 12:22:54 +00:00
error "New version must start with a v"
fi
2024-04-24 19:43:11 +00:00
if [ [ -z ${ ref } ] ] ; then
2022-12-15 13:41:30 +00:00
error "No ref specified"
fi
# shellcheck source=scripts/release/check_commit_metadata.sh
2024-04-24 19:43:11 +00:00
source " ${ SCRIPT_DIR } /check_commit_metadata.sh " " ${ old_version } " " ${ ref } "
2022-12-15 13:41:30 +00:00
# Sort commits by title prefix, then by date, only return sha at the end.
2024-04-24 19:43:11 +00:00
git_show_out = " $(
{
echo " ${ COMMIT_METADATA_COMMITS [@] } " |
tr ' ' '\n' |
xargs git show --no-patch --pretty= format:"%ct %h %s"
} | sort -k3,3 -k1,1n | cut -d' ' -f2
) "
mapfile -t commits <<< " ${ git_show_out } "
2022-12-15 13:41:30 +00:00
2023-01-09 19:19:07 +00:00
# From: https://github.com/commitizen/conventional-commit-types
# NOTE(mafredri): These need to be supported in check_commit_metadata.sh as well.
declare -a section_order = (
breaking
2023-01-09 19:57:42 +00:00
security
2023-01-09 19:19:07 +00:00
feat
fix
docs
refactor
perf
test
build
ci
chore
revert
other
2023-02-15 14:23:06 +00:00
experimental
2023-01-09 19:19:07 +00:00
)
declare -A section_titles = (
[ breaking] = 'BREAKING CHANGES'
2023-01-09 19:57:42 +00:00
[ security] = 'SECURITY'
2023-01-09 19:19:07 +00:00
[ feat] = 'Features'
2023-01-10 14:04:33 +00:00
[ fix] = 'Bug fixes'
2023-01-09 19:19:07 +00:00
[ docs] = 'Documentation'
2023-01-10 14:04:33 +00:00
[ refactor] = 'Code refactoring'
[ perf] = 'Performance improvements'
2023-01-09 19:19:07 +00:00
[ test] = 'Tests'
[ build] = 'Builds'
2023-01-10 14:04:33 +00:00
[ ci] = 'Continuous integration'
2023-01-09 19:19:07 +00:00
[ chore] = 'Chores'
[ revert] = 'Reverts'
2023-01-10 14:04:33 +00:00
[ other] = 'Other changes'
2023-02-15 14:23:06 +00:00
[ experimental] = 'Experimental changes'
2023-01-09 19:19:07 +00:00
)
# Verify that all items in section_order exist as keys in section_titles and
# vice-versa.
for cat in " ${ section_order [@] } " ; do
2024-04-24 19:43:11 +00:00
if [ [ " ${ !section_titles[*] } " != *" ${ cat } " * ] ] ; then
error " BUG: category ${ cat } does not exist in section_titles "
2023-01-09 19:19:07 +00:00
fi
done
for cat in " ${ !section_titles[@] } " ; do
2024-04-24 19:43:11 +00:00
if [ [ " ${ section_order [*] } " != *" ${ cat } " * ] ] ; then
error " BUG: Category ${ cat } does not exist in section_order "
2023-01-09 19:19:07 +00:00
fi
done
2022-12-15 13:41:30 +00:00
for commit in " ${ commits [@] } " ; do
2024-04-24 19:43:11 +00:00
title = ${ COMMIT_METADATA_TITLE [ ${ commit } ] }
if [ [ -v COMMIT_METADATA_HUMAN_TITLE[ ${ commit } ] ] ] ; then
title = ${ COMMIT_METADATA_HUMAN_TITLE [ ${ commit } ] }
fi
if [ [ ${ title } = ~ \( #[0-9]*\)$ ]]; then
title = " ${ title %) } , ${ commit } ) "
else
title = " ${ title } ( ${ commit } ) "
fi
line = " - ${ title } "
line = ${ line //) (/, ) }
if [ [ -v COMMIT_METADATA_AUTHORS[ ${ commit } ] ] ] ; then
line += " ( ${ COMMIT_METADATA_AUTHORS [ ${ commit } ] } ) "
2023-01-25 09:13:42 +00:00
fi
2022-12-15 13:41:30 +00:00
2023-01-09 19:19:07 +00:00
# Default to "other" category.
cat = other
for c in " ${ !section_titles[@] } " ; do
2024-04-24 19:43:11 +00:00
if [ [ ${ c } = = " ${ COMMIT_METADATA_CATEGORY [ ${ commit } ] } " ] ] ; then
cat = ${ c }
2023-01-09 19:19:07 +00:00
break
fi
done
2024-04-24 19:43:11 +00:00
declare " ${ cat } " _changelog += " ${ line } " $'\n'
2022-12-15 13:41:30 +00:00
done
changelog = " $(
2023-01-09 19:19:07 +00:00
for cat in " ${ section_order [@] } " ; do
changes = " $( eval " echo -e \"\${ ${ cat } _changelog:-}\" " ) "
if ( ( ${# changes } > 0) ) ; then
2024-04-24 19:43:11 +00:00
echo -e " \n### ${ section_titles [ " ${ cat } " ] } \n "
if [ [ ${ cat } = = experimental ] ] ; then
2023-02-15 14:23:06 +00:00
echo -e "These changes are feature-flagged and can be enabled with the \`--experiments\` server flag. They may change or be removed in future releases.\n"
fi
2024-04-24 19:43:11 +00:00
echo -e " ${ changes } "
2023-01-09 19:19:07 +00:00
fi
done
2022-12-15 13:41:30 +00:00
) "
2024-04-24 19:43:11 +00:00
image_tag = " $( execrelative ../image_tag.sh --version " ${ new_version } " ) "
blurb =
stable_since =
if ( ( mainline) ) ; then
blurb = "
> [ !NOTE]
> This is a mainline Coder release. We advise enterprise customers without a staging environment to install our [ latest stable release] ( https://github.com/coder/coder/releases/latest) while we refine this version. Learn more about our [ Release Schedule] ( https://coder.com/docs/v2/latest/install/releases) .
"
else
# Date format: April 23, 2024
d = $( date +'%B %d, %Y' )
stable_since = " > ## Stable (since ${ d } ) " $'\n\n'
fi
2022-12-15 13:41:30 +00:00
2024-04-24 19:43:11 +00:00
echo -e " ${ stable_since } ## Changelog
${ blurb } ${ changelog }
2022-12-15 13:41:30 +00:00
2024-04-24 19:43:11 +00:00
Compare: [ \` ${ old_version } ...${ new_version } \` ] ( https://github.com/coder/coder/compare/${ old_version } ...${ new_version } )
2022-12-15 13:41:30 +00:00
2023-01-10 14:04:33 +00:00
## Container image
2022-12-15 13:41:30 +00:00
2024-04-24 19:43:11 +00:00
- \` docker pull ${ image_tag } \`
2023-01-31 17:33:42 +00:00
## Install/upgrade
2023-02-08 12:40:52 +00:00
Refer to our docs to [ install] ( https://coder.com/docs/v2/latest/install) or [ upgrade] ( https://coder.com/docs/v2/latest/admin/upgrade) Coder, or use a release asset below.
2022-12-15 13:41:30 +00:00
"