Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

changelog: add go-changelog templates and tooling #101

Merged
merged 23 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
63108eb
changelog: add go-changelog templates
mikemorris Feb 15, 2022
9cbfdc9
ci: add changelog-checker from Consul core
mikemorris Feb 17, 2022
b30ac93
github: update PR template to remove HashiCorp-only changelog note
mikemorris Feb 23, 2022
032250d
makefile: add stub changelog tasks
mikemorris Feb 28, 2022
fd299a3
changelog: remove provider-specific types from release note template
mikemorris Mar 30, 2022
00e4a63
changelog: remove provider-specific features section from changelog t…
mikemorris Mar 30, 2022
2d2cb75
changelog: restore FEATURES section in template, move BREAKING CHANGE…
mikemorris Mar 30, 2022
00267ba
makefile: implement make changelog task
mikemorris Mar 30, 2022
3a5a140
makefile: add stub for make changelog-entry
mikemorris Mar 30, 2022
215876c
attempt to call changelog-entry from tmp fork
mikemorris Mar 31, 2022
d916f7e
fixme: use go-changelog fork until changelog-entry PR is merged
mikemorris Apr 1, 2022
509d717
changelog: add types file, add security section and reorder changelog…
mikemorris Apr 7, 2022
008a52c
fixme: update make changelog-check task to install from PR branch, no…
mikemorris Apr 7, 2022
6ffe14e
ci: validate changelog entry content with changelog-check
mikemorris Apr 8, 2022
d54b0a0
fixup: move changelog-check.sh to scripts directory
mikemorris Apr 8, 2022
b6ffca6
ci: set goenv 1.16 to build changelog-check from source
mikemorris Apr 8, 2022
79fd440
ci: minor cleanup and naming for changelog-check GitHub Action
mikemorris Apr 8, 2022
ef43f2e
ci: rename workflow file to changelog.yml
mikemorris Apr 8, 2022
930f785
changelog: add line breaks after section headers in template
mikemorris Apr 8, 2022
04c6595
changelog: fix note template link, add underscore prefix handling for…
mikemorris Apr 8, 2022
b7d23a2
ci: use extglob syntax to match optional underscore for enterprise ch…
mikemorris Apr 8, 2022
23987e7
cleanup: remove duplicate changelog-check.sh
mikemorris Apr 27, 2022
c2a4fb0
github: add PR template note to use make changelog-check
mikemorris Apr 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/101.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
changelog: add go-changelog templates and tooling
```
56 changes: 56 additions & 0 deletions .changelog/changelog.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{{- if index .NotesByType "breaking-change" -}}
BREAKING CHANGES:

{{range index .NotesByType "breaking-change" -}}
* {{ template "note" .}}
{{ end -}}
{{- end -}}

{{- if .NotesByType.security }}
SECURITY:

{{range .NotesByType.security -}}
* {{ template "note" .}}
{{ end -}}
{{- end -}}

{{- if .NotesByType.deprecation -}}
DEPRECATIONS:

{{range .NotesByType.deprecation -}}
* {{ template "note" .}}
{{ end -}}
{{- end -}}

{{- if .NotesByType.feature }}
FEATURES:

{{range .NotesByType.feature -}}
* {{ template "note" . }}
{{ end -}}
{{- end -}}

{{- $improvements := combineTypes .NotesByType.improvement .NotesByType.enhancement -}}
{{- if $improvements }}
IMPROVEMENTS:

{{range $improvements | sort -}}
* {{ template "note" . }}
{{ end -}}
{{- end -}}

{{- if .NotesByType.bug }}
BUG FIXES:

{{range .NotesByType.bug -}}
* {{ template "note" . }}
{{ end -}}
{{- end -}}

{{- if .NotesByType.note -}}
NOTES:

{{range .NotesByType.note -}}
* {{ template "note" .}}
{{ end -}}
{{- end -}}
3 changes: 3 additions & 0 deletions .changelog/release-note.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{- define "note" -}}
{{.Body}}{{if not (stringHasPrefix .Issue "_")}} [[GH-{{- .Issue -}}](https://github.com/hashicorp/consul-api-gateway/issues/{{- .Issue -}})]{{end}}
{{- end -}}
7 changes: 7 additions & 0 deletions .changelog/types.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
breaking-change
security
deprecation
feature
enhancement
bug
note
1 change: 0 additions & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@
### Checklist:
- [ ] Tests added
- [ ] CHANGELOG entry added
> HashiCorp engineers only, community PRs should not add a changelog entry.
> Entries should use imperative present tense (e.g. Add support for...)
mikemorris marked this conversation as resolved.
Show resolved Hide resolved
42 changes: 42 additions & 0 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This workflow checks that there is either a 'pr/no-changelog' label applied to a PR
# or there is a .changelog/<pr_number>.txt file containing a changelog entry with
# one or more valid changelog notes
name: changelog
on:
pull_request:
types: [opened, synchronize, labeled]
# Runs on PRs to main and all release branches
branches:
- main
- release/*

jobs:
validate:
# If there a `pr/no-changelog` label we ignore this check
if: "!contains(github.event.pull_request.labels.*.name, 'pr/no-changelog')"
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0 # by default the checkout action doesn't checkout all branches
# Go 1.16 or later needed for building changelog-check from source
- uses: ./.github/actions/goenv
with:
go-version: '1.17'
- name: Check for changelog entry in diff
run: |
pull_request_base_main=$(expr "${{ github.event.pull_request.base.ref }}" = "main")

# For PRs against the main branch, the changelog file name should match
# the PR number
if [ pull_request_base_main ]; then
enforce_matching=1
changelog_file_path=".changelog/${{ github.event.pull_request.number }}.txt"
else
changelog_file_path=".changelog/*(_)+([[:digit:]]).txt"
fi

# Fail status check if non-zero exit code is returned
./scripts/changelog-check.sh ${changelog_file_path} ${enforce_matching}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ cover.out
demo-deployment
bin
pkg/bin
go-changelog/
27 changes: 27 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,33 @@ endif
test:
go test ./...

.PHONY: changelog
changelog:
ifeq (, $(shell which changelog-build))
@go install github.com/hashicorp/go-changelog/cmd/changelog-build@latest
endif
ifeq (, $(LAST_RELEASE_GIT_TAG))
@echo "Please set the LAST_RELEASE_GIT_TAG environment variable to generate a changelog section of notes since the last release."
else
changelog-build -last-release ${LAST_RELEASE_GIT_TAG} -entries-dir .changelog/ -changelog-template .changelog/changelog.tmpl -note-template .changelog/release-note.tmpl -this-release $(shell git rev-parse HEAD)
endif

.PHONY: changelog-entry
changelog-entry:
ifeq (, $(shell which changelog-entry))
@go install github.com/hashicorp/go-changelog/cmd/changelog-entry@latest
endif
changelog-entry -dir .changelog

.PHONY: changelog-check
changelog-check:
ifeq (, $(shell which changelog-check))
@rm -rf go-changelog
@git clone -b changelog-check https://github.com/mikemorris/go-changelog
@cd go-changelog && go install ./cmd/changelog-check
endif
@changelog-check

# Run controller tests
.PHONY: ctrl-test
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
Expand Down
29 changes: 29 additions & 0 deletions changelog-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
mikemorris marked this conversation as resolved.
Show resolved Hide resolved

set -e

changelog_file_path=$1

if [ -n "$2" ]; then
enforce_matching_pull_request_number="matching this PR number "
fi

# Check if there is a diff matching the expected changelog file path
changelog_files=$(git --no-pager diff --name-only HEAD "$(git merge-base HEAD "origin/main")" -- ${changelog_file_path})

# Exit with error if no changelog entry is found
if [ -z "$changelog_files" ]; then
echo "Did not find a changelog entry ${enforce_matching_pull_request_number}and the 'pr/no-changelog' label was not applied. Reference - https://github.com/hashicorp/consul/pull/8387"
exit 1
fi

# Validate format with make changelog-check, exit with error if any note has an
# invalid format
for file in $changelog_files; do
if ! cat $file | make changelog-check; then
echo "Found a changelog entry ${enforce_matching_pull_request_number}but the note format in ${file} was invalid."
exit 1
fi
done

echo "Found valid changelog entry!"
30 changes: 30 additions & 0 deletions scripts/changelog-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

set -e
shopt -s extglob

changelog_file_path=$1

if [ ! -z "$2" ]; then
enforce_matching_pull_request_number="matching this PR number "
fi

# Check if there is a diff matching the expected changelog file path
changelog_files=$(git --no-pager diff --name-only HEAD "$(git merge-base HEAD "origin/main")" -- ${changelog_file_path})

# Exit with error if no changelog entry is found
if [ -z "$changelog_files" ]; then
echo "Did not find a changelog entry ${enforce_matching_pull_request_number}and the 'pr/no-changelog' label was not applied. Reference - https://github.com/hashicorp/consul/pull/8387"
exit 1
fi

# Validate format with make changelog-check, exit with error if any note has an
# invalid format
for file in $changelog_files; do
if ! cat $file | make changelog-check; then
echo "Found a changelog entry ${enforce_matching_pull_request_number}but the note format in ${file} was invalid."
exit 1
fi
done

echo "Found valid changelog entry!"