name: Determinism Check

env:
    CONVEX_VS_MESH_HASH: '0x219df2ceee6baff2'
    RAGDOLL_HASH: '0x9bace3bd537e6759'

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

jobs:
  linux:
    runs-on: ubuntu-22.04
    name: Linux Determinism Check

    steps:
    - name: Checkout Code
      uses: actions/checkout@v3
    - name: Configure CMake
      run: cmake -B ${{github.workspace}}/Build/Linux_Distribution -DCMAKE_BUILD_TYPE=Distribution -DCMAKE_CXX_COMPILER=clang++ Build -DCROSS_PLATFORM_DETERMINISTIC=ON -DTARGET_VIEWER=OFF -DTARGET_SAMPLES=OFF -DTARGET_HELLO_WORLD=OFF -DTARGET_UNIT_TESTS=OFF
    - name: Build
      run: cmake --build ${{github.workspace}}/Build/Linux_Distribution
    - name: Test ConvexVsMesh
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: ./PerformanceTest -q=LinearCast -t=2 -s=ConvexVsMesh -validate_hash=${CONVEX_VS_MESH_HASH}
    - name: Test Ragdoll
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: ./PerformanceTest -q=LinearCast -t=2 -s=Ragdoll -validate_hash=${RAGDOLL_HASH}

  msvc_cl:
    runs-on: windows-latest
    name: Visual Studio CL Determinism Check

    steps:
    - name: Checkout Code
      uses: actions/checkout@v3
    - name: Add msbuild to PATH
      uses: microsoft/setup-msbuild@v1.3
    - name: Configure CMake
      run: cmake -B ${{github.workspace}}/Build/VS2022_CL -G "Visual Studio 17 2022" -A x64 Build -DCROSS_PLATFORM_DETERMINISTIC=ON -DTARGET_VIEWER=OFF -DTARGET_SAMPLES=OFF -DTARGET_HELLO_WORLD=OFF -DTARGET_UNIT_TESTS=OFF
    - name: Build
      run: msbuild Build\VS2022_CL\JoltPhysics.sln /property:Configuration=Distribution
    - name: Test ConvexVsMesh
      working-directory: ${{github.workspace}}/Build/VS2022_CL/Distribution
      run: ./PerformanceTest -q=LinearCast -t=2 -s=ConvexVsMesh "-validate_hash=$env:CONVEX_VS_MESH_HASH"
    - name: Test Ragdoll
      working-directory: ${{github.workspace}}/Build/VS2022_CL/Distribution
      run: ./PerformanceTest -q=LinearCast -t=2 -s=Ragdoll "-validate_hash=$env:RAGDOLL_HASH"

  macos:
    runs-on: macos-latest
    name: macOS Determinism Check

    steps:
    - name: Checkout Code
      uses: actions/checkout@v3
    - name: Configure CMake
      run: cmake -B ${{github.workspace}}/Build/Linux_Distribution -DCMAKE_BUILD_TYPE=Distribution Build -DCROSS_PLATFORM_DETERMINISTIC=ON -DTARGET_VIEWER=OFF -DTARGET_SAMPLES=OFF -DTARGET_HELLO_WORLD=OFF -DTARGET_UNIT_TESTS=OFF -DUSE_AVX2=OFF -DUSE_AVX512=OFF -DUSE_LZCNT=OFF -DUSE_TZCNT=OFF
    - name: Build
      run: cmake --build ${{github.workspace}}/Build/Linux_Distribution
    - name: Test ConvexVsMesh
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: ./PerformanceTest -q=LinearCast -t=2 -s=ConvexVsMesh -validate_hash=${CONVEX_VS_MESH_HASH}
    - name: Test Ragdoll
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: ./PerformanceTest -q=LinearCast -t=2 -s=Ragdoll -validate_hash=${RAGDOLL_HASH}

  arm:
    runs-on: ubuntu-22.04
    name: ARM Determinism Check
    steps:
    - name: Checkout Code
      uses: actions/checkout@v3
    - name: Update index
      run: sudo apt-get update
    - name: Install Cross Compiler
      run: sudo apt-get install gcc-11-aarch64-linux-gnu gcc-11-multilib g++-11-multilib libstdc++-11-dev-arm64-cross qemu-user -y
    - name: Configure CMake
      run: cmake -B ${{github.workspace}}/Build/Linux_Distribution -DCMAKE_BUILD_TYPE=Distribution -DCMAKE_CXX_COMPILER=clang++ Build -DCROSS_PLATFORM_DETERMINISTIC=ON -DCROSS_COMPILE_ARM=ON -DTARGET_VIEWER=OFF -DTARGET_SAMPLES=OFF -DTARGET_HELLO_WORLD=OFF -DTARGET_UNIT_TESTS=ON
    - name: Build
      run: cmake --build ${{github.workspace}}/Build/Linux_Distribution
    - name: Test
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: qemu-aarch64 -L /usr/aarch64-linux-gnu/ ./UnitTests
    - name: Test ConvexVsMesh
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: qemu-aarch64 -L /usr/aarch64-linux-gnu/ ./PerformanceTest -q=LinearCast -t=2 -s=ConvexVsMesh -validate_hash=${CONVEX_VS_MESH_HASH}
    - name: Test Ragdoll
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: qemu-aarch64 -L /usr/aarch64-linux-gnu/ ./PerformanceTest -q=LinearCast -t=2 -s=Ragdoll -validate_hash=${RAGDOLL_HASH}
