name: Build Snapshots

on:
  push:
    branches:
      - master
      - WIP-keyboard-stuff
  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
            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-14
            xcode_version: 15.4
            name: MacOS
            cpu: x86_64
            os: darwin
            flavour: opt
          - image: macos-14
            xcode_version: 15.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
      if: ${{ matrix.os == 'darwin' && env.BUILD_CERTIFICATE_BASE64 }}
      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: ${{ secrets.BUILD_CERTIFICATE_BASE64 && '748867M822' }}
      # Directory name only
      uses: ./.github/actions/build
      with:
        os: ${{ matrix.os }}
        cpu: ${{ matrix.cpu }}
        flavour: ${{ matrix.flavour }}
