Skip to content

Commit aec1590

Browse files
chore: Add more categories and titles for release notes (#5632)
Co-authored-by: Dean Sheather <dean@deansheather.com>
1 parent 70d71bc commit aec1590

File tree

2 files changed

+63
-37
lines changed

2 files changed

+63
-37
lines changed

scripts/release/check_commit_metadata.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ main() {
106106
commit_prefix=${BASH_REMATCH[1]}
107107
fi
108108
case $commit_prefix in
109-
feat | fix)
109+
# From: https://github.com/commitizen/conventional-commit-types
110+
feat | fix | docs | style | refactor | perf | test | build | ci | chore | revert)
110111
COMMIT_METADATA_CATEGORY[$commit_sha_short]=$commit_prefix
111112
;;
112113
*)

scripts/release/generate_release_notes.sh

Lines changed: 61 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -64,58 +64,83 @@ source "$SCRIPT_DIR/release/check_commit_metadata.sh" "${old_version}" "${ref}"
6464
# Sort commits by title prefix, then by date, only return sha at the end.
6565
mapfile -t commits < <(git log --no-merges --pretty=format:"%ct %h %s" "${old_version}..${ref}" | sort -k3,3 -k1,1n | cut -d' ' -f2)
6666

67-
breaking_changelog=
68-
feat_changelog=
69-
fix_changelog=
70-
other_changelog=
67+
# From: https://github.com/commitizen/conventional-commit-types
68+
# NOTE(mafredri): These need to be supported in check_commit_metadata.sh as well.
69+
declare -a section_order=(
70+
breaking
71+
feat
72+
fix
73+
docs
74+
refactor
75+
perf
76+
test
77+
build
78+
ci
79+
chore
80+
revert
81+
other
82+
)
83+
84+
declare -A section_titles=(
85+
[breaking]='BREAKING CHANGES'
86+
[feat]='Features'
87+
[fix]='Bug Fixes'
88+
[docs]='Documentation'
89+
[refactor]='Code Refactoring'
90+
[perf]='Performance Improvements'
91+
[test]='Tests'
92+
[build]='Builds'
93+
[ci]='Continuous Integration'
94+
[chore]='Chores'
95+
[revert]='Reverts'
96+
[other]='Other Changes'
97+
)
98+
99+
# Verify that all items in section_order exist as keys in section_titles and
100+
# vice-versa.
101+
for cat in "${section_order[@]}"; do
102+
if [[ " ${!section_titles[*]} " != *" $cat "* ]]; then
103+
error "BUG: category $cat does not exist in section_titles"
104+
fi
105+
done
106+
for cat in "${!section_titles[@]}"; do
107+
if [[ " ${section_order[*]} " != *" $cat "* ]]; then
108+
error "BUG: Category $cat does not exist in section_order"
109+
fi
110+
done
71111

72112
for commit in "${commits[@]}"; do
73113
line="- $commit ${COMMIT_METADATA_TITLE[$commit]}\n"
74114

75-
case "${COMMIT_METADATA_CATEGORY[$commit]}" in
76-
breaking)
77-
breaking_changelog+="$line"
78-
;;
79-
feat)
80-
feat_changelog+="$line"
81-
;;
82-
fix)
83-
fix_changelog+="$line"
84-
;;
85-
*)
86-
other_changelog+="$line"
87-
;;
88-
esac
115+
# Default to "other" category.
116+
cat=other
117+
for c in "${!section_titles[@]}"; do
118+
if [[ $c == "${COMMIT_METADATA_CATEGORY[$commit]}" ]]; then
119+
cat=$c
120+
break
121+
fi
122+
done
123+
declare "$cat"_changelog+="$line"
89124
done
90125

91126
changelog="$(
92-
if ((${#breaking_changelog} > 0)); then
93-
echo -e "### BREAKING CHANGES\n"
94-
echo -e "$breaking_changelog"
95-
fi
96-
if ((${#feat_changelog} > 0)); then
97-
echo -e "### Features\n"
98-
echo -e "$feat_changelog"
99-
fi
100-
if ((${#fix_changelog} > 0)); then
101-
echo -e "### Bug fixes\n"
102-
echo -e "$fix_changelog"
103-
fi
104-
if ((${#other_changelog} > 0)); then
105-
echo -e "### Other changes\n"
106-
echo -e "$other_changelog"
107-
fi
127+
for cat in "${section_order[@]}"; do
128+
changes="$(eval "echo -e \"\${${cat}_changelog:-}\"")"
129+
if ((${#changes} > 0)); then
130+
echo -e "\n### ${section_titles["$cat"]}\n"
131+
echo -e "$changes"
132+
fi
133+
done
108134
)"
109135

110136
image_tag="$(execrelative ./image_tag.sh --version "$new_version")"
111137

112138
echo -e "## Changelog
113-
114139
$changelog
115140
116141
Compare: [\`${old_version}...${new_version}\`](https://github.com/coder/coder/compare/${old_version}...${new_version})
117142
118-
## Container image
143+
## Container Image
119144
120145
- \`docker pull $image_tag\`
121146
"

0 commit comments

Comments
 (0)