# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: mineru
on:
  push:
    branches:
      - "master"
    paths-ignore:
      - "cmds/**"
      - "**.md"
  pull_request:
    branches:
      - "master"
    paths-ignore:
      - "cmds/**"
      - "**.md"
  workflow_dispatch:
jobs:
  cli-test:
    runs-on: ubuntu-latest
    timeout-minutes: 40
    strategy:
      fail-fast: true

    steps:
    - name: PDF cli
      uses: actions/checkout@v3
      with:
        fetch-depth: 2
      
    - name: check-requirements
      run: |
        pip install -r requirements.txt
        pip install -r requirements-qa.txt
        pip install magic-pdf
    - name: test_cli
      run: |
        cp magic-pdf.template.json ~/magic-pdf.json
        echo $GITHUB_WORKSPACE
        cd $GITHUB_WORKSPACE && export PYTHONPATH=. && pytest -s -v tests/test_unit.py
        cd $GITHUB_WORKSPACE &&  pytest -s -v tests/test_cli/test_cli.py
                                                                                                                            
    - name: benchmark
      run: |
        cd $GITHUB_WORKSPACE &&  pytest -s -v tests/test_cli/test_bench.py

  notify_to_feishu:
    if: ${{ always() && !cancelled() && contains(needs.*.result, 'failure') && (github.ref_name == 'master') }}
    needs: [cli-test]
    runs-on: mineru
    steps:
    - name: get_actor
      run: |
          metion_list="quyuan"
          echo $GITHUB_ACTOR
          if [[ $GITHUB_ACTOR == "drunkpig" ]]; then
            metion_list="xuchao"
          elif [[ $GITHUB_ACTOR == "myhloli" ]]; then
            metion_list="zhaoxiaomeng"
          elif [[ $GITHUB_ACTOR == "icecraft" ]]; then
            metion_list="xurui1"
          fi
          echo $metion_list
          echo "METIONS=$metion_list" >> "$GITHUB_ENV"
          echo ${{ env.METIONS }}

    - name: notify
      run: |
        curl  ${{ secrets.WEBHOOK_URL }} -H 'Content-Type: application/json'  -d '{
        "msgtype": "text",
        "text": {
            "mentioned_list": ["${{ env.METIONS }}"] , "content": "'${{ github.repository }}' GitHubAction Failed!\n 细节请查看：https://github.com/'${{ github.repository }}'/actions/runs/'${GITHUB_RUN_ID}'"
        }
        }'   