name: Distribute Exe

on:
  release:
    types:
      - created
  workflow_dispatch:

jobs:
  build:
    runs-on: windows-latest

    steps:
    - name: Checkout
      uses: actions/checkout@v4
      with:
        fetch-depth: 0
        submodules: 'recursive'

    - name: Add powerpc-unknown-linux-gnu
      run: rustup target add --toolchain stable powerpc-unknown-linux-gnu
      working-directory: randomprime

    - name: Cargo Build
      run: cargo build
      working-directory: randomprime

    - name: Upload Artifacts
      uses: actions/upload-artifact@v3
      with:
        name: randomprime_patcher.exe
        path: randomprime\target\debug\randomprime_patcher.exe
        if-no-files-found: error

  attach:
    runs-on: ubuntu-latest
    needs: build

    steps:
    - name: Download Artifact
      uses: actions/download-artifact@v3
      with:
        name: randomprime_patcher.exe

    - uses: montudor/action-zip@v1
      with:
        args: zip randomprime_patcher.zip randomprime_patcher.exe

    - name: Attach to Release
      uses: svenstaro/upload-release-action@v2
      with:
        file: randomprime_patcher.zip
        asset_name: randomprime_patcher-$tag.zip
        tag: ${{ github.ref }}
        overwrite: true
