name: Build latest (Wii/GameCube)
# trigger via either push to selected branches or on manual run
on:
  push:
    branches:
      - main
      - master
  workflow_dispatch:

concurrency:
  group: ${{ github.ref }}-wiigc
  cancel-in-progress: true

jobs:
  build:
    runs-on: ubuntu-latest
    container:
      image: devkitpro/devkitppc:latest
    steps:
      - uses: actions/checkout@v4
      - name: Compile Wii and GameCube build
        id: compile
        run: |
          make wii
          make clean
          make gamecube
          
      - name: Create Wii homebrew
        run: |
          mkdir -p wiitest/apps/ClassiCube
          cp ClassiCube-wii.dol wiitest/apps/ClassiCube/boot.dol
          cp misc/wii/icon.png wiitest/apps/ClassiCube/icon.png
          cp misc/wii/meta.xml wiitest/apps/ClassiCube/meta.xml


      - uses: ./.github/actions/notify_failure
        if: ${{ always() && steps.compile.outcome == 'failure' }}
        with:
          NOTIFY_MESSAGE: 'Failed to compile Wii/Gamecube build'
          WEBHOOK_URL: '${{ secrets.WEBHOOK_URL }}'
          
          
      - uses: ./.github/actions/upload_build
        if: ${{ always() && steps.compile.outcome == 'success' }}
        with:
          SOURCE_FILE: 'ClassiCube-wii.dol'
          DEST_NAME: 'ClassiCube-wii.dol'
          
      - uses: ./.github/actions/upload_build
        if: ${{ always() && steps.compile.outcome == 'success' }}
        with:
          SOURCE_FILE: 'ClassiCube-gc.dol'
          DEST_NAME: 'ClassiCube-gc.dol'
          
      - uses: ./.github/actions/upload_build
        if: ${{ always() && steps.compile.outcome == 'success' }}
        with:
          SOURCE_FILE: 'ClassiCube-wii.elf'
          DEST_NAME: 'ClassiCube-wii.elf'
          
      - uses: ./.github/actions/upload_build
        if: ${{ always() && steps.compile.outcome == 'success' }}
        with:
          SOURCE_FILE: 'ClassiCube-gc.elf'
          DEST_NAME: 'ClassiCube-gc.elf'
          
      - uses: ./.github/actions/upload_build
        if: ${{ always() && steps.compile.outcome == 'success' }}
        with:
          SOURCE_FILE: 'wiitest'
          DEST_NAME: 'ClassiCube-Wii-Homebrew'
          
          
      - uses: ./.github/actions/notify_success
        if: ${{ always() && steps.compile.outcome == 'success' }}
        with:
          DESTINATION_URL: '${{ secrets.NOTIFY_URL }}'
          WORKFLOW_NAME: 'wiigc'