Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add go-changelog #882

Merged
merged 7 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
47 changes: 47 additions & 0 deletions .changelog/changelog.tmpl
Original file line number Diff line number Diff line change
@@ -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 changes: 3 additions & 0 deletions .changelog/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/terraform-provider-helm/issues/{{- .Issue -}})]{{end}}
{{- end -}}
111 changes: 111 additions & 0 deletions .github/workflows/CHANGELOG_GUIDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# How To Use
BBBmau marked this conversation as resolved.
Show resolved Hide resolved

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
```

35 changes: 35 additions & 0 deletions .github/workflows/changelog-checker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This workflow checks that there is either a 'pr/no-changelog' label applied to a PR
BBBmau marked this conversation as resolved.
Show resolved Hide resolved
# or there is a .changelog/<pr number>.txt file associated with a PR for a 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
21 changes: 20 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 gen/changelog LAST_RELEASE=gitref THIS_RELEASE=gitref
BBBmau marked this conversation as resolved.
Show resolved Hide resolved
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) | \
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ require (
sigs.k8s.io/yaml v1.3.0
)

require github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
BBBmau marked this conversation as resolved.
Show resolved Hide resolved

require (
cloud.google.com/go v0.99.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
Expand Down Expand Up @@ -143,7 +145,6 @@ require (
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/cobra v1.4.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect
github.com/vmihailenco/tagparser v0.1.1 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
Expand Down