name: Build (3DS)

on:
  push:
    branches: [ master, actions ]
  pull_request:
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    defaults:
      run:
        shell: bash

    # Build inside the official devkitPro image (has dkp-pacman & toolchains preconfigured)
    container:
      image: devkitpro/devkitarm:latest
      options: --user root

    env:
      DEVKITPRO: /opt/devkitpro
      DEVKITARM: /opt/devkitpro/devkitARM
      PATH: /opt/devkitpro/tools/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

    steps:
      - name: Install Node.js (required for GitHub Actions)
        run: |
          apt-get update
          apt-get install -y nodejs npm

      - name: Checkout (with submodules)
        uses: actions/checkout@v4
        with:
          submodules: recursive

      - name: Install makerom & bannertool (Linux x64)
        run: |
         MAKEROM_VER=makerom-v0.18.4
         BANNERP_URL="https://github.com/Epicpkmn11/bannertool/releases/download/v1.2.2/bannertool.zip"
         set -euxo pipefail
         mkdir -p /opt/devkitpro/tools/bin
         curl -L "https://github.com/3DSGuy/Project_CTR/releases/download/${MAKEROM_VER}/${MAKEROM_VER}-ubuntu_x86_64.zip" -o /tmp/makerom.zip
         unzip -j /tmp/makerom.zip -d /opt/devkitpro/tools/bin
         chmod +x /opt/devkitpro/tools/bin/makerom
         curl -L "$BANNERP_URL" -o /tmp/bannertool.zip
         unzip -p /tmp/bannertool.zip 'linux-x86_64/bannertool' > /opt/devkitpro/tools/bin/bannertool
         chmod +x /opt/devkitpro/tools/bin/bannertool

      - name: Build
        run: make -j"$(nproc)"

      - name: Upload artifacts
        uses: actions/upload-artifact@v3
        with:
          name: mice-build
          path: output/
          if-no-files-found: warn
