name: Run Rive tests

on:
  pull_request:
    branches:
      - main
  push:

jobs:
  run_tests:
    name: Run Rive tests
    runs-on: ghcr.io/cirruslabs/macos-runner:sonoma
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          token: ${{ secrets.PAT_GITHUB }}
          submodules: true

      - name: Configure venv
        run: |
          python3 -m venv .venv
          source .venv/bin/activate
          echo PATH=$PATH >> $GITHUB_ENV

      - name: Add rive_build.sh to PATH
        shell: bash
        run: echo "${{github.workspace}}/submodules/rive-runtime/build" >> $GITHUB_PATH

      - name: Installing pre-requisites
        run: |
          set -x
          # Install some dependencies & premake5
          brew install ninja
          curl https://github.com/premake/premake-core/releases/download/v5.0.0-beta2/premake-5.0.0-beta2-macosx.tar.gz -L -o premake_macosx.tar.gz
          tar -xvf premake_macosx.tar.gz 2>/dev/null
          rm premake_macosx.tar.gz
          sudo chmod a+x premake5
          mkdir bin
          cp premake5 bin/premake5
          sudo mv premake5 /usr/local/bin
          pip3 install ply

      - name: Select Xcode 15.4
        run: sudo xcodes select 15.4

      - name: Build for iOS Simulator (using the cache, we should make an archive of course)
        run: |
          ./scripts/build.sh ios_sim release

      - name: Test iOS runtime
        run: ./scripts/test.sh ios_sim

      - name: Build for visionOS Simulator (using the cache, we should make an archive of course)
        run: |
          ./scripts/build.sh xrsimulator release

      - name: Test visionOS runtime
        run: ./scripts/test.sh xrsimulator

      - name: Build for tvOS Simulator (using the cache, we should make an archive of course)
        run: |
          ./scripts/build.sh appletvsimulator release

      - name: Test tvOS runtime
        run: ./scripts/test.sh appletvsimulator

      - name: Build for Mac Catalyst (using the cache, we should make an archive of course)
        run: |
          ./scripts/build.sh maccatalyst release

      - name: Test Mac Catalyst runtime
        run: ./scripts/test.sh maccatalyst
