Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changelog generation workflow #1519

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/changelog-generation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
name: Raise PR with Changelog

on:
push:
branches:
- "release-*"

jobs:
build-and-run-release-notes:
runs-on: ubuntu-latest

steps:
- name: Check out code onto GOPATH
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
check-latest: true

- name: Build and Install Release Notes Tool
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
./generate-changelog.sh
cat CHANGELOG.md

- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
commit-message: "chore: autogenerate changelog"
title: "Changelog"
body: This PR contains an autogenerated changelog for newer commits. The new changelog can be modified [here](https://github.com/prometheus/client_golang/blob/changelog-branch/CHANGELOG.md).
branch: changelog-branch
signoff: true
delete-branch: true
labels: automated-pr, release-note-none
SachinSahu431 marked this conversation as resolved.
Show resolved Hide resolved
20 changes: 20 additions & 0 deletions changelog-template.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{- $CurrentRevision := .CurrentRevision -}}
{{- $PreviousRevision := .PreviousRevision -}}

{{with .NotesWithActionRequired -}}
## Urgent Upgrade Notes

### (No, really, you MUST read this before you upgrade)

{{range .}}{{println "-" .}} {{end}}
{{end}}

{{- if .Notes -}}
{{- range $notes := .Notes -}}
{{range $note := .NoteEntries}}
{{- if ne $notes.Kind "Uncategorized" }}
* [{{- $notes.Kind }}] {{$note}}
{{- end }}
{{- end -}}
{{- end -}}
{{- end -}}
48 changes: 48 additions & 0 deletions generate-changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

git fetch --tags

CURR_DIR=$(pwd)

VERSION=$(cat VERSION)
TAG_NAME="v${VERSION}"

MANUAL_START_SHA=$1
MANUAL_END_SHA=$2

# Get the start SHA based on the tag, if not manually provided
if [ -z "$MANUAL_START_SHA" ]; then
START_SHA=$(git rev-list -n 1 "${TAG_NAME}")
else
START_SHA=$MANUAL_START_SHA
fi

# Get the end SHA (latest commit on main branch), if not manually provided
if [ -z "$MANUAL_END_SHA" ]; then
END_SHA=$(git rev-parse HEAD)
else
END_SHA=$MANUAL_END_SHA
fi

temp_dir="$(mktemp -d)" && \
git clone --depth=1 -q https://github.com/kubernetes/release.git "${temp_dir}" && \
cd "${temp_dir}/" && \
go build ./cmd/release-notes/ && \
mv release-notes /usr/local/bin/

release-notes \
--start-sha "${START_SHA}" \
--end-sha "${END_SHA}" \
--org prometheus \
--repo client_golang \
--branch main \
--required-author "" \
--debug \
--dependencies=false \
--output="CHANGELOG_NEW.md" \
--go-template "go-template:${CURR_DIR}/changelog-template.tpl"

cat "CHANGELOG_NEW.md"

# Append new changelog entries to Unreleased section
sed "/## Unreleased/r CHANGELOG_NEW.md" "${CURR_DIR}/CHANGELOG.md" > "CHANGELOG_TMP.md" && mv "CHANGELOG_TMP.md" "${CURR_DIR}/CHANGELOG.md"
Loading