name: Release


on:
  push:
    tags:
    - 'v[0-9]+.[0-9]+.[0-9]+'
    - 'v[0-9]+.[0-9]+.[0-9]+\+*'
    - 'v[0-9]+.[0-9]+.[0-9]+-*'


jobs:

  build:
    strategy:
      matrix:
        emu : [ Switch, Emulators ]
    runs-on: ubuntu-latest
    outputs:
      filename1: ${{ steps.set-output.outputs.filename-Switch }}
      filename2: ${{ steps.set-output.outputs.filename-Emulators }}
    steps:
    -
      name : Checkout
      uses : actions/checkout@v3
    -
      name : Build artifacts
      id   : build
      uses : ./.github/actions/build
      with:
        tag : ${{ github.ref_name }}
        emu : ${{ matrix.emu }}
    -
      name  : Set output
      id    : set-output
      shell : bash
      run   : |
        echo "::set-output name=filename-${{ matrix.emu }}::${{ steps.build.outputs.filename }}"

  release:
    needs: build
    runs-on: ubuntu-latest
    steps:
    -
      name : Checkout
      uses : actions/checkout@v3
    -
      name : Create release
      id   : release
      uses : ./.github/actions/release
      with:
        tag          : ${{ github.ref_name }}
        GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
    -
      name : Attach build artifacts to release (Switch)
      uses : ./.github/actions/attach
      with:
        filename     : ${{ needs.build.outputs.filename1 }}
        upload_url   : ${{ steps.release.outputs.upload_url }}
        GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
    -
      name : Attach build artifacts to release (Emulators)
      uses : ./.github/actions/attach
      with:
        filename     : ${{ needs.build.outputs.filename2 }}
        upload_url   : ${{ steps.release.outputs.upload_url }}
        GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
