name: citest

on:
  push:
    branches:
      - master
      - "release/**"
    paths-ignore:
      - "setup.*"
      - "requirements.txt"
      - "requirements/**"
      - "docs/**"
      - "tools/**"
      - ".dev_scripts/**"
      - "README.md"
      - "README_*.md"
      - "NOTICE"
      - ".github/workflows/lint.yaml"
      - ".github/workflows/publish.yaml"

  pull_request:
    paths-ignore:
      - "setup.*"
      - "requirements.txt"
      - "requirements/**"
      - "docs/**"
      - "tools/**"
      - ".dev_scripts/**"
      - "README.md"
      - "README_*.md"
      - "NOTICE"
      - ".github/workflows/lint.yaml"
      - ".github/workflows/publish.yaml"

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

jobs:
  unittest:
    # The type of runner that the job will run on
    runs-on: [self-hosted]
    timeout-minutes: 240
    steps:
      - name: ResetFileMode
        shell: bash
        run: |
          # reset filemode to allow action runner to delete files
          # generated by root in docker
          set -e
          source ~/.bashrc
          sudo chown -R $USER:$USER  $ACTION_RUNNER_DIR

      - name: Checkout
        uses: actions/checkout@v3
        with:
            lfs: 'true'
            submodules: 'true'
            fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 0 }}
      - name: Get changed files
        id: changed-files
        run: |
            if ${{ github.event_name == 'pull_request' }}; then
                echo "PR_CHANGED_FILES=$(git diff --name-only -r HEAD^1 HEAD | xargs)" >> $GITHUB_ENV
            else
                echo "PR_CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | xargs)" >> $GITHUB_ENV
            fi
      - name: Checkout LFS objects
        run: git lfs checkout
      - name: Run unittest
        shell: bash
        run: |
          set -e
          source /mnt/modelscope/ci_env.sh
          bash .dev_scripts/dockerci.sh
