name: Generate changelog

on: workflow_dispatch

jobs:
  generate-changelog:
    name: Generate changelog
    runs-on: ubuntu-20.04
    outputs:
      release_body: ${{ steps.release.outputs.release_body }}
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: Generate a changelog
        uses: orhun/git-cliff-action@v1
        id: git-cliff
        with:
          config: cliff.toml
          args: --output CHANGELOG.md
        env:
          OUTPUT: CHANGELOG.md
      - name: Set the release body
        id: release
        shell: bash
        run: |
          r=$(cat ${{ steps.git-cliff.outputs.changelog }})
          r="$(printf "$r" | tail -n +3)"
          r="${r//'%'/'%25'}"
          r="${r//$'\n'/'%0A'}"
          r="${r//$'\r'/'%0D'}"
          echo "::set-output name=release_body::$r"
