You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

api-tests.yml 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. name: Run Pytest
  2. on:
  3. pull_request:
  4. branches:
  5. - main
  6. paths:
  7. - api/**
  8. - docker/**
  9. - .github/workflows/api-tests.yml
  10. concurrency:
  11. group: api-tests-${{ github.head_ref || github.run_id }}
  12. cancel-in-progress: true
  13. jobs:
  14. test:
  15. name: API Tests
  16. runs-on: ubuntu-latest
  17. defaults:
  18. run:
  19. shell: bash
  20. strategy:
  21. matrix:
  22. python-version:
  23. - "3.11"
  24. - "3.12"
  25. steps:
  26. - name: Checkout code
  27. uses: actions/checkout@v4
  28. with:
  29. persist-credentials: false
  30. - name: Setup UV and Python
  31. uses: ./.github/actions/setup-uv
  32. with:
  33. python-version: ${{ matrix.python-version }}
  34. uv-lockfile: api/uv.lock
  35. - name: Check UV lockfile
  36. run: uv lock --project api --check
  37. - name: Install dependencies
  38. run: uv sync --project api --dev
  39. - name: Run Unit tests
  40. run: |
  41. uv run --project api bash dev/pytest/pytest_unit_tests.sh
  42. # Extract coverage percentage and create a summary
  43. TOTAL_COVERAGE=$(python -c 'import json; print(json.load(open("coverage.json"))["totals"]["percent_covered_display"])')
  44. # Create a detailed coverage summary
  45. echo "### Test Coverage Summary :test_tube:" >> $GITHUB_STEP_SUMMARY
  46. echo "Total Coverage: ${TOTAL_COVERAGE}%" >> $GITHUB_STEP_SUMMARY
  47. echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
  48. uv run --project api coverage report >> $GITHUB_STEP_SUMMARY
  49. echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
  50. - name: Run dify config tests
  51. run: uv run --project api dev/pytest/pytest_config_tests.py
  52. - name: MyPy Cache
  53. uses: actions/cache@v4
  54. with:
  55. path: api/.mypy_cache
  56. key: mypy-${{ matrix.python-version }}-${{ runner.os }}-${{ hashFiles('api/uv.lock') }}
  57. - name: Run MyPy Checks
  58. run: dev/mypy-check
  59. - name: Set up dotenvs
  60. run: |
  61. cp docker/.env.example docker/.env
  62. cp docker/middleware.env.example docker/middleware.env
  63. - name: Expose Service Ports
  64. run: sh .github/workflows/expose_service_ports.sh
  65. - name: Set up Sandbox
  66. uses: hoverkraft-tech/compose-action@v2.0.2
  67. with:
  68. compose-file: |
  69. docker/docker-compose.middleware.yaml
  70. services: |
  71. db
  72. redis
  73. sandbox
  74. ssrf_proxy
  75. - name: setup test config
  76. run: |
  77. cp api/tests/integration_tests/.env.example api/tests/integration_tests/.env
  78. - name: Run Workflow
  79. run: uv run --project api bash dev/pytest/pytest_workflow.sh
  80. - name: Run Tool
  81. run: uv run --project api bash dev/pytest/pytest_tools.sh