on:
  push:
    tags: ["[0-9]+.[0-9]+.[0-9]+"]

jobs:
  draft-release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Get changelog
        id: extract-changelog
        env:
          REF_NAME: ${{ github.ref_name }}
        run: |
          git fetch --tags --force
          RELEASE_NAME="${REF_NAME} $(date +'%Y-%m-%d')"
          git tag -l --format='%(contents:body)' "${REF_NAME}" > next-changelog.txt
          echo "RELEASE_NAME=$RELEASE_NAME" >> $GITHUB_OUTPUT
      - name: Create Release
        uses: softprops/action-gh-release@v1
        with:
          tag_name: ${{ github.ref }}
          name: ${{ steps.extract-changelog.outputs.RELEASE_NAME }}
          body_path: next-changelog.txt
          draft: true # Draft it
          token: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
