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.6KB

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