From 5280104232a5d3d45e748e4f99fff7d6ad69b1cc Mon Sep 17 00:00:00 2001 From: Alessandro Gario <5714290+alessandrogario@users.noreply.github.com> Date: Mon, 22 Feb 2021 21:27:33 +0100 Subject: [PATCH] CI: Automatically generate the release changelog (#123) --- .github/workflows/build.yml | 13 +++++++++++++ scripts/generate_changelog.sh | 30 ++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100755 scripts/generate_changelog.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 624b4351d..6950a8f49 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -598,6 +598,18 @@ jobs: if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') steps: + - name: Clone the anvill repository + uses: actions/checkout@v2 + with: + path: anvill + fetch-depth: 0 + + - name: Generate the changelog + shell: bash + working-directory: anvill + run: | + ./scripts/generate_changelog.sh changelog.md + - name: Download all artifacts uses: actions/download-artifact@v2 @@ -611,6 +623,7 @@ jobs: with: tag_name: ${{ github.ref }} release_name: Version ${{ github.ref }} + body_path: anvill/changelog.md draft: true prerelease: true diff --git a/scripts/generate_changelog.sh b/scripts/generate_changelog.sh new file mode 100755 index 000000000..631326324 --- /dev/null +++ b/scripts/generate_changelog.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +PROJECT_NAME="anvill" + +main() { + if [[ $# != 1 ]] ; then + printf "Usage:\n\tgenerate_changelog.sh \n" + return 1 + fi + + local output_path="${1}" + local current_version="$(git describe --tags --always)" + local previous_version="$(git describe --tags --always --abbrev=0 ${current_version}^)" + + echo "Current version: ${current_version}" + echo "Previous version: ${previous_version}" + echo "Output file: ${output_path}" + + printf "# Changelog\n\n" > "${output_path}" + printf "The following are the changes that happened between versions ${previous_version} and ${current_version}\n\n" >> "${output_path}" + + git log ${previous_version}...${current_version} \ + --pretty=format:" * [%h](http://github.com/lifting-bits/${PROJECT_NAME}/commit/%H) - %s" \ + --reverse | grep -v 'Merge branch' >> "${output_path}" + + return 0 +} + +main $@ +exit $?