test.yml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. name: Tests
  2. on:
  3. push:
  4. branches: [ main, develop ]
  5. pull_request:
  6. branches: [ main, develop ]
  7. workflow_dispatch:
  8. jobs:
  9. test:
  10. name: Run Tests
  11. runs-on: ubuntu-latest
  12. strategy:
  13. matrix:
  14. python-version: ['3.11', '3.12']
  15. steps:
  16. - name: Checkout code
  17. uses: actions/checkout@v4
  18. - name: Set up Python ${{ matrix.python-version }}
  19. uses: actions/setup-python@v5
  20. with:
  21. python-version: ${{ matrix.python-version }}
  22. cache: 'pip'
  23. - name: Install dependencies
  24. run: |
  25. python -m pip install --upgrade pip
  26. pip install -r requirements.txt
  27. pip install pytest pytest-asyncio pytest-cov hypothesis httpx
  28. - name: Create necessary directories
  29. run: |
  30. mkdir -p tests/logs
  31. mkdir -p logs
  32. - name: Run unit tests
  33. run: |
  34. pytest tests/unit -v --cov=src --cov-report=xml --cov-report=term -m unit
  35. continue-on-error: false
  36. - name: Run integration tests
  37. run: |
  38. pytest tests/integration -v --cov=src --cov-append --cov-report=xml --cov-report=term -m integration
  39. continue-on-error: true
  40. - name: Run end-to-end tests
  41. run: |
  42. pytest tests/e2e -v --cov=src --cov-append --cov-report=xml --cov-report=term -m e2e
  43. continue-on-error: true
  44. - name: Generate coverage report
  45. run: |
  46. coverage report --fail-under=80
  47. continue-on-error: true
  48. - name: Upload coverage to Codecov
  49. uses: codecov/codecov-action@v4
  50. with:
  51. file: ./coverage.xml
  52. flags: unittests
  53. name: codecov-umbrella
  54. fail_ci_if_error: false
  55. token: ${{ secrets.CODECOV_TOKEN }}
  56. - name: Upload coverage artifacts
  57. uses: actions/upload-artifact@v4
  58. if: always()
  59. with:
  60. name: coverage-report-${{ matrix.python-version }}
  61. path: |
  62. coverage.xml
  63. htmlcov/
  64. retention-days: 30
  65. - name: Upload test logs
  66. uses: actions/upload-artifact@v4
  67. if: always()
  68. with:
  69. name: test-logs-${{ matrix.python-version }}
  70. path: tests/logs/
  71. retention-days: 7
  72. lint:
  73. name: Code Quality
  74. runs-on: ubuntu-latest
  75. steps:
  76. - name: Checkout code
  77. uses: actions/checkout@v4
  78. - name: Set up Python
  79. uses: actions/setup-python@v5
  80. with:
  81. python-version: '3.11'
  82. cache: 'pip'
  83. - name: Install linting tools
  84. run: |
  85. python -m pip install --upgrade pip
  86. pip install flake8 black isort mypy
  87. - name: Run flake8
  88. run: |
  89. flake8 src tests --count --select=E9,F63,F7,F82 --show-source --statistics
  90. flake8 src tests --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
  91. continue-on-error: true
  92. - name: Check code formatting with black
  93. run: |
  94. black --check src tests
  95. continue-on-error: true
  96. - name: Check import sorting with isort
  97. run: |
  98. isort --check-only src tests
  99. continue-on-error: true
  100. - name: Type checking with mypy
  101. run: |
  102. mypy src --ignore-missing-imports
  103. continue-on-error: true
  104. security:
  105. name: Security Scan
  106. runs-on: ubuntu-latest
  107. steps:
  108. - name: Checkout code
  109. uses: actions/checkout@v4
  110. - name: Set up Python
  111. uses: actions/setup-python@v5
  112. with:
  113. python-version: '3.11'
  114. - name: Install security tools
  115. run: |
  116. python -m pip install --upgrade pip
  117. pip install safety bandit
  118. - name: Run safety check
  119. run: |
  120. pip install -r requirements.txt
  121. safety check --json
  122. continue-on-error: true
  123. - name: Run bandit security scan
  124. run: |
  125. bandit -r src -f json -o bandit-report.json
  126. continue-on-error: true
  127. - name: Upload security reports
  128. uses: actions/upload-artifact@v4
  129. if: always()
  130. with:
  131. name: security-reports
  132. path: |
  133. bandit-report.json
  134. retention-days: 30
  135. build-status:
  136. name: Build Status
  137. runs-on: ubuntu-latest
  138. needs: [test, lint, security]
  139. if: always()
  140. steps:
  141. - name: Check build status
  142. run: |
  143. if [ "${{ needs.test.result }}" == "success" ]; then
  144. echo "✅ Tests passed"
  145. else
  146. echo "❌ Tests failed"
  147. exit 1
  148. fi