Add go-changelog (#882)

* add changelog-build changelog-entry

* add github action for go-changelog

* tidy

* vendor

* small changelog details
This commit is contained in:
Mauricio Alvarez Leon 2022-06-14 15:24:18 -07:00 committed by GitHub
parent c97454efc5
commit 326ed12f43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 217 additions and 1 deletions

47
.changelog/changelog.tmpl Normal file
View file

@ -0,0 +1,47 @@
{{- 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.feature }}
FEATURES:
{{range .NotesByType.feature -}}
* {{ template "note" . }}
{{ end -}}
{{- end -}}
{{- if .NotesByType.improvement }}
IMPROVEMENTS:
{{range .NotesByType.improvement -}}
* {{ template "note" . }}
{{ end -}}
{{- end -}}
{{- if .NotesByType.deprecation }}
DEPRECATIONS:
{{range .NotesByType.deprecation -}}
* {{ template "note" . }}
{{ end -}}
{{- end -}}
{{- if .NotesByType.bug }}
BUG FIXES:
{{range .NotesByType.bug -}}
* {{ template "note" . }}
{{ end -}}
{{- end -}}

3
.changelog/note.tmpl Normal file
View file

@ -0,0 +1,3 @@
{{- define "note" -}}
{{.Body}}{{if not (stringHasPrefix .Issue "_")}} [[GH-{{- .Issue -}}](https://github.com/hashicorp/terraform-provider-helm/issues/{{- .Issue -}})]{{end}}
{{- end -}}

36
.github/workflows/changelog-checker.yml vendored Normal file
View file

@ -0,0 +1,36 @@
# 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 associated with a PR for a changelog entry
name: Changelog Entry
on:
pull_request:
types: [opened, synchronize, labeled]
# Runs on PRs to main and all release branches
branches:
- main
jobs:
# checks that a .changelog entry is present for a PR
changelog-check:
# 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
- name: Check for changelog entry in diff
run: |
# check if there is a diff in the .changelog directory
changelog_files=$(git --no-pager diff --name-only HEAD "$(git merge-base HEAD "origin/${{ github.event.pull_request.base.ref }}")" -- .changelog/${{ github.event.pull_request.number }}.txt)
# If we do not find a file in .changelog/, we fail the check
if [ -z "$changelog_files" ]; then
# Fail status check when no .changelog entry was found on the PR
echo "Did not find a .changelog entry and the 'pr/no-changelog' label was not applied. Reference - https://github.com/hashicorp/terraform-provider-helm/tree/main/.github/workflows/CHANGELOG_GUIDE.md"
exit 1
else
echo "Found .changelog entry in PR!"
fi

111
CHANGELOG_GUIDE.md Normal file
View file

@ -0,0 +1,111 @@
# How To Use
Helm Provider uses `go-changelog` to generate its changelog on release:
* https://github.com/hashicorp/go-changelog
To install, run the following commands:
```
go install github.com/hashicorp/go-changelog/cmd/changelog-build
go install github.com/hashicorp/go-changelog/cmd/changelog-entry
```
Either command can be ran with the following make command:
```
make changelog
make changelog-entry
```
## CHANGELOG entry examples
CHANGELOG entries are expected to be txt files created inside this folder
`.changelog`. The file name is expected to be the same pull request number that will
be linked when the CHANGELOG is generated. So for example, if your pull request is
\#1234, your file name would be `.changelog/1234.txt`.
While for git commit messages, we expect the leading subject to be more specific
as to the section it updates, for example a change with k8s might be:
```
builtin/k8s: Add support for feature Y
This commit adds support for feature Y....
```
The changelog entry should be more user facing friendly, so it would instead read:
~~~
```release-note:improvement
plugin/k8s: Add support for feature Y
```
~~~
Below are some examples of how to generate a CHANGELOG entry with your pull
request.
### Improvement
~~~
```release-note:improvement
server: Add new option for configs
```
~~~
### Feature
~~~
```release-note:feature
plugin/nomad: New feature integration
```
~~~
### Bug
~~~
```release-note:bug
plugin/docker: Fix broken code
```
~~~
### Multiple Entries
~~~
```release-note:bug
plugin/docker: Fix broken code
```
```release-note:bug
plugin/nomad: Fix broken code
```
```release-note:bug
plugin/k8s: Fix broken code
```
~~~
### Long Description with Markdown
~~~
```release-note:feature
cli: Lorem ipsum dolor `sit amet`, _consectetur_ adipiscing elit, **sed** do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
```
~~~
## How to generate CHANGELOG entries for release
Below is an example for running `go-changelog` to generate a collection of
entries. It will generate output that can be inserted into CHANGELOG.md.
For more information as to what each flag does, make sure to run `changelog-build -help`.
```
changelog-build -last-release v0.5.0 -entries-dir .changelog/ -changelog-template changelog.tmpl -note-template note.tmpl -this-release 86b6b38faa7c69f26f1d4c71e271cd4285daadf9
```

View file

@ -16,11 +16,30 @@ ifneq ($(origin TRAVIS_TAG), undefined)
VERSION := $(TRAVIS_TAG)
endif
# For changelog generation, default the last release to the last tag on
# any branch, and this release to just be the current branch we're on.
LAST_RELEASE?=$$(git describe --tags $$(git rev-list --tags --max-count=1))
THIS_RELEASE?=$$(git rev-parse --abbrev-ref HEAD)
default: build
build: fmtcheck
go build -v .
# expected to be invoked by make changelog LAST_RELEASE=gitref THIS_RELEASE=gitref
changelog:
@echo "Generating changelog for $(THIS_RELEASE) from $(LAST_RELEASE)..."
@echo
@changelog-build -last-release $(LAST_RELEASE) \
-entries-dir .changelog/ \
-changelog-template .changelog/changelog.tmpl \
-note-template .changelog/note.tmpl \
-this-release $(THIS_RELEASE)
changelog-entry:
@changelog-entry -dir .changelog/
test: fmtcheck
go test $(TEST) -v || exit 1
echo $(TEST) | \
@ -109,4 +128,4 @@ website-lint:
@echo "==> Checking for broken links..."
@scripts/markdown-link-check.sh "$(DOCKER)" "$(DOCKER_RUN_OPTS)" "$(DOCKER_VOLUME_OPTS)" "$(PROVIDER_DIR_DOCKER)"
.PHONY: build test testacc testrace cover vet fmt fmtcheck errcheck test-compile packages clean website-lint
.PHONY: build test testacc testrace cover vet fmt fmtcheck errcheck test-compile packages clean website-lint changelog changelog-entry