forked from cloudflare/cloudflare-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
workflows: add more automation for changelogs
- Loading branch information
1 parent
e103aee
commit 2506863
Showing
13 changed files
with
469 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Changelog check | ||
on: [pull_request_target] | ||
|
||
jobs: | ||
changelog-check: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: ^1.17 | ||
- run: make tools | ||
- run: go run tools/cmd/changelog-check/main.go ${{ github.event.pull_request.number }} | ||
env: | ||
GITHUB_OWNER: cloudflare | ||
GITHUB_REPO: cloudflare-go | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: Add CHANGELOG for dependabot changes | ||
on: pull_request_target | ||
permissions: | ||
pull-requests: write | ||
issues: write | ||
repository-projects: write | ||
contents: write | ||
jobs: | ||
dependabot: | ||
runs-on: ubuntu-latest | ||
if: ${{ github.event.pull_request.user.login == 'dependabot[bot]' }} | ||
steps: | ||
- name: Fetch dependabot metadata | ||
id: dependabot-metadata | ||
uses: dependabot/[email protected] | ||
- uses: actions/checkout@v3 | ||
- run: | | ||
gh pr checkout $PR_URL | ||
cat << EOF > .changelog/$PR_NUMBER.txt | ||
\`\`\`release-note:dependency | ||
provider: bumps $DEP_NAME from $DEP_PREV_VERSION to $DEP_NEXT_VERSION | ||
\`\`\` | ||
EOF | ||
git config user.name github-actions[bot] | ||
git config user.email github-actions[bot]@users.noreply.github.com | ||
git add .changelog/$PR_NUMBER.txt | ||
git commit -m "add CHANGELOG for #$PR_NUMBER" | ||
git push | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
PR_URL: ${{ github.event.pull_request.html_url }} | ||
PR_NUMBER: ${{ github.event.pull_request.number }} | ||
DEP_NAME: ${{ steps.dependabot-metadata.outputs.dependency-names }} | ||
DEP_PREV_VERSION: ${{ steps.dependabot-metadata.outputs.previous-version }} | ||
DEP_NEXT_VERSION: ${{ steps.dependabot-metadata.outputs.new-version }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Generate CHANGELOG | ||
on: | ||
pull_request_target: | ||
types: [closed] | ||
workflow_dispatch: | ||
jobs: | ||
GenerateChangelog: | ||
if: github.event.pull_request.merged || github.event_name == 'workflow_dispatch' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- run: cd tools && go install github.com/hashicorp/go-changelog/cmd/changelog-build | ||
- run: ./scripts/generate-changelog.sh | ||
- run: | | ||
if [[ `git status --porcelain` ]]; then | ||
if ${{github.event_name == 'workflow_dispatch'}}; then | ||
MSG="Update CHANGELOG.md (Manual Trigger)" | ||
else | ||
MSG="Update CHANGELOG.md for #${{ github.event.pull_request.number }}" | ||
fi | ||
git config --local user.email [email protected] | ||
git config --local user.name changelogbot | ||
git add CHANGELOG.md | ||
git commit -m "$MSG" | ||
git push | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
on: | ||
pull_request_target: | ||
types: [closed] | ||
name: Add merged PR and linked issues to current milestone of target branch | ||
jobs: | ||
add-merged-to-current-milestone: | ||
if: github.event.pull_request.merged | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.event.pull_request.base.ref }} | ||
- id: get-current-milestone | ||
run: | | ||
echo ::set-output name=current_milestone::v$(head -1 CHANGELOG.md | cut -d " " -f 2) | ||
- run: echo ${{ steps.get-current-milestone.outputs.current_milestone }} | ||
- id: get-milestone-id | ||
run: | | ||
echo ::set-output name=milestone_id::$(curl -H "Authorization: Bearer ${{secrets.GITHUB_TOKEN}}" https://api.github.com/repos/${{ github.repository_owner }}/${{ github.event.repository.name }}/milestones | jq 'map(select(.title == "${{ steps.get-current-milestone.outputs.current_milestone }}"))[0].number') | ||
- run: echo ${{ steps.get-milestone-id.outputs.milestone_id }} | ||
- uses: breathingdust/current-milestone-action@v4 | ||
with: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
pull_number: ${{ github.event.pull_request.number }} | ||
milestone_number: ${{ steps.get-milestone-id.outputs.milestone_id }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.46.0 (Unreleased) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
## Changelog Process | ||
|
||
We use the [go-changelog](https://github.com/hashicorp/go-changelog) to generate and update the changelog from files created in the `.changelog/` directory. It is important that when you raise your Pull Request, there is a changelog entry which describes the changes your contribution makes. Not all changes require an entry in the CHANGELOG, guidance follows on what changes do. | ||
|
||
### Changelog Format | ||
|
||
The changelog format requires an entry in the following format, where HEADER corresponds to the changelog category, and the entry is the changelog entry itself. The entry should be included in a file in the `.changelog` directory with the naming convention `{PR-NUMBER}.txt`. For example, to create a changelog entry for pull request 1234, there should be a file named `.changelog/1234.txt`. | ||
|
||
````markdown | ||
```release-note:{HEADER} | ||
{ENTRY} | ||
``` | ||
```` | ||
|
||
If a pull request should contain multiple changelog entries, then multiple blocks can be added to the same changelog file. For example: | ||
|
||
````markdown | ||
```release-note:note | ||
foo: The `broken` attribute has been deprecated. All configurations using `broken` should be updated to use the new `not_broken` attribute instead. | ||
``` | ||
|
||
```release-note:enhancement | ||
foo: Add `not_broken` attribute | ||
``` | ||
```` | ||
|
||
### Skipping changelog entries | ||
|
||
In order to skip/pass the automated checks where a CHANGELOG entry is not required, apply the `workflow/skip-changelog-entry` label. | ||
|
||
### Pull Request Types to CHANGELOG | ||
|
||
The CHANGELOG is intended to show operator-impacting changes to the codebase for a particular version. If every change or commit to the code resulted in an entry, the CHANGELOG would become less useful for operators. The lists below are general guidelines and examples for when a decision needs to be made to decide whether a change should have an entry. | ||
|
||
#### Changes that should have a CHANGELOG entry | ||
|
||
##### Resource and provider bug fixes | ||
|
||
A new bug entry should use the `release-note:bug` header and have a prefix indicating the file/service it corresponds to, a colon, then followed by a brief summary. | ||
|
||
````markdown | ||
```release-note:bug | ||
foo: Fix 'thing' being optional | ||
``` | ||
```` | ||
|
||
##### Resource and provider enhancements | ||
|
||
A new enhancement entry should use the `release-note:enhancement` header and have a prefix indicating the file/service it corresponds to, a colon, then followed by a brief summary. | ||
|
||
````markdown | ||
```release-note:enhancement | ||
foo: Add new capability | ||
``` | ||
```` | ||
|
||
##### Deprecations | ||
|
||
A breaking-change entry should use the `release-note:note` header and have a prefix indicating the file/service it corresponds to, a colon, then followed by a brief summary. | ||
|
||
````markdown | ||
```release-note:note | ||
foo: X attribute is being deprecated in favor of the new Y attribute | ||
``` | ||
```` | ||
|
||
##### Breaking Changes and Removals | ||
|
||
A breaking-change entry should use the `release-note:breaking-change` header and have a prefix indicating the file/service it corresponds to, a colon, then followed by a brief summary. | ||
|
||
````markdown | ||
```release-note:breaking-change | ||
foo: Resource no longer works for 'EXAMPLE' parameters | ||
``` | ||
```` | ||
|
||
#### Changes that may have a CHANGELOG entry | ||
|
||
Dependency updates: If the update contains relevant bug fixes or enhancements that affect operators, those should be called out. | ||
Any changes which do not fit into the above categories but warrant highlighting. | ||
|
||
````markdown | ||
```release-note:note | ||
foo: Example resource now does X slightly differently | ||
``` | ||
|
||
```release-note:dependency | ||
`foo` v0.1.0 => v0.1.1 | ||
``` | ||
```` | ||
|
||
#### Changes that should _not_ have a CHANGELOG entry | ||
|
||
- Resource and provider documentation updates | ||
- Testing updates | ||
- Code refactoring (context dependant) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{{- if index .NotesByType "breaking-change" }} | ||
BREAKING CHANGES: | ||
|
||
{{range index .NotesByType "breaking-change" -}} | ||
{{ template "note" .}} | ||
{{ end -}} | ||
{{- end -}} | ||
|
||
{{- if .NotesByType.note }} | ||
NOTES: | ||
|
||
{{range .NotesByType.note -}} | ||
{{ template "note" .}} | ||
{{ end -}} | ||
{{- end -}} | ||
|
||
{{- if .NotesByType.enhancement }} | ||
ENHANCEMENTS: | ||
|
||
{{range .NotesByType.enhancement | sort -}} | ||
{{ template "note" .}} | ||
{{ end -}} | ||
{{- end -}} | ||
|
||
{{- if .NotesByType.bug }} | ||
BUG FIXES: | ||
|
||
{{range .NotesByType.bug | sort -}} | ||
{{ template "note" . }} | ||
{{ end -}} | ||
{{- end -}} | ||
|
||
{{- if .NotesByType.dependency }} | ||
DEPENDENCIES: | ||
|
||
{{range .NotesByType.dependency | sort -}} | ||
{{ template "note" . }} | ||
{{ end -}} | ||
{{- end -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/bin/bash | ||
|
||
set -o errexit | ||
set -o nounset | ||
|
||
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
__parent="$(dirname "$__dir")" | ||
|
||
CHANGELOG_FILE_NAME="CHANGELOG.md" | ||
CHANGELOG_TMP_FILE_NAME="CHANGELOG.tmp" | ||
TARGET_SHA=$(git rev-parse HEAD) | ||
PREVIOUS_RELEASE_SHA=$(git rev-list -n 1 $(git describe --abbrev=0 --match='v*.*.*' --tags)) | ||
|
||
if [ $TARGET_SHA == $PREVIOUS_RELEASE_SHA ]; then | ||
echo "Nothing to do" | ||
exit 0 | ||
fi | ||
|
||
PREVIOUS_CHANGELOG=$(sed -n -e "/## $(git describe --abbrev=0 --match='v*.*.*' --tags | tr -d v)/,\$p" $__parent/$CHANGELOG_FILE_NAME) | ||
|
||
if [ -z "$PREVIOUS_CHANGELOG" ] | ||
then | ||
echo "Unable to locate previous changelog contents." | ||
exit 1 | ||
fi | ||
|
||
CHANGELOG=$($(go env GOPATH)/bin/changelog-build -this-release $TARGET_SHA \ | ||
-last-release $PREVIOUS_RELEASE_SHA \ | ||
-git-dir $__parent \ | ||
-entries-dir .changelog \ | ||
-changelog-template $__dir/changelog.tmpl \ | ||
-note-template $__dir/release-note.tmpl) | ||
|
||
if [ -z "$CHANGELOG" ] | ||
then | ||
echo "No changelog generated." | ||
exit 0 | ||
fi | ||
|
||
rm -f $CHANGELOG_TMP_FILE_NAME | ||
|
||
sed -n -e "1{/## /p;}" $__parent/$CHANGELOG_FILE_NAME > $CHANGELOG_TMP_FILE_NAME | ||
echo "$CHANGELOG" >> $CHANGELOG_TMP_FILE_NAME | ||
echo >> $CHANGELOG_TMP_FILE_NAME | ||
echo "$PREVIOUS_CHANGELOG" >> $CHANGELOG_TMP_FILE_NAME | ||
|
||
cp $CHANGELOG_TMP_FILE_NAME $CHANGELOG_FILE_NAME | ||
|
||
rm $CHANGELOG_TMP_FILE_NAME | ||
|
||
echo "Successfully generated changelog." | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{{- define "note" -}} | ||
* {{.Body}} ([#{{- .Issue -}}](https://github.com/cloudflare/cloudflare-go/issues/{{- .Issue -}})) | ||
{{- end -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//go:build tools | ||
// +build tools | ||
|
||
package tools | ||
|
||
//go:generate go install github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs | ||
//go:generate go install github.com/bflad/tfproviderlint/cmd/tfproviderlintx | ||
//go:generate go install github.com/client9/misspell/cmd/misspell | ||
//go:generate go install github.com/golangci/golangci-lint/cmd/golangci-lint | ||
//go:generate go install github.com/hashicorp/go-changelog/cmd/changelog-build | ||
//go:generate go install github.com/google/go-github/github | ||
//go:generate go install golang.org/x/oauth2 | ||
|
||
import ( | ||
_ "github.com/bflad/tfproviderlint/cmd/tfproviderlintx" | ||
_ "github.com/client9/misspell/cmd/misspell" | ||
_ "github.com/golangci/golangci-lint/cmd/golangci-lint" | ||
_ "github.com/google/go-github/github" | ||
_ "github.com/hashicorp/go-changelog/cmd/changelog-build" | ||
_ "github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs" | ||
_ "golang.org/x/oauth2" | ||
) |
Oops, something went wrong.