From 2271f4cdb6b82f66a1656ff9448fd54fc8c33060 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Tue, 7 Jan 2020 13:55:56 +0100 Subject: [PATCH] Generate changelog on release The changelog is generated using the git log of pull request merges since the last tagged release, and is in the following format: * {PR title} #{PR number} --- .github/workflows/releases.yml | 4 +++- .gitignore | 1 + .goreleaser.yml | 7 ------- script/changelog | 20 ++++++++++++++++++++ 4 files changed, 24 insertions(+), 8 deletions(-) create mode 100755 script/changelog diff --git a/.github/workflows/releases.yml b/.github/workflows/releases.yml index c8796be908f..b293a2d93b0 100644 --- a/.github/workflows/releases.yml +++ b/.github/workflows/releases.yml @@ -16,11 +16,13 @@ jobs: uses: actions/setup-go@v1 with: go-version: 1.13 + - name: Generate changelog + run: script/changelog | tee CHANGELOG.md - name: Run GoReleaser uses: goreleaser/goreleaser-action@v1 with: version: latest - args: release + args: release --release-notes=CHANGELOG.md env: GH_OAUTH_CLIENT_ID: 178c6fc778ccc68e1d6a GH_OAUTH_CLIENT_SECRET: ${{secrets.OAUTH_CLIENT_SECRET}} diff --git a/.gitignore b/.gitignore index fe3d1d53866..76ddfcc68a8 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /dist /site .github/**/node_modules +/CHANGELOG.md diff --git a/.goreleaser.yml b/.goreleaser.yml index fe901b955be..b3ee2336c23 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -39,10 +39,3 @@ nfpms: formats: - deb - rpm - -changelog: - sort: asc - filters: - exclude: - - "^docs:" - - "^test:" diff --git a/script/changelog b/script/changelog new file mode 100755 index 00000000000..42a91cf5da0 --- /dev/null +++ b/script/changelog @@ -0,0 +1,20 @@ +#!/bin/bash +set -e + +current_tag="${GITHUB_REF#refs/tags/}" +start_ref="HEAD" + +# Find the previous release on the same branch, skipping prereleases if the +# current tag is a full release +previous_tag="" +while [[ -z $previous_tag || ( $previous_tag == *-* && $current_tag != *-* ) ]]; do + previous_tag="$(git describe --tags "$start_ref"^ --abbrev=0)" + start_ref="$previous_tag" +done + +git log "$previous_tag".. --reverse --merges --oneline --grep='Merge pull request #' | \ + while read -r sha title; do + pr_num="$(grep -o '#[[:digit:]]\+' <<<"$title")" + pr_desc="$(git show -s --format=%b "$sha" | sed -n '1,/^$/p' | tr $'\n' ' ')" + printf "* %s %s\n\n" "$pr_desc" "$pr_num" + done \ No newline at end of file