name: Version release

on:
  push:
    tags:
      - 'v*.*.*'

jobs:
  run-distcheck:
    uses: ./.github/workflows/dist_check.yaml

  create-dist-archives:
    needs: run-distcheck
    uses: ./.github/workflows/dist_archives.yaml
    with:
      zip: true
      artifact-name: 'dist-archives'

  create-osx-installer:
    needs: create-dist-archives
    uses: ./.github/workflows/dist_osx.yaml
    with:
      tarball-artifact-name: 'dist-archives'
      artifact-name: 'osx-installer'
      version-string: ${{ needs.create-dist-archives.outputs.version_number }}

  create-release:
    needs: [run-distcheck, create-dist-archives, create-osx-installer]
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
    - uses: actions/checkout@v4
    - name: Extract release notes
      id: extract-release-notes
      uses: RaumZeit/extract-release-notes@a991ec1541871118630638fe002862a023870cff
      with:
        header_level: 3
        version_prefix: "Version"
    - name: Download source archives
      uses: actions/download-artifact@v4
      with:
        name: dist-archives
    - name: Download OSX installer
      uses: actions/download-artifact@v4
      with:
        pattern: osx-installer-*
        merge-multiple: true
    - name: Make release
      uses: ncipollo/release-action@v1
      with:
        artifacts: "ViennaRNA-*.tar.gz,ViennaRNA-*.zip,ViennaRNA-*-MacOSX-*.dmg"
        body: ${{ steps.extract-release-notes.outputs.release_notes }}
        name: "ViennaRNA Package ${{ needs.create-dist-archives.outputs.version_number }}"
