name: 'Release changelog'
on:
  workflow_call:
    inputs:
      version:
        description: "Which version number should we use for the release"
        type: 'string'
        required: true

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
      - name: Build changelog
        id: github_release
        uses: metcalfc/changelog-generator@v4.3.1
        with:
          myToken: ${{ secrets.GITHUB_TOKEN }}
          base-ref: v${{ inputs.version }}
      - name: Create release
        uses: softprops/action-gh-release@v2
        with:
          tag_name: v${{ inputs.version }}
          name: v${{ inputs.version }}
          body: ${{ steps.github_release.outputs.changelog }}
          prerelease: ${{ contains(inputs.version, 'beta') || contains(inputs.version, 'alpha') }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN}}