ci.yml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 unit tests
  56. run: |
  57. cd backend
  58. python -m pytest tests/unit/ -v --tb=short -m "not slow"
  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 Build (optional, for release confidence)
  134. # ============================================================================
  135. docker-build:
  136. name: Docker Build
  137. runs-on: ubuntu-latest
  138. needs: [backend-tests, frontend-build]
  139. steps:
  140. - uses: actions/checkout@v4
  141. - name: Set up Docker Buildx
  142. uses: docker/setup-buildx-action@v3
  143. - name: Build Docker image
  144. uses: docker/build-push-action@v6
  145. with:
  146. context: .
  147. push: false
  148. tags: bambuddy:test
  149. cache-from: type=gha
  150. cache-to: type=gha,mode=max