name: Make MacOSX installer

on:
  workflow_dispatch:
    inputs:
      config-flags:
        description: 'Configure flags for building the Mac OSX installer'
        default: '--without-openmp --with-cluster --with-kinwalker --without-rnaxplorer --enable-macosx-installer --disable-lto'
        required: false
        type: string
      version-string:
        description: 'Version string, e.g. 2.7.1'
        required: false
        default: '2.7.1'
        type: string
      artifact-name:
        description: 'Name of the artifact'
        required: false
        default: 'osx-installer'
        type: string
      tarball-artifact-name:
        description: 'Name of the tarball artifact (for download)'
        required: false
        default: 'dist-archives'
        type: string
  workflow_call:
    inputs:
      config-flags:
        description: 'Configure flags for building the Mac OSX installer'
        default: '--without-openmp --with-cluster --with-kinwalker --without-rnaxplorer --enable-macosx-installer --disable-lto'
        required: false
        type: string
      version-string:
        description: 'Version string, e.g. 2.7.1'
        required: false
        default: '2.7.1'
        type: string
      artifact-name:
        description: 'Name of the artifact'
        required: false
        default: 'osx-installer'
        type: string
      tarball-artifact-name:
        description: 'Name of the tarball artifact (for download)'
        required: false
        default: 'dist-archives'
        type: string

jobs:
  create_osx_installer:
    runs-on: ${{ matrix.os }}

    strategy:
      # Ensure that a wheel builder finishes even if another fails
      fail-fast: false
      matrix:
        os: [macos-15-intel, macos-14]

    steps:
    - uses: actions/download-artifact@v4
      with:
        name: ${{ inputs.tarball-artifact-name }}
    - name: extract and configure
      run:  |
        tar -xzf ViennaRNA-${{ inputs.version-string }}.tar.gz
        cd ViennaRNA-${{ inputs.version-string }}/
        ./configure ${{ inputs.config-flags }}
    - name: compile and build installer
      working-directory: ViennaRNA-${{ inputs.version-string }}
      run: |
        make
    - name: rename installer x86_64
      if: ${{ matrix.os == 'macos-15-intel' }}
      run: |
        mv ViennaRNA-${{ inputs.version-string }}/packaging/macosx/ViennaRNA-${{ inputs.version-string }}-MacOSX.dmg ViennaRNA-${{ inputs.version-string }}/ViennaRNA-${{ inputs.version-string }}-MacOSX-x86_64.dmg
    - name: rename installer arm64
      if: ${{ matrix.os == 'macos-14' }}
      run: |
        mv ViennaRNA-${{ inputs.version-string }}/packaging/macosx/ViennaRNA-${{ inputs.version-string }}-MacOSX.dmg ViennaRNA-${{ inputs.version-string }}/ViennaRNA-${{ inputs.version-string }}-MacOSX-arm64.dmg
    - name: Upload artifacts
      uses: actions/upload-artifact@v4
      with:
        name: ${{ inputs.artifact-name }}-${{ matrix.os }}
        path: ViennaRNA-${{ inputs.version-string }}/ViennaRNA-${{ inputs.version-string }}-MacOSX-*.dmg
        retention-days: 3
