From 11a55b9c9c8d3be0fcbcc2b9f36894d317c1cedf Mon Sep 17 00:00:00 2001 From: Andrew Kroh Date: Wed, 3 Apr 2024 11:46:51 -0400 Subject: [PATCH] automation - add changelog and release automation (#86) 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/.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. --- .../.pre-0.15.0-changelog.md | 44 +++++----------- .changelog/78.txt | 3 ++ .changelog/88.txt | 3 ++ .github/release/changelog.gotmpl | 43 ++++++++++++++++ .github/release/release-note.gotmpl | 3 ++ .github/scripts/check-changelog.sh | 40 +++++++++++++++ .github/workflows/changelog.yml | 24 +++++++++ .github/workflows/release.yml | 51 +++++++++++++++++++ CONTRIBUTING.md | 46 +++++++++++++++++ 9 files changed, 226 insertions(+), 31 deletions(-) rename CHANGELOG.md => .changelog/.pre-0.15.0-changelog.md (87%) create mode 100644 .changelog/78.txt create mode 100644 .changelog/88.txt create mode 100644 .github/release/changelog.gotmpl create mode 100644 .github/release/release-note.gotmpl create mode 100755 .github/scripts/check-changelog.sh create mode 100644 .github/workflows/changelog.yml create mode 100644 .github/workflows/release.yml create mode 100644 CONTRIBUTING.md diff --git a/CHANGELOG.md b/.changelog/.pre-0.15.0-changelog.md similarity index 87% rename from CHANGELOG.md rename to .changelog/.pre-0.15.0-changelog.md index 3553a1b..c84c862 100644 --- a/CHANGELOG.md +++ b/.changelog/.pre-0.15.0-changelog.md @@ -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] @@ -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 @@ -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 @@ -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 + diff --git a/.changelog/78.txt b/.changelog/78.txt new file mode 100644 index 0000000..af816d6 --- /dev/null +++ b/.changelog/78.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +build: Releases are now built with Go 1.22. +``` diff --git a/.changelog/88.txt b/.changelog/88.txt new file mode 100644 index 0000000..cf3a7f4 --- /dev/null +++ b/.changelog/88.txt @@ -0,0 +1,3 @@ +```release-note:bug +pcap input: Check for nil packet and transport layer when streaming pcap files. +``` diff --git a/.github/release/changelog.gotmpl b/.github/release/changelog.gotmpl new file mode 100644 index 0000000..61f8f4f --- /dev/null +++ b/.github/release/changelog.gotmpl @@ -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 -}} diff --git a/.github/release/release-note.gotmpl b/.github/release/release-note.gotmpl new file mode 100644 index 0000000..6310047 --- /dev/null +++ b/.github/release/release-note.gotmpl @@ -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 -}} diff --git a/.github/scripts/check-changelog.sh b/.github/scripts/check-changelog.sh new file mode 100755 index 0000000..11e71e5 --- /dev/null +++ b/.github/scripts/check-changelog.sh @@ -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 diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml new file mode 100644 index 0000000..fb382dd --- /dev/null +++ b/.github/workflows/changelog.yml @@ -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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..fe96b5e --- /dev/null +++ b/.github/workflows/release.yml @@ -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 }}" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..41073ac --- /dev/null +++ b/CONTRIBUTING.md @@ -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.