name: backend-torchscript

on:
  push:
    paths-ignore:
      - "demo/**"
      - "tools/**"

  pull_request:
    paths-ignore:
      - "demo/**"
      - "tools/**"
      - "docs/**"

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  build_torchscript:
    runs-on: ubuntu-20.04
    strategy:
      matrix:
        python-version: [3.7]
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3
        with:
          submodules: 'recursive'
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python-version }}
      - name: Install mmdeploy
        run: |
          python -m pip install torch==1.11.0 torchvision==0.12.0 --extra-index-url https://download.pytorch.org/whl/lts/1.11/cpu
          python -m pip install mmcv-lite
          python tools/scripts/build_ubuntu_x64_torchscript.py 8
          python -c 'from mmdeploy.backend.torchscript import is_available; assert is_available()'
