name: Tag and Release

on:
  push:
    branches: [ release ]

  workflow_dispatch:


jobs:

  Release:
  
    runs-on: ubuntu-latest

    steps:

      - name: Checkout the repo 
        uses: actions/checkout@v2

      - name: Extract values
        run: |
          version="$(cat VERSION | xargs)"
          echo $version
          version_array=($version)
          echo ${version_array[2]}
          echo ::set-output name=fetk-version::${version_array[2]}
        shell: bash
        id: job-values

      - name: Create tag
        uses: tvdias/github-tagger@v0.0.1
        with:
          repo-token: "${{ secrets.RELEASE_TOKEN }}"
          tag: ${{ steps.job-values.outputs.fetk-version }}

      - name: Extract release text
        run: |
          ./extract_section.sh -f CHANGELOG.md -v ${{ steps.job-values.outputs.fetk-version }} > release.md
          cat release.md

      - name: Create Release
        uses: softprops/action-gh-release@v1
        env:
          GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
        with:
          body_path: release.md
          tag_name: ${{ steps.job-values.outputs.fetk-version }}
