name: 'Release changelog'

on:
  push:
    tags:
      - '*'

jobs:
  release:
    if: startsWith(github.ref, 'refs/tags/')
    runs-on: ubuntu-latest
    steps:
      - name: Get version from tag
        id: tag_name
        run: |
          echo ::set-output name=current_version::${GITHUB_REF#refs/tags/v}
        shell: bash

      - name: Build Changelog
        id: github_release
        uses: mikepenz/release-changelog-builder-action@main
        with:
          configuration: ".github/workflows/changelog/configuration.json"
          owner: "AlexRogalskiy"
          repo: "typescript-tools"
          ignorePreReleases: "false"
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Create Release
        uses: actions/create-release@latest
        with:
          draft: false
          prerelease: false
          tag_name: ${{ steps.tag_name.outputs.current_version }}
          release_name: ${{ steps.tag_name.outputs.current_version }}
          body: ${{steps.github_release.outputs.changelog}}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
