Add changelog to Github Actions releases

Using Github Actions you can create new releases in Github easily. This is done by using Create a Release Action.
You can add Markdown to the body of this Action. One common detail that is usually included with releases is the list of the changes from last release. After doing some research and many pushes to Github I found the solution and I thought it would be a good idea to put it somewhere!

name: Release-Me

      - '*'

    runs-on: windows-latest
    - uses: actions/checkout@v2
        fetch-depth: '0'
    - name: Get the version
      id: get_version
      run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
      shell: bash
    - name: Get changes
      id: get_changes
      run: echo ::set-output name=changes::$(git log --oneline $(git describe --tags --abbrev=0 @^)..@ | sed 's/$/%0A/')
      shell: bash
    - name: Create release
      id: create_release
      uses: actions/create-release@v1
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        tag_name: ${{ steps.get_version.outputs.VERSION }}
        release_name: ${{ steps.get_version.outputs.VERSION }}
        body: |
          ## Changelog
          ${{ steps.get_changes.outputs.changes }}
        draft: true
        prerelease: true

This will list all the changes from current to last git tag. It is very important to set fetch-depth to 0 so the git history is loaded for the branch.

One thing that took me some time to figure out was that following characters have to be escaped and the runner will unescape them in reverse.

  • % to %25
  • \n to %0A
  • \r to %0D