Skip to content

Commit

Permalink
Merge pull request #69 from doitintl/changelog
Browse files Browse the repository at this point in the history
Add changelog generation plumbing
  • Loading branch information
stepanstipl committed Nov 11, 2020
2 parents bb07413 + cef1a78 commit 43b48ea
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ jobs:
scripts/alpine-setup.sh
GOOS=darwin GOARCH=amd64 make all
GOOS=linux GOARCH=amd64 make all
make changelog
shell: sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Archive release artifacts
uses: actions/upload-artifact@v1
with:
Expand Down Expand Up @@ -69,6 +72,7 @@ jobs:
release_name: Release ${{ steps.get_tag.outputs.git_tag }}
draft: true
prerelease: false
body_path: ./release-artifacts/changelog.md
- name: Upload Release Asset - Mac
id: upload-release-asset-mac
uses: actions/upload-release-asset@v1
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ RELEASE_DIR ?= release-artifacts
PACKED_DIR ?= $(BIN_DIR)/packed
CMDS ?= $(shell ls $(CMD_DIR))
BINS ?= $(addsuffix -$(GOOS)-$(GOARCH),$(addprefix $(BIN_DIR)/,$(CMDS)))
CHANGELOG ?= changelog.md

BIN_ARCH ?= $(GOOS)-$(GOARCH)
RELEASE_SUFFIX ?= $(GIT_REF)-$(BIN_ARCH).tar.gz
Expand Down Expand Up @@ -118,3 +119,8 @@ clean:
rm -rf $(GENERATE_DIR)
rm -rf $(BIN_DIR)
.PHONY: clean

## Generate Changelog based on PRs
changelog:
OUTPUT_FILE=$(RELEASE_DIR)/$(CHANGELOG) ./scripts/github-changelog.sh
.PHONY: changelog
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,31 @@ Use imperative, present tense (Add, not ~Added~), capitalize first letter of
summary, no dot at the and. The body and footer are optional. Relevant GitHub
issues should be referenced in the footer in the form `Fixes #123, fixes #456`.

### Changelog

Changelog is generated automatically based on merged PRs using
[changelog-gen][chlg-gen]. Template can be found in `scripts/changelog.tmpl`.

PRs are categorized based on their labels, into following sections:
- Announcements - `announcement` label
- Breaking Changes - `breaking-change` label
- Features - `feature` label
- Changes - `change` label
- Fixes - `fix` label
- Internal/Other - everything else

PR can be excluded from changelog with `no-release-note` label. PR title is
used by default, however, the copy can be customized by including following
block in the PR body:

~~~
```release-note
This is an example release note!
```
~~~

[chlg-gen]: https://github.com/paultyng/changelog-gen

## Issues and Contributions

Please open any issues and/or PRs against github.com/doitintl/kube-no-trouble repository.
Expand Down
3 changes: 3 additions & 0 deletions scripts/alpine-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ UPX_VERSION="3.96"
OPA_VERSION="0.22.0"

apk add --update --no-cache \
curl \
git \
jq \
make \
tar

Expand All @@ -20,3 +22,4 @@ wget -q -O "/usr/local/bin/opa" "https://github.com/open-policy-agent/opa/releas
chmod +x "/usr/local/bin/opa"

go get github.com/rakyll/statik
go get github.com/paultyng/changelog-gen
68 changes: 68 additions & 0 deletions scripts/changelog.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{{- $announcements := newStringList -}}
{{- $breaking := newStringList -}}
{{- $features := newStringList -}}
{{- $changes := newStringList -}}
{{- $fixes := newStringList -}}
{{- $other := newStringList -}}

{{- range . -}}
{{if has "announcement" .Labels -}}
{{$features = append $announcements (renderReleaseNote .) -}}
{{else if .BreakingChange -}}
{{$breaking = append $breaking (renderReleaseNote .) -}}
{{else if has "feature" .Labels -}}
{{$features = append $features (renderReleaseNote .) -}}
{{else if has "change" .Labels -}}
{{$fixes = append $changes (renderReleaseNote .) -}}
{{else if has "fix" .Labels -}}
{{$fixes = append $fixes (renderReleaseNote .) -}}
{{else -}}
{{$other = append $other (renderReleaseNote .) -}}
{{end -}}
{{- end -}}

{{- if gt (len $announcements) 0 -}}
{{range $announcements | sortAlpha -}}
{{. }}
{{end -}}
{{- end -}}

{{- if gt (len $breaking) 0 -}}
**Breaking Changes**:

{{range $breaking | sortAlpha -}}
* {{. }}
{{end -}}
{{- end -}}

{{- if gt (len $features) 0}}
**Features**:

{{range $features | sortAlpha -}}
* {{. }}
{{end -}}
{{- end -}}

{{- if gt (len $changes) 0}}
**Changes**:

{{range $changes | sortAlpha -}}
* {{. }}
{{end -}}
{{- end -}}

{{- if gt (len $fixes) 0}}
**Fixes**:

{{range $fixes | sortAlpha -}}
* {{. }}
{{end -}}
{{- end -}}

{{- if gt (len $other) 0}}
**Internal/Other**:

{{range $other | sortAlpha -}}
* {{. }}
{{end -}}
{{- end -}}
18 changes: 18 additions & 0 deletions scripts/github-changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env sh
# Set strict error checking
set -emou pipefail

GH_ORG="doitintl"
GH_REPO="kube-no-trouble"
CHANGELOG_TEMPLATE="./scripts/changelog.tmpl"
OUTPUT_FILE="${OUTPUT_FILE:="./changelog.md"}"

RELEASE_SHA="$(curl --silent "https://api.github.com/repos/${GH_ORG}/${GH_REPO}/releases/latest" \
| jq -r '.target_commitish')"
MASTER_SHA="$(git rev-parse origin/master)"

echo "- Generating changelog (${OUTPUT_FILE})"

changelog-gen -changelog "${CHANGELOG_TEMPLATE}" \
-owner "${GH_ORG}" -repo "${GH_REPO}" \
"${RELEASE_SHA}" "${MASTER_SHA}" | tee "${OUTPUT_FILE}"

0 comments on commit 43b48ea

Please sign in to comment.