Skip to content

Commit cf5eaf8

Browse files
authored
Add changelog (#12)
1 parent 92e6e34 commit cf5eaf8

File tree

5 files changed

+124
-0
lines changed

5 files changed

+124
-0
lines changed

.changelog/changelog.tmpl

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{{- if index .NotesByType "breaking-change" -}}
2+
BREAKING CHANGES:
3+
4+
{{range index .NotesByType "breaking-change" -}}
5+
* {{ template "note" . }}
6+
{{ end -}}
7+
{{- end -}}
8+
9+
{{- if .NotesByType.security }}
10+
SECURITY:
11+
12+
{{range .NotesByType.security -}}
13+
* {{ template "note" . }}
14+
{{ end -}}
15+
{{- end -}}
16+
17+
{{- if .NotesByType.feature }}
18+
FEATURES:
19+
20+
{{range .NotesByType.feature -}}
21+
* {{ template "note" . }}
22+
{{ end -}}
23+
{{- end -}}
24+
25+
{{- $improvements := combineTypes .NotesByType.improvement .NotesByType.enhancement -}}
26+
{{- if $improvements }}
27+
IMPROVEMENTS:
28+
29+
{{range $improvements | sort -}}
30+
* {{ template "note" . }}
31+
{{ end -}}
32+
{{- end -}}
33+
34+
{{- if .NotesByType.deprecation }}
35+
DEPRECATIONS:
36+
37+
{{range .NotesByType.deprecation -}}
38+
* {{ template "note" . }}
39+
{{ end -}}
40+
{{- end -}}
41+
42+
{{- if .NotesByType.bug }}
43+
BUG FIXES:
44+
45+
{{range .NotesByType.bug -}}
46+
* {{ template "note" . }}
47+
{{ end -}}
48+
{{- end -}}
49+
50+
{{- if .NotesByType.note }}
51+
NOTES:
52+
53+
{{range .NotesByType.note -}}
54+
* {{ template "note" . }}
55+
{{ end -}}
56+
{{- end -}}
57+

.changelog/note.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{{- define "note" -}}
2+
{{.Body}}{{if not (stringHasPrefix .Issue "_")}} [[GH-{{- .Issue -}}](https://github.com/hashicorp/consul-dataplane/pull/{{- .Issue -}})]{{end}}
3+
{{- end -}}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# This workflow checks that there is either a 'pr/no-changelog' label applied to a PR
2+
# or there is a .changelog/<pr number>.txt file associated with a PR for a changelog entry
3+
4+
name: Changelog Checker
5+
6+
on:
7+
pull_request:
8+
types: [opened, synchronize, labeled]
9+
# Runs on PRs to main and all release branches
10+
branches:
11+
- main
12+
- release/*
13+
14+
jobs:
15+
# checks that a .changelog entry is present for a PR
16+
changelog-check:
17+
# If there a `pr/no-changelog` label we ignore this check.
18+
if: "! contains(github.event.pull_request.labels.*.name, 'pr/no-changelog')"
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- uses: actions/checkout@v2
23+
with:
24+
ref: ${{ github.event.pull_request.head.sha }}
25+
fetch-depth: 0 # by default the checkout action doesn't checkout all branches
26+
- name: Check for changelog entry in diff
27+
run: |
28+
pull_request_base_main=$(expr "${{ github.event.pull_request.base.ref }}" = "main")
29+
30+
# check if there is a diff in the .changelog directory
31+
# for PRs against the main branch, the changelog file name should match the PR number
32+
if [ pull_request_base_main ]; then
33+
enforce_matching_pull_request_number="matching this PR number "
34+
changelog_file_path=".changelog/${{ github.event.pull_request.number }}.txt"
35+
else
36+
changelog_file_path=".changelog/*.txt"
37+
fi
38+
39+
changelog_files=$(git --no-pager diff --name-only HEAD "$(git merge-base HEAD "origin/main")" -- ${changelog_file_path})
40+
41+
# If we do not find a file in .changelog/, we fail the check
42+
if [ -z "$changelog_files" ]; then
43+
# Fail status check when no .changelog entry was found on the PR
44+
echo "Did not find a .changelog entry ${enforce_matching_pull_request_number}and the 'pr/no-changelog' label was not applied."
45+
exit 1
46+
else
47+
echo "Found .changelog entry in PR!"
48+
fi

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 0.1.0-beta (Unreleased)
2+
3+
* Initial release.

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,16 @@ copy-bootstrap-config:
9696
.PHONY: unit-tests
9797
unit-tests:
9898
go test ./...
99+
100+
.PHONY: changelog
101+
changelog:
102+
ifdef LAST_RELEASE_GIT_TAG
103+
changelog-build \
104+
-last-release $(LAST_RELEASE_GIT_TAG) \
105+
-entries-dir .changelog/ \
106+
-changelog-template .changelog/changelog.tmpl \
107+
-note-template .changelog/note.tmpl \
108+
-this-release $(REVISION)
109+
else
110+
$(error Cannot generate changelog without LAST_RELEASE_GIT_TAG)
111+
endif

0 commit comments

Comments
 (0)