name: Build Snapshots

on:
  push:
    branches:
      - master
      - WIP-keyboard-stuff
      - sdl3
  pull_request:
    branches:
      - master

jobs:
  build:
    name: ${{ matrix.name }} ${{ matrix.cpu }}
    runs-on: ${{ matrix.image }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - image: ubuntu-latest
            name: Unit Tests (on Linux)
            cpu: x86_64
            os: linux
            flavour: unittest
          - image: ubuntu-latest
            name: Linux (native, super-opt)
            cpu: x86_64
            os: linux
            flavour: super-opt
          - image: ubuntu-latest
            name: Linux (native, debug, minimal g++)
            cpu: x86_64
            os: linux
            flavour: debug
          - image: ubuntu-latest
            name: Linux
            cpu: x86_64
            os: linux
            flavour: opt
#          - image: ubuntu-latest
#            name: Linux
#            cpu: aarch64
#            os: linux
#            flavour: opt
          - image: ubuntu-24.04
            name: Windows
            cpu: x86_64
            os: mingw-w64
            flavour: opt
          - image: macos-15
            xcode_version: 16.4
            name: MacOS
            cpu: x86_64
            os: darwin
            flavour: opt
          - image: macos-15
            xcode_version: 16.4
            name: MacOS
            cpu: aarch64
            os: darwin
            flavour: opt
#          - image: ubuntu-latest
#            name: Android
#            cpu: arm
#            os: android
#            flavour: opt
          - image: windows-latest
            name: Windows-VC
            cpu: x64
            os: windows-vc
            flavour: opt
    steps:
    - name: Get current code from Git repo
      uses: actions/checkout@v4
      with:
        fetch-depth: 0
    - name: Select Xcode version
      if: ${{ matrix.xcode_version }}
      run: sudo xcode-select -s /Applications/Xcode_${{ matrix.xcode_version }}.app/Contents/Developer
    - name: Preparations for signing binaries on Darwin builds
      # Don't fail build for pull requests if vars and secrets are not defined.
      if: ${{ matrix.os == 'darwin' && vars.CODE_SIGN_IDENTITY }}
      uses: ./.github/actions/prepare-sign
      env:
        BUILD_CERTIFICATE_BASE64: ${{ secrets.BUILD_CERTIFICATE_BASE64 }}
        P12_PASSWORD: ${{ secrets.P12_PASSWORD }}
        KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }}
      with:
        os: ${{ matrix.os }}
    - name: Perform the actual build
      env:
        CODE_SIGN_IDENTITY: ${{ vars.CODE_SIGN_IDENTITY }}
      # Directory name only
      uses: ./.github/actions/build
      with:
        os: ${{ matrix.os }}
        cpu: ${{ matrix.cpu }}
        flavour: ${{ matrix.flavour }}
