name: DNNE

on:
  push:
    branches: [master]
    paths-ignore:
      - '**/*.md'
  pull_request:
    branches: [master]
    paths-ignore:
      - '**/*.md'

jobs:
  linux:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        flavor: [ 'Debug', 'Release' ]
    steps:
    - uses: actions/checkout@v5
    - name: Setup .NET
      uses: actions/setup-dotnet@v5
      with:
        dotnet-version: '8.0.x'
        dotnet-quality: 'ga'
    - name: Setup Rust
      uses: actions-rust-lang/setup-rust-toolchain@v1
      with:
        toolchain: 'stable'
    - name: Build Product and Package
      run: dotnet build src/create_package.proj -c ${{ matrix.flavor }}
    - name: Unit Test Product
      run: dotnet test test/DNNE.UnitTests -bl:unittest.${{ matrix.flavor }}.binlog -c ${{ matrix.flavor }}
    - name: Unit Test Product (gcc)
      run: |
        dotnet clean test/DNNE.UnitTests -c ${{ matrix.flavor }}
        dotnet test test/DNNE.UnitTests -c ${{ matrix.flavor }} -p:BuildWithGCC=true
    - name: Unit Test Product (g++)
      run: |
        dotnet clean test/DNNE.UnitTests -c ${{ matrix.flavor }}
        dotnet test test/DNNE.UnitTests -c ${{ matrix.flavor }} -p:BuildWithGPP=true
    - name: Build test.proj
      run: |
        dotnet build test/test.proj -c  ${{ matrix.flavor }} -p:BuildPackage=false
    - name: Upload Build Logs
      if: failure()
      uses: actions/upload-artifact@v7
      with:
        name: unittest.linux.${{ matrix.flavor }}.binlog
        path: unittest.${{ matrix.flavor }}.binlog
    - name: Upload Package
      uses: actions/upload-artifact@v7
      with:
        name: package.${{ matrix.flavor }}
        path: src/dnne-pkg/bin/${{ matrix.flavor }}/DNNE.*.nupkg

  windows:
    runs-on: windows-latest
    strategy:
      matrix:
        flavor: [ 'Debug', 'Release' ]
    steps:
    - uses: actions/checkout@v5
    - name: Setup .NET
      uses: actions/setup-dotnet@v5
      with:
        dotnet-version: '8.0.x'
        dotnet-quality: 'ga'
    - name: Setup Rust
      uses: actions-rust-lang/setup-rust-toolchain@v1
      with:
        toolchain: 'stable'
    - name: Build Product and Package
      run: dotnet build src\create_package.proj -c ${{ matrix.flavor }}
    - name: Build ExportingAssembly (.NET Core and .NET Framework)
      run: dotnet build test\ExportingAssembly -c ${{ matrix.flavor }}
    - name: Build ExportingAssembly (cross-compile win-arm64)
      run: |
        dotnet clean test\ExportingAssembly -c ${{ matrix.flavor }}
        dotnet build test\ExportingAssembly -c ${{ matrix.flavor }} -p:DnneRuntimeIdentifier=win-arm64
    - name: Build ExportingAssembly (cross-compile win-x86)
      run: |
        dotnet clean test\ExportingAssembly -c ${{ matrix.flavor }}
        dotnet build test\ExportingAssembly -c ${{ matrix.flavor }} -p:DnneRuntimeIdentifier=win-x86
    - name: Unit Test Product (cpp)
      run: |
        dotnet clean test\DNNE.UnitTests -c ${{ matrix.flavor }}
        dotnet test test\DNNE.UnitTests -bl:unittest.${{ matrix.flavor }}.binlog -c ${{ matrix.flavor }} -p:BuildAsCPPWithMSVC=true
    - name: Unit Test Product
      run: |
        dotnet clean test\DNNE.UnitTests -c ${{ matrix.flavor }}
        dotnet test test\DNNE.UnitTests -c ${{ matrix.flavor }}
    - name: Build test.proj
      run: |
        dotnet build test\test.proj -c  ${{ matrix.flavor }} -p:BuildPackage=false
    - name: Upload Build Logs
      if: failure()
      uses: actions/upload-artifact@v7
      with:
        name: unittest.windows.${{ matrix.flavor }}.binlog
        path: unittest.${{ matrix.flavor }}.binlog

  macos:
    runs-on: macos-latest
    strategy:
      matrix:
        flavor: [ 'Debug', 'Release' ]
    steps:
    - uses: actions/checkout@v5
    - name: Setup .NET
      uses: actions/setup-dotnet@v5
      with:
        dotnet-version: '8.0.x'
        dotnet-quality: 'ga'
    - name: Setup Rust
      uses: actions-rust-lang/setup-rust-toolchain@v1
      with:
        toolchain: 'stable'
    - name: Build Product and Package
      run: dotnet build src/create_package.proj -c  ${{ matrix.flavor }}
    - name: Unit Test Product
      run: dotnet test test/DNNE.UnitTests -bl:unittest.${{ matrix.flavor }}.binlog -c  ${{ matrix.flavor }}
    - name: Unit Test Product (clang++)
      run: |
        dotnet clean test/DNNE.UnitTests -c ${{ matrix.flavor }}
        dotnet test test/DNNE.UnitTests -c  ${{ matrix.flavor }} -p:BuildWithClangPP=true
    - name: Build test.proj
      run: |
        dotnet build test/test.proj -c  ${{ matrix.flavor }} -p:BuildPackage=false
    - name: Upload Build Logs
      if: failure()
      uses: actions/upload-artifact@v7
      with:
        name: unittest.macos.${{ matrix.flavor }}.binlog
        path: unittest.${{ matrix.flavor }}.binlog
