---
name: release

on:
  push:
    branches:
      - main
    tags:
      - "v*.*.*"

  workflow_run:
    workflows: ["pre-commit"]
    types:
      - completed

jobs:
  release:
    name: Release Job
    runs-on: ubuntu-latest
    if: startsWith(github.ref, 'refs/tags/v')
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Install go (required for Changelog parsing)
        uses: actions/setup-go@v4

      - name: Parse CHANGELOG.md
        run: |
          GO111MODULE=on go install github.com/rcmachado/changelog@0.7.0
          changelog show "$GITHUB_REF_NAME" > ${{ github.workspace }}-CHANGELOG.txt
          echo "Release note for $GITHUB_REF_NAME :"
          cat ${{ github.workspace }}-CHANGELOG.txt

      - name: Release
        uses: softprops/action-gh-release@v1
        with:
          body_path: ${{ github.workspace }}-CHANGELOG.txt
          files: |
            LICENSE
            CHANGELOG.md
