name: TB_Plugin_CI

on:
  push:
    branches:
      - main
      - release/**
      - plugin/**

  pull_request:
    branches:
      - main
      - release/**
      - plugin/**

jobs:
  generate-matrix:
    runs-on: ubuntu-latest
    outputs:
      matrix: ${{ steps.set-matrix.outputs.matrix }}
    steps:
      - id: set-matrix
        run: |
          echo $GITHUB_BASE_REF
          if [ $GITHUB_BASE_REF == "plugin/vnext" ]
          then
            echo "matrix={\"python-version\":[3.8], \"cuda-version\":[\"cpu\"], \"pytorch-version\":[\"nightly\"]}" >> "$GITHUB_OUTPUT"
          else
            echo "matrix={\"python-version\":[3.8], \"cuda-version\":[\"cpu\"], \"pytorch-version\":[\"nightly\", \"2.0\", \"stable\"]}" >> "$GITHUB_OUTPUT"
          fi

  build:
    needs: generate-matrix
    runs-on: ubuntu-latest
    strategy:
      matrix: ${{fromJSON(needs.generate-matrix.outputs.matrix)}}
    steps:
      - uses: actions/checkout@v2
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python-version }}
          architecture: "x64"
      - name: Test
        env:
          CUDA_VERSION: ${{ matrix.cuda-version }}
          PYTORCH_VERSION: ${{ matrix.pytorch-version }}
          TORCH_PROFILER_LOG_LEVEL: DEBUG
          GRPC_VERBOSITY: DEBUG
          GRPC_ENABLE_FORK_SUPPORT: "False"
        run: |
          set -e
          cd tb_plugin
          sh ./ci_scripts/install_env.sh
          pip install .[gs]
          cd test
          pytest
