name: rust_api

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

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

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

jobs:
  test_rust_api:
    runs-on: ubuntu-18.04
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3
        with:
          submodules: 'recursive'

      - name: Set up Python 3.7
        uses: actions/setup-python@v2
        with:
          python-version: 3.7
      - name: Install latest nightly Rust
        uses: actions-rs/toolchain@v1
        with:
            toolchain: nightly
            override: true
            components: rustfmt, clippy
      - name: update
        run: sudo apt update
      - name: Install dependencies
        run: sudo apt install llvm-dev libclang-dev clang git-lfs
      - name: Install onnxruntime
        run: |
          wget https://github.com/microsoft/onnxruntime/releases/download/v1.8.1/onnxruntime-linux-x64-1.8.1.tgz
          tar -zxvf onnxruntime-linux-x64-1.8.1.tgz
          pushd onnxruntime-linux-x64-1.8.1
          popd
      - name: Install opencv
        run: sudo apt-get install libopencv-dev
      - name: Install mmdeploy with onnxruntime backend
        run: |
          wget https://github.com/open-mmlab/mmdeploy/releases/download/v0.9.0/mmdeploy-0.9.0-linux-x86_64-onnxruntime1.8.1.tar.gz
          tar -zxvf mmdeploy-0.9.0-linux-x86_64-onnxruntime1.8.1.tar.gz
      - name: Download rust-mmdeploy
        run: git clone https://github.com/liu-mengyang/rust-mmdeploy
      - name: Download converted models
        run: git clone https://github.com/liu-mengyang/mmdeploy-converted-models --depth=1
      - name: Test rustdemo
        run: |
          pushd rust-mmdeploy
          export MMDEPLOY_DIR=/home/runner/work/mmdeploy/mmdeploy/mmdeploy-0.9.0-linux-x86_64-onnxruntime1.8.1/sdk
          export LD_LIBRARY_PATH=$MMDEPLOY_DIR/lib:$LD_LIBRARY_PATH
          export ONNXRUNTIME_DIR=/home/runner/work/mmdeploy/mmdeploy/onnxruntime-linux-x64-1.8.1
          export LD_LIBRARY_PATH=$ONNXRUNTIME_DIR/lib:$LD_LIBRARY_PATH
          cargo build
          sh ci_test.sh
