name: Examples

on:
  push:
    branches:
    - main
    - develop
  pull_request:
    branches:
    - main
    - develop

  workflow_dispatch:

jobs:
  build_and_test:
    if: contains(toJson(github.event.commits), '***NO_CI***') == false && contains(toJson(github.event.commits), '[ci skip]') == false && contains(toJson(github.event.commits), '[skip ci]') == false
    name: Testing library examples, running on ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false # show all errors for each platform (vs. cancel jobs on error)
      matrix:
        include:
        - os: ubuntu-latest
          backend: "-DRTNEURAL_STL=ON"
        - os: windows-latest
          backend: "-DRTNEURAL_STL=ON"
        - os: macos-latest
          backend: "-DRTNEURAL_STL=ON"

    steps:
    - name: Get latest CMake
      uses: lukka/get-cmake@latest

    - name: Checkout code
      uses: actions/checkout@v2

    - name: Configure
      env:
        BACKEND_ARG: ${{ matrix.backend }}
      shell: bash
      run: cmake -Bbuild -DBUILD_EXAMPLES=ON $BACKEND_ARG

    - name: Build
      shell: bash
      run: cmake --build build --config Release --parallel

    - name: Hello RTNeural
      shell: bash
      run: ./build/examples_out/hello_rtneural

    - name: RTNeural Static Model
      shell: bash
      run: ./build/examples_out/rtneural_static_model

    - name: RTNeural Dynamic Model
      shell: bash
      run: ./build/examples_out/rtneural_dynamic_model models/dense.json

    - name: RTNeural Custom Layer Model
      shell: bash
      run: ./build/examples_out/custom_layer_model

    - name: RTNeural Conv1D Torch
      shell: bash
      run: ./build/examples_out/torch_conv1d

    - name: RTNeural GRU Torch
      shell: bash
      run: ./build/examples_out/torch_gru

    - name: RTNeural Conv1D Stateless
      shell: bash
      run: ./build/examples_out/conv1d_stateless_example

    - name: Hello RTNeural with Makefile
      if: runner.os == 'Linux'
      shell: bash
      working-directory: ${{github.workspace}}/examples/hello_rtneural
      run: make hello_rtneural.exe
