name: Generate Changelog on Tag

on:
  push:
    tags:
      - 'v*'

permissions:
  contents: write

jobs:
  changelog:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout (full history)
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Build changelog from commits
        id: build
        uses: mikepenz/release-changelog-builder-action@v4
        with:
          configuration: .github/changelog-config.json
          ignorePreReleases: false
          toTag: ${{ github.ref_name }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Create / Update GitHub Release notes
        uses: softprops/action-gh-release@v2
        with:
          tag_name: ${{ github.ref_name }}
          body: ${{ steps.build.outputs.changelog }}