name: Release

on:
  push:
    tags:
      - '*'

jobs:
  make-release:

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3

      - name: Extract version
        id: version
        run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/}

      - name: Create changelog
        id: changelog
        uses: jaywcjlove/changelog-generator@main
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          filter: 'Release \d+\.\d+\.\d+'

      - name: Install dependencies
        uses: ConorMacBride/install-package@v1.1.0
        with:
          apt: tox

      - name: Create archive
        run: tox -e archive
        env:
          VERSION: ${{ steps.version.outputs.VERSION }}

      - name: Publish release
        uses: softprops/action-gh-release@v1
        with:
          body: |
            ${{ steps.changelog.outputs.compareurl }}
            ${{ steps.changelog.outputs.changelog }}
          files: dist/ahriman-*.tar.gz
          fail_on_unmatched_files: true
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
