Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

api-tests.yml 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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: astral-sh/setup-uv@v6
  32. with:
  33. enable-cache: true
  34. python-version: ${{ matrix.python-version }}
  35. cache-dependency-glob: api/uv.lock
  36. - name: Check UV lockfile
  37. run: uv lock --project api --check
  38. - name: Install dependencies
  39. run: uv sync --project api --dev
  40. - name: Run Unit tests
  41. run: |
  42. uv run --project api bash dev/pytest/pytest_unit_tests.sh
  43. - name: Run ty check
  44. run: |
  45. cd api
  46. uv add --dev ty
  47. uv run ty check || true
  48. - name: Run pyrefly check
  49. run: |
  50. cd api
  51. uv add --dev pyrefly
  52. uv run pyrefly check || true
  53. - name: Coverage Summary
  54. run: |
  55. set -x
  56. # Extract coverage percentage and create a summary
  57. TOTAL_COVERAGE=$(python -c 'import json; print(json.load(open("coverage.json"))["totals"]["percent_covered_display"])')
  58. # Create a detailed coverage summary
  59. echo "### Test Coverage Summary :test_tube:" >> $GITHUB_STEP_SUMMARY
  60. echo "Total Coverage: ${TOTAL_COVERAGE}%" >> $GITHUB_STEP_SUMMARY
  61. uv run --project api coverage report --format=markdown >> $GITHUB_STEP_SUMMARY
  62. - name: Run dify config tests
  63. run: uv run --project api dev/pytest/pytest_config_tests.py
  64. - name: MyPy Cache
  65. uses: actions/cache@v4
  66. with:
  67. path: api/.mypy_cache
  68. key: mypy-${{ matrix.python-version }}-${{ runner.os }}-${{ hashFiles('api/uv.lock') }}
  69. - name: Run MyPy Checks
  70. run: dev/mypy-check
  71. - name: Set up dotenvs
  72. run: |
  73. cp docker/.env.example docker/.env
  74. cp docker/middleware.env.example docker/middleware.env
  75. - name: Expose Service Ports
  76. run: sh .github/workflows/expose_service_ports.sh
  77. - name: Set up Sandbox
  78. uses: hoverkraft-tech/compose-action@v2.0.2
  79. with:
  80. compose-file: |
  81. docker/docker-compose.middleware.yaml
  82. services: |
  83. db
  84. redis
  85. sandbox
  86. ssrf_proxy
  87. - name: setup test config
  88. run: |
  89. cp api/tests/integration_tests/.env.example api/tests/integration_tests/.env
  90. - name: Run Workflow
  91. run: uv run --project api bash dev/pytest/pytest_workflow.sh
  92. - name: Run Tool
  93. run: uv run --project api bash dev/pytest/pytest_tools.sh
  94. - name: Run TestContainers
  95. run: uv run --project api bash dev/pytest/pytest_testcontainers.sh