Skip to content

Commit

Permalink
automation - add changelog and release automation (#86)
Browse files Browse the repository at this point in the history
Add a new Github workflow for releases that automates
the generation of a draft GH release with changelog notes.

Pull requests will be required to add new file to at
.changelog/<pr_number>.txt with a changelog message or
label with skip-changelog to bypass the check. See
CONTRIBUTING.md for more details.

This backfills the .changelog directory with entries
for changes since v0.14.0.

The original CHANGELOG.md file has been moved into
.changelog/.pre-0.15.0-changelog.md to preserve this information.
  • Loading branch information
andrewkroh authored Apr 3, 2024
1 parent 69177af commit 11a55b9
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 31 deletions.
44 changes: 13 additions & 31 deletions CHANGELOG.md → .changelog/.pre-0.15.0-changelog.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
# Change Log
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Added
> [!NOTE]
> This file contains the historical release notes for versions prior to v0.15.0.
> It is no longer updated. Please see the GitHub release notes for newer
> releases.
### Changed

- Update build to use Go 1.22. [#78](https://github.com/elastic/stream/pull/78)

### Fixed

- Check for nil packet and transport layer when streaming pcap files [#88](https://github.com/elastic/stream/pull/88)

### Removed
This project adheres to [Semantic Versioning](http://semver.org/).

## [0.14.0]

Expand All @@ -26,29 +17,14 @@ This project adheres to [Semantic Versioning](http://semver.org/).

- Update build to use Go 1.20. [#75](https://github.com/elastic/stream/pull/75)

### Fixed

### Removed

## [0.13.0]

### Added

- Added support for azure eventhub output: [#58](https://github.com/elastic/stream/pull/58)
- Added `exit-on-unmatched-rule` flag: [#63](https://github.com/elastic/stream/pull/63)
- Added sequences to the http server: [#64](https://github.com/elastic/stream/pull/64)

### Changed

### Fixed

### Removed

## [0.12.0]

### Added

- Added support for azure eventhub output: [#58](https://github.com/elastic/stream/pull/58)

## [0.11.0]

### Added
Expand Down Expand Up @@ -148,7 +124,12 @@ no longer contain a trailing newline. [#31](https://github.com/elastic/stream/pu
- Added pcap and log file inputs.
- Added udp, tcp, and tls outputs.

[Unreleased]: https://github.com/elastic/stream/compare/v0.8.0...HEAD
[0.14.0]: https://github.com/elastic/stream/releases/tag/v0.14.0
[0.13.0]: https://github.com/elastic/stream/releases/tag/v0.13.0
[0.11.0]: https://github.com/elastic/stream/releases/tag/v0.11.0
[0.10.0]: https://github.com/elastic/stream/releases/tag/v0.10.0
[0.9.1]: https://github.com/elastic/stream/releases/tag/v0.9.1
[0.9.0]: https://github.com/elastic/stream/releases/tag/v0.9.0
[0.8.0]: https://github.com/elastic/stream/releases/tag/v0.8.0
[0.7.0]: https://github.com/elastic/stream/releases/tag/v0.7.0
[0.6.2]: https://github.com/elastic/stream/releases/tag/v0.6.2
Expand All @@ -160,3 +141,4 @@ no longer contain a trailing newline. [#31](https://github.com/elastic/stream/pu
[0.2.0]: https://github.com/elastic/stream/releases/tag/v0.2.0
[0.1.0]: https://github.com/elastic/stream/releases/tag/v0.1.0
[0.0.1]: https://github.com/elastic/stream/releases/tag/v0.0.1

3 changes: 3 additions & 0 deletions .changelog/78.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
build: Releases are now built with Go 1.22.
```
3 changes: 3 additions & 0 deletions .changelog/88.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
pcap input: Check for nil packet and transport layer when streaming pcap files.
```
43 changes: 43 additions & 0 deletions .github/release/changelog.gotmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{{- if .NotesByType.note -}}
NOTES:
{{range .NotesByType.note -}}
* {{ template "note" .}}
{{ end -}}
{{- end -}}

{{- if .NotesByType.deprecation -}}
DEPRECATIONS:
{{range .NotesByType.deprecation -}}
* {{ template "note" .}}
{{ end -}}
{{- end -}}

{{- if index .NotesByType "breaking-change" -}}
BREAKING CHANGES:
{{range index .NotesByType "breaking-change" -}}
* {{ template "note" .}}
{{ end -}}
{{- end -}}

{{- $features := combineTypes .NotesByType.feature (index .NotesByType "new-resource" ) (index .NotesByType "new-datasource") (index .NotesByType "new-data-source") -}}
{{- if $features }}
FEATURES:
{{range $features | sort -}}
* {{ template "note" . }}
{{ end -}}
{{- end -}}

{{- $improvements := combineTypes .NotesByType.improvement .NotesByType.enhancement -}}
{{- if $improvements }}
IMPROVEMENTS:
{{range $improvements | sort -}}
* {{ template "note" . }}
{{ end -}}
{{- end -}}

{{- if .NotesByType.bug }}
BUG FIXES:
{{range .NotesByType.bug -}}
* {{ template "note" . }}
{{ end -}}
{{- end -}}
3 changes: 3 additions & 0 deletions .github/release/release-note.gotmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{- define "note" -}}
{{if eq "new-resource" .Type}}**New Resource:** {{else if eq "new-datasource" .Type}}**New Data Source:** {{ end }}{{.Body}} ([GH-{{- .Issue -}}])
{{- end -}}
40 changes: 40 additions & 0 deletions .github/scripts/check-changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash
set -uo pipefail

if [[ -z "${PR_NUMBER}" ]]; then
echo "PR_NUMBER must be set."
exit 1
fi

if [[ -z "${BASE_REF}" ]]; then
echo "BASE_REF must be set."
exit 1
fi

docs_url="https://github.com/GoogleCloudPlatform/magic-modules/blob/2834761fec3acbf35cacbffe100530f82eada650/.ci/RELEASE_NOTES_GUIDE.md#expected-format"

# Version of https://github.com/hashicorp/go-changelog.
go_changelog_version=ba40b3a
go_changelog_check="go run github.com/hashicorp/go-changelog/cmd/changelog-check@${go_changelog_version}"

expected_changelog_file=.changelog/${PR_NUMBER}.txt

# Verify file is present.
if [ ! -e "${expected_changelog_file}" ]; then
echo "Changelog file missing at ${expected_changelog_file}.
Please add a changelog entry following the format described [here](${docs_url}).
If this change does not require a changelog entry then label the pull request
with skip-changelog.
" >> $GITHUB_STEP_SUMMARY
exit 1
fi

# Check the format.
if ! ${go_changelog_check} "${expected_changelog_file}"; then
echo "Changelog format is invalid. See build log." >> $GITHUB_STEP_SUMMARY
exit 1
fi

echo "Changelog is valid." >> $GITHUB_STEP_SUMMARY
24 changes: 24 additions & 0 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: changelog

on:
pull_request:
types: [opened, synchronize, labeled, unlabeled]
branches:
- main

permissions:
contents: read

jobs:
check:
if: "!contains(github.event.pull_request.labels.*.name, 'skip-changelog')"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: changelog
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
BASE_REF: ${{ github.event.pull_request.base.ref }}
run: .github/scripts/check-changelog.sh
51 changes: 51 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
name: release

on:
workflow_dispatch:
inputs:
version:
description: Tag name (e.g. v1.2.3) for this version (does not need to exist).
required: true
type: string
last_release:
description: Last release tag.
required: true
type: string

permissions:
contents: read

jobs:
draft:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Need full history.

- name: release notes
run: >-
go run github.com/hashicorp/go-changelog/cmd/changelog-build@ba40b3a
-changelog-template .github/release/changelog.gotmpl
-note-template .github/release/release-note.gotmpl
-entries-dir ./.changelog
-last-release "${{ inputs.last_release }}"
-this-release HEAD | tee /tmp/release-notes.txt
cat << EOF >> /tmp/release-notes.txt
DOWNLOAD:
- \`docker pull docker.elastic.co/observability/stream:${{ inputs.version }}\`
EOF
- name: draft GH release
env:
GH_TOKEN: ${{ github.token }}
run: >-
gh release create "${{ inputs.version }}"
--draft
--notes-file /tmp/release-notes.txt
--title "${{ inputs.version }}"
46 changes: 46 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Contributing

Pull requests are welcomed. You must

- Sign the Elastic [Contributor License Agreement](https://www.elastic.co/contributor-agreement).
- Include a changelog entry at `.changelog/{pr-number}.txt` with your pull
request. Or label the PR with `skip-changelog` if it is a non-user facing
change (test fixes, CI changes, etc.).
- Include tests that demonstrate the change is working.

The `.changelog/{pr-number}.txt` changelog file must follow a Markdown code
block format like

~~~
```release-note:enhancement
webhook: Added support for HTTP response headers.
```
~~~

You must use one of these types:

- `release-note:enhancement`
- `release-note:bug`
- `release-note:deprecation`
- `release-note:breaking-change`
- `release-note:new-resource`

The changelog file may contain more than one Markdown code block if there is
more than one change.

~~~
```release-note:enhancement
http mock server: Added minify_json template helper function for minifying static JSON.
```
```release-note:bug
http mock server: Fixed YAML unmarshaling of numbers.
```
~~~

## Releasing

To create a new release, use the release workflow in GitHub actions. This will create a new draft
release in GitHub releases with a changelog. After the job completes, review the draft and if
everything is correct, publish the release. When the release is published, GitHub will create the
git tag.

0 comments on commit 11a55b9

Please sign in to comment.