ci.yml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. name: CI
  2. on:
  3. push:
  4. branches: [main]
  5. pull_request:
  6. # Run on all PRs, but skip for repo owner (runs local tests)
  7. # Skip CI for repo owner's PRs (they run tests locally)
  8. # This check is applied to all jobs below
  9. env:
  10. PYTHON_VERSION: '3.11'
  11. NODE_VERSION: '20'
  12. # Cancel in-progress runs for the same branch
  13. concurrency:
  14. group: ${{ github.workflow }}-${{ github.ref }}
  15. cancel-in-progress: true
  16. jobs:
  17. # ============================================================================
  18. # Backend Checks
  19. # ============================================================================
  20. backend-lint:
  21. name: Backend Lint
  22. runs-on: ubuntu-latest
  23. if: github.event_name == 'push' || github.actor != github.repository_owner
  24. steps:
  25. - uses: actions/checkout@v4
  26. - name: Set up Python
  27. uses: actions/setup-python@v5
  28. with:
  29. python-version: ${{ env.PYTHON_VERSION }}
  30. - name: Install ruff
  31. run: pip install ruff
  32. - name: Run ruff check
  33. run: ruff check backend/
  34. - name: Run ruff format check
  35. run: ruff format --check backend/
  36. backend-tests:
  37. name: Backend Tests
  38. runs-on: ubuntu-latest
  39. if: github.event_name == 'push' || github.actor != github.repository_owner
  40. needs: backend-lint
  41. steps:
  42. - uses: actions/checkout@v4
  43. - name: Set up Python
  44. uses: actions/setup-python@v5
  45. with:
  46. python-version: ${{ env.PYTHON_VERSION }}
  47. - name: Cache pip
  48. uses: actions/cache@v4
  49. with:
  50. path: ~/.cache/pip
  51. key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
  52. restore-keys: |
  53. ${{ runner.os }}-pip-
  54. - name: Install dependencies
  55. run: |
  56. python -m pip install --upgrade pip
  57. pip install -r requirements.txt
  58. pip install pytest pytest-asyncio pytest-cov pytest-timeout
  59. - name: Run tests
  60. timeout-minutes: 10
  61. run: |
  62. cd backend
  63. python -m pytest tests/ -v --tb=short --timeout=60 --timeout-method=thread
  64. # ============================================================================
  65. # Frontend Checks
  66. # ============================================================================
  67. frontend-lint:
  68. name: Frontend Lint
  69. runs-on: ubuntu-latest
  70. if: github.event_name == 'push' || github.actor != github.repository_owner
  71. steps:
  72. - uses: actions/checkout@v4
  73. - name: Set up Node.js
  74. uses: actions/setup-node@v4
  75. with:
  76. node-version: ${{ env.NODE_VERSION }}
  77. cache: 'npm'
  78. cache-dependency-path: frontend/package-lock.json
  79. - name: Install dependencies
  80. working-directory: frontend
  81. run: npm ci
  82. - name: Run ESLint
  83. working-directory: frontend
  84. run: npm run lint
  85. frontend-typecheck:
  86. name: Frontend Type Check
  87. runs-on: ubuntu-latest
  88. if: github.event_name == 'push' || github.actor != github.repository_owner
  89. steps:
  90. - uses: actions/checkout@v4
  91. - name: Set up Node.js
  92. uses: actions/setup-node@v4
  93. with:
  94. node-version: ${{ env.NODE_VERSION }}
  95. cache: 'npm'
  96. cache-dependency-path: frontend/package-lock.json
  97. - name: Install dependencies
  98. working-directory: frontend
  99. run: npm ci
  100. - name: Run TypeScript check
  101. working-directory: frontend
  102. run: npx tsc --noEmit
  103. frontend-tests:
  104. name: Frontend Tests
  105. runs-on: ubuntu-latest
  106. if: github.event_name == 'push' || github.actor != github.repository_owner
  107. needs: [frontend-lint, frontend-typecheck]
  108. steps:
  109. - uses: actions/checkout@v4
  110. - name: Set up Node.js
  111. uses: actions/setup-node@v4
  112. with:
  113. node-version: ${{ env.NODE_VERSION }}
  114. cache: 'npm'
  115. cache-dependency-path: frontend/package-lock.json
  116. - name: Install dependencies
  117. working-directory: frontend
  118. run: npm ci
  119. - name: Run tests
  120. timeout-minutes: 10
  121. working-directory: frontend
  122. run: npm run test:run
  123. frontend-build:
  124. name: Frontend Build
  125. runs-on: ubuntu-latest
  126. if: github.event_name == 'push' || github.actor != github.repository_owner
  127. needs: [frontend-tests]
  128. steps:
  129. - uses: actions/checkout@v4
  130. - name: Set up Node.js
  131. uses: actions/setup-node@v4
  132. with:
  133. node-version: ${{ env.NODE_VERSION }}
  134. cache: 'npm'
  135. cache-dependency-path: frontend/package-lock.json
  136. - name: Install dependencies
  137. working-directory: frontend
  138. run: npm ci
  139. - name: Build
  140. working-directory: frontend
  141. run: npm run build
  142. # ============================================================================
  143. # Docker Tests (matches test_docker.sh)
  144. # ============================================================================
  145. docker-test:
  146. name: Docker Build
  147. runs-on: ubuntu-latest
  148. if: github.event_name == 'push' || github.actor != github.repository_owner
  149. timeout-minutes: 20
  150. needs: [backend-tests, frontend-build]
  151. steps:
  152. - uses: actions/checkout@v4
  153. # Test 1: Docker Build
  154. - name: Build production image
  155. run: docker build -t bambuddy:test .
  156. - name: Verify backend imports
  157. run: docker run --rm bambuddy:test python -c "import backend.app.main; print('Backend imports OK')"
  158. - name: Verify static files exist
  159. run: docker run --rm bambuddy:test test -d /app/static
  160. # Test 2: Backend Unit Tests in Docker
  161. - name: Build backend test image
  162. run: docker compose -f docker-compose.test.yml build backend-test
  163. - name: Run backend tests in Docker
  164. run: docker compose -f docker-compose.test.yml run --rm backend-test
  165. # Test 3: Frontend Unit Tests in Docker
  166. - name: Build frontend test image
  167. run: docker compose -f docker-compose.test.yml build frontend-test
  168. - name: Run frontend tests in Docker
  169. run: docker compose -f docker-compose.test.yml run --rm frontend-test
  170. # Test 4: Integration Tests
  171. - name: Build integration container
  172. run: docker compose -f docker-compose.test.yml build integration
  173. - name: Start integration container
  174. run: |
  175. docker compose -f docker-compose.test.yml up -d integration
  176. echo "Waiting for container to be healthy..."
  177. for i in {1..30}; do
  178. if docker compose -f docker-compose.test.yml ps integration | grep -q "healthy"; then
  179. echo "Container is healthy"
  180. break
  181. fi
  182. sleep 2
  183. done
  184. - name: Test health endpoint
  185. run: |
  186. HEALTH=$(docker compose -f docker-compose.test.yml exec -T integration curl -s http://localhost:8000/health)
  187. echo "$HEALTH"
  188. echo "$HEALTH" | grep -q "healthy"
  189. - name: Test API endpoint
  190. run: |
  191. docker compose -f docker-compose.test.yml exec -T integration curl -s http://localhost:8000/api/v1/settings
  192. - name: Test static files served
  193. run: |
  194. STATUS=$(docker compose -f docker-compose.test.yml exec -T integration curl -s -o /dev/null -w "%{http_code}" http://localhost:8000/)
  195. echo "Static files HTTP status: $STATUS"
  196. [ "$STATUS" = "200" ]
  197. - name: Show logs on failure
  198. if: failure()
  199. run: docker compose -f docker-compose.test.yml logs
  200. - name: Cleanup
  201. if: always()
  202. run: docker compose -f docker-compose.test.yml down -v --remove-orphans