From e4a84061bb0d0026b105c3f854dbf8445bd87a7c Mon Sep 17 00:00:00 2001 From: Mickael Stanislas Date: Wed, 14 Feb 2024 09:43:57 +0100 Subject: [PATCH] chore: add changelog scripts --- .github/changelog/changelog.tmpl | 56 +++++++++++++++++++++++++ .github/changelog/generate-changelog.sh | 54 ++++++++++++++++++++++++ .github/changelog/release-note.tmpl | 3 ++ 3 files changed, 113 insertions(+) create mode 100644 .github/changelog/changelog.tmpl create mode 100644 .github/changelog/generate-changelog.sh create mode 100644 .github/changelog/release-note.tmpl diff --git a/.github/changelog/changelog.tmpl b/.github/changelog/changelog.tmpl new file mode 100644 index 0000000..3ed0bdb --- /dev/null +++ b/.github/changelog/changelog.tmpl @@ -0,0 +1,56 @@ +{{- if .NotesByType.deprecation -}} +### :warning: **Deprecations** + +{{range .NotesByType.deprecation -}} +* {{ template "note" .}} +{{ end -}} +{{- end -}} + +{{- if index .NotesByType "breaking-change" -}} +### :rotating_light: **Breaking Changes** + +{{range index .NotesByType "breaking-change" -}} +* {{ template "note" .}} +{{ end -}} +{{- end -}} + +{{- if index .NotesByType "feature" -}} +### :rocket: **New Features** + +{{range index .NotesByType "feature" -}} +* {{ template "note" .}} +{{ end -}} +{{- end -}} + +{{- $improvements := combineTypes .NotesByType.improvement .NotesByType.enhancement -}} +{{- if $improvements }} +### :tada: **Improvements** + +{{range $improvements | sort -}} +* {{ template "note" . }} +{{ end -}} +{{- end -}} + +{{- if .NotesByType.bug }} +### :bug: **Bug Fixes** + +{{range .NotesByType.bug -}} +* {{ template "note" . }} +{{ end -}} +{{- end -}} + +{{- if .NotesByType.note -}} +### :information_source: **Notes** + +{{range .NotesByType.note -}} +* {{ template "note" .}} +{{ end -}} +{{- end -}} + +{{- if .NotesByType.dependency }} +### :dependabot: **Dependencies** + +{{range .NotesByType.dependency | sort -}} +* {{ template "note" . }} +{{ end -}} +{{- end -}} \ No newline at end of file diff --git a/.github/changelog/generate-changelog.sh b/.github/changelog/generate-changelog.sh new file mode 100644 index 0000000..a5274bb --- /dev/null +++ b/.github/changelog/generate-changelog.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +set -o errexit +set -o nounset + +__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +__parent="$(dirname "$__dir")" +__root="$(dirname "$__parent")" + +CHANGELOG_FILE_NAME="CHANGELOG.md" +CHANGELOG_TMP_FILE_NAME="CHANGELOG.tmp" +TARGET_SHA=$(git rev-parse HEAD) +PREVIOUS_RELEASE_TAG=$(git describe --abbrev=0 --match='v*.*.*' --tags) +PREVIOUS_RELEASE_SHA=$(git rev-list -n 1 $PREVIOUS_RELEASE_TAG) + +if [ $TARGET_SHA == $PREVIOUS_RELEASE_SHA ]; then + echo "Nothing to do" + exit 0 +fi + +PREVIOUS_CHANGELOG=$(sed -n -e "/# ${PREVIOUS_RELEASE_TAG#v}/,\$p" $__root/$CHANGELOG_FILE_NAME) + +if [ -z "$PREVIOUS_CHANGELOG" ] +then + echo "Unable to locate previous changelog contents." + exit 1 +fi + +CHANGELOG=$($(go env GOPATH)/bin/changelog-build -this-release $TARGET_SHA \ + -last-release $PREVIOUS_RELEASE_SHA \ + -git-dir $__root \ + -entries-dir .changelog \ + -changelog-template $__dir/changelog.tmpl \ + -note-template $__dir/release-note.tmpl) +if [ -z "$CHANGELOG" ] +then + echo "No changelog generated." + exit 0 +fi + +rm -f $CHANGELOG_TMP_FILE_NAME + +sed -n -e "1{/# /p;}" $__root/$CHANGELOG_FILE_NAME > $CHANGELOG_TMP_FILE_NAME +echo "$CHANGELOG" >> $CHANGELOG_TMP_FILE_NAME +echo >> $CHANGELOG_TMP_FILE_NAME +echo "$PREVIOUS_CHANGELOG" >> $CHANGELOG_TMP_FILE_NAME + +cp $CHANGELOG_TMP_FILE_NAME $CHANGELOG_FILE_NAME + +rm $CHANGELOG_TMP_FILE_NAME + +echo "Successfully generated changelog." + +exit 0 \ No newline at end of file diff --git a/.github/changelog/release-note.tmpl b/.github/changelog/release-note.tmpl new file mode 100644 index 0000000..9e2652e --- /dev/null +++ b/.github/changelog/release-note.tmpl @@ -0,0 +1,3 @@ +{{- define "note" -}} +{{.Body}} (GH-{{- .Issue -}}) +{{- end -}} \ No newline at end of file