ci.yml 6.6 KB

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