name: CI

on:
  pull_request:
  push:
    branches:
      - master
    paths:
      - './**.c'
      - './**.h'
      - './**.hpp'
      - './**.cpp'
  workflow_dispatch:
    branches:
      - feature

jobs:

  msbuild-windows-64bit-build:
    runs-on: windows-latest

    steps:
    - uses: actions/checkout@v3

    - name: Add MSBuild to PATH
      uses: microsoft/setup-msbuild@v1.0.2

    - name: Add Premake to PATH
      uses: abel0b/setup-premake@v2.4
      with:
        version: "5.0.0-beta2"      

    - name: Run Premake Install Dependencies
      run: premake5 installdependencies

    - name: Get zydis
      run: premake5 installzydis

    - name: Run Premake
      run: premake5 vs2022

    - name: Build 64 bit
      run: premake5 build

    - name: Run Tests
      run: premake5 test

  msbuild-windows-32bit-build:
    runs-on: windows-latest

    steps:
    - uses: actions/checkout@v3

    - name: Add MSBuild to PATH
      uses: microsoft/setup-msbuild@v1.0.2

    - name: Add Premake to PATH
      uses: abel0b/setup-premake@v2.4
      with:
        version: "5.0.0-beta2"      

    - name: Run Premake Install Dependencies
      run: premake5 installdependencies

    - name: Get zydis
      run: premake5 installzydis

    - name: Run Premake
      run: premake5 vs2022

    - name: Build 32 bit
      run: premake5 build_32bit

    - name: Run Tests 
      run: premake5 test_32bit

  gmake-linux-64bit-build:
   runs-on: ubuntu-latest

   steps:
    - uses: actions/checkout@v3

    - name: Add Premake to PATH
      uses: abel0b/setup-premake@v2.4
      with:
        version: "5.0.0-beta2"      

    - name: Run Premake Install Dependencies
      run: premake5 installdependencies

    - name: Get zydis
      run: premake5 installzydis

    - name: Run Premake
      run: premake5 gmake2

    - name: Build
      run: premake5 build

    - name: Run Tests 
      run: premake5 test

  gmake-linux-32bit-build:
   runs-on: ubuntu-latest
   steps:
    - uses: actions/checkout@v3

    - name: Add gcc multilib to PATH
      run: sudo apt install gcc-multilib g++-multilib
    
    - name: Add Premake to PATH
      uses: abel0b/setup-premake@v2.4
      with:
        version: "5.0.0-beta2"      

    - name: Run Premake Install Dependencies
      run: premake5 installdependencies

    - name: Get zydis
      run: premake5 installzydis

    - name: Run Premake
      run: premake5 gmake2
   
    - name: Build
      run: premake5 build_32bit
    
    - name: Run Tests 
      run: premake5 test_32bit

  clang-macos-build:
   runs-on: macos-latest

   steps:
    - uses: actions/checkout@v3

    - name: Add Premake to PATH
      uses: abel0b/setup-premake@v2.4
      with:
        version: "5.0.0-beta2"      

    - name: Run Premake Install Dependencies
      run: premake5 installdependencies

    - name: Get zydis
      run: premake5 installzydis

    - name: Run Premake
      run: premake5 gmake2

    - name: Build 
      run: premake5 build

    - name: Run Test
      run: premake5 test

  gmake-wasm-build:
   runs-on: ubuntu-latest
   steps:
    - uses: actions/checkout@v3

    - name: Add Premake to PATH
      uses: abel0b/setup-premake@v2.4
      with:
        version: "5.0.0-beta2"      

    - name: Add Emsdk to PATH
      uses: mymindstorm/setup-emsdk@v13

    - name: Get zydis
      run: premake5 installzydis

    - name: Run Premake
      run: premake5 gmake2
    
    - name: Build Wasm
      run: premake5 web_build
 
  ndk-android-build:
   runs-on: ubuntu-latest

   steps:
    - uses: actions/checkout@v3

    - name: Add Ndk to PATH
      uses: nttld/setup-ndk@v1
      with:
        ndk-version: r26d

    - name: Add Premake to PATH
      uses: abel0b/setup-premake@v2.4
      with:
        version: "5.0.0-beta2"

    - name: Get premake-androidndk
      run: git clone https://github.com/Triang3l/premake-androidndk .premake/premake-androidndk

    - name: Get zydis
      run: premake5 installzydis

    - name: Add require to Premake 
      run: echo "require \"premake-androidndk/androidndk\"" > temp && cat premake5.lua >> temp && mv temp premake5.lua

    - name: Run Premake 
      run: premake5 androidndk

    - name: Build
      run: premake5 build_android

  xcode-ios-build:
   runs-on: "macos-latest"
   steps:
    - uses: actions/checkout@v3

    - name: Add Premake to PATH
      uses: abel0b/setup-premake@v2.4
      with:
        version: "5.0.0-beta2"      

    - uses: maxim-lobanov/setup-xcode@v1
      with:
        xcode-version: '14.3.1'

    - name: Get zydis
      run: premake5 installzydis

    - name: Run Premake 
      run: premake5 xcode4

    - name: Fix IOS xcode file 
      run: premake5 fixios

    - name: Build
      run: xcodebuild -project UCodeLang/UCodeLang.xcodeproj -configuration Debug -sdk iphoneos build

