Skip to content

Commit

Permalink
CI: Automatically generate the release changelog (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandrogario authored Feb 22, 2021
1 parent be24fd5 commit 5280104
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -611,6 +623,7 @@ jobs:
with:
tag_name: ${{ github.ref }}
release_name: Version ${{ github.ref }}
body_path: anvill/changelog.md
draft: true
prerelease: true

Expand Down
30 changes: 30 additions & 0 deletions scripts/generate_changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

PROJECT_NAME="anvill"

main() {
if [[ $# != 1 ]] ; then
printf "Usage:\n\tgenerate_changelog.sh <path/to/changelog/file.md>\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 $?

0 comments on commit 5280104

Please sign in to comment.