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

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

jobs:
  build-switch:
    runs-on: ubuntu-latest
    container:
      image: devkitpro/devkita64:latest
    steps:
      - uses: actions/checkout@v4
      - name: Compile Switch build
        id: compile
        run: |
          make switch
          

      - uses: ./.github/actions/notify_failure
        if: ${{ always() && steps.compile.outcome == 'failure' }}
        with:
          NOTIFY_MESSAGE: 'Failed to compile Switch build'
          WEBHOOK_URL: '${{ secrets.WEBHOOK_URL }}'
          
          
      - uses: ./.github/actions/upload_build
        if: ${{ always() && steps.compile.outcome == 'success' }}
        with:
          SOURCE_FILE: 'ClassiCube-switch.nro'
          DEST_NAME: 'ClassiCube-switch.nro'
          
      - uses: ./.github/actions/upload_build
        if: ${{ always() && steps.compile.outcome == 'success' }}
        with:
          SOURCE_FILE: 'ClassiCube-switch.elf'
          DEST_NAME: 'ClassiCube-switch.elf'
          
          
      - uses: ./.github/actions/notify_success
        if: ${{ always() && steps.compile.outcome == 'success' }}
        with:
          DESTINATION_URL: '${{ secrets.NOTIFY_URL }}'
          WORKFLOW_NAME: 'switch'