|
1 | | -name: CI - Pull Request Checks |
| 1 | +name: CI/CD Pipeline |
2 | 2 |
|
3 | | -# Only run on pull requests targeting main branch |
| 3 | +# Trigger on push to main/develop and all pull requests |
4 | 4 | on: |
| 5 | + push: |
| 6 | + branches: [main, develop] |
5 | 7 | pull_request: |
6 | | - branches: [ main ] |
| 8 | + branches: [main, develop] |
| 9 | + |
| 10 | +# Cancel in-progress runs for same branch |
| 11 | +concurrency: |
| 12 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 13 | + cancel-in-progress: true |
7 | 14 |
|
8 | 15 | jobs: |
9 | | - test: |
10 | | - name: Code Quality & Testing |
| 16 | + # Code quality checks |
| 17 | + quality: |
| 18 | + name: Code Quality & Linting |
11 | 19 | runs-on: ubuntu-latest |
12 | 20 |
|
13 | 21 | steps: |
14 | | - # Checkout the repository code |
15 | 22 | - name: Checkout code |
16 | 23 | uses: actions/checkout@v4 |
17 | 24 |
|
18 | | - # Setup Node.js environment with caching for faster installs |
19 | 25 | - name: Setup Node.js |
20 | 26 | uses: actions/setup-node@v4 |
21 | 27 | with: |
22 | 28 | node-version: '20' |
23 | 29 | cache: 'npm' |
24 | 30 |
|
25 | | - # Install dependencies using npm ci (clean install) |
26 | | - # This ensures consistent dependency versions across CI runs |
27 | 31 | - name: Install dependencies |
28 | 32 | run: npm ci |
29 | 33 |
|
30 | | - # Run ESLint to check code quality and style |
31 | | - # This catches potential bugs and enforces coding standards |
32 | | - - name: Run linter |
| 34 | + - name: Run ESLint |
33 | 35 | run: npm run lint |
34 | | - continue-on-error: true # Don't fail the build on linting warnings |
35 | 36 |
|
36 | | - # Run Vitest test suite |
37 | | - # Validates that all unit and integration tests pass |
| 37 | + - name: Check for unused imports |
| 38 | + run: npx eslint . --ext .js,.jsx --quiet |
| 39 | + continue-on-error: true |
| 40 | + |
| 41 | + # TypeScript type checking |
| 42 | + typecheck: |
| 43 | + name: TypeScript Type Check |
| 44 | + runs-on: ubuntu-latest |
| 45 | + |
| 46 | + steps: |
| 47 | + - name: Checkout code |
| 48 | + uses: actions/checkout@v4 |
| 49 | + |
| 50 | + - name: Setup Node.js |
| 51 | + uses: actions/setup-node@v4 |
| 52 | + with: |
| 53 | + node-version: '20' |
| 54 | + cache: 'npm' |
| 55 | + |
| 56 | + - name: Install dependencies |
| 57 | + run: npm ci |
| 58 | + |
| 59 | + - name: Type check |
| 60 | + run: npm run typecheck || echo "Type checking skipped (migration in progress)" |
| 61 | + continue-on-error: true |
| 62 | + |
| 63 | + # Run tests |
| 64 | + test: |
| 65 | + name: Unit & Integration Tests |
| 66 | + runs-on: ubuntu-latest |
| 67 | + |
| 68 | + steps: |
| 69 | + - name: Checkout code |
| 70 | + uses: actions/checkout@v4 |
| 71 | + |
| 72 | + - name: Setup Node.js |
| 73 | + uses: actions/setup-node@v4 |
| 74 | + with: |
| 75 | + node-version: '20' |
| 76 | + cache: 'npm' |
| 77 | + |
| 78 | + - name: Install dependencies |
| 79 | + run: npm ci |
| 80 | + |
38 | 81 | - name: Run tests |
39 | 82 | run: npm run test:run |
40 | 83 |
|
41 | | - # Check for high/critical security vulnerabilities |
42 | | - # Only fails on high or critical severity issues |
43 | | - - name: Security audit |
| 84 | + - name: Generate coverage report |
| 85 | + run: npm run test:coverage |
| 86 | + continue-on-error: true |
| 87 | + |
| 88 | + - name: Upload coverage to Codecov |
| 89 | + uses: codecov/codecov-action@v3 |
| 90 | + with: |
| 91 | + files: ./coverage/lcov.info |
| 92 | + flags: unittests |
| 93 | + name: codecov-interact |
| 94 | + fail_ci_if_error: false |
| 95 | + continue-on-error: true |
| 96 | + |
| 97 | + # Security scanning |
| 98 | + security: |
| 99 | + name: Security Scan |
| 100 | + runs-on: ubuntu-latest |
| 101 | + |
| 102 | + steps: |
| 103 | + - name: Checkout code |
| 104 | + uses: actions/checkout@v4 |
| 105 | + |
| 106 | + - name: Setup Node.js |
| 107 | + uses: actions/setup-node@v4 |
| 108 | + with: |
| 109 | + node-version: '20' |
| 110 | + cache: 'npm' |
| 111 | + |
| 112 | + - name: Install dependencies |
| 113 | + run: npm ci |
| 114 | + |
| 115 | + - name: Run npm audit |
44 | 116 | run: npm audit --audit-level=high |
45 | | - continue-on-error: true # Don't fail on advisory issues |
| 117 | + continue-on-error: true |
| 118 | + |
| 119 | + - name: Check for secrets |
| 120 | + uses: trufflesecurity/trufflehog@main |
| 121 | + with: |
| 122 | + path: ./ |
| 123 | + base: ${{ github.event.repository.default_branch }} |
| 124 | + head: HEAD |
| 125 | + continue-on-error: true |
| 126 | + |
| 127 | + # Build application |
| 128 | + build: |
| 129 | + name: Build Application |
| 130 | + needs: [quality, typecheck, test] |
| 131 | + runs-on: ubuntu-latest |
| 132 | + |
| 133 | + steps: |
| 134 | + - name: Checkout code |
| 135 | + uses: actions/checkout@v4 |
| 136 | + |
| 137 | + - name: Setup Node.js |
| 138 | + uses: actions/setup-node@v4 |
| 139 | + with: |
| 140 | + node-version: '20' |
| 141 | + cache: 'npm' |
| 142 | + |
| 143 | + - name: Install dependencies |
| 144 | + run: npm ci |
| 145 | + |
| 146 | + - name: Build for production |
| 147 | + run: npm run build |
| 148 | + env: |
| 149 | + NODE_ENV: production |
| 150 | + |
| 151 | + - name: Check build size |
| 152 | + run: | |
| 153 | + echo "Build size:" |
| 154 | + du -sh dist/ |
| 155 | + echo "Detailed breakdown:" |
| 156 | + du -h dist/* | sort -hr | head -20 |
| 157 | + |
| 158 | + - name: Upload build artifacts |
| 159 | + uses: actions/upload-artifact@v3 |
| 160 | + with: |
| 161 | + name: dist-${{ github.sha }} |
| 162 | + path: dist/ |
| 163 | + retention-days: 7 |
| 164 | + |
| 165 | + # Deploy to staging (develop branch only) |
| 166 | + deploy-staging: |
| 167 | + name: Deploy to Staging |
| 168 | + needs: [build, security] |
| 169 | + if: github.ref == 'refs/heads/develop' && github.event_name == 'push' |
| 170 | + runs-on: ubuntu-latest |
| 171 | + environment: |
| 172 | + name: staging |
| 173 | + url: https://staging-interact.vercel.app |
| 174 | + |
| 175 | + steps: |
| 176 | + - name: Checkout code |
| 177 | + uses: actions/checkout@v4 |
| 178 | + |
| 179 | + - name: Download build artifacts |
| 180 | + uses: actions/download-artifact@v3 |
| 181 | + with: |
| 182 | + name: dist-${{ github.sha }} |
| 183 | + path: dist/ |
| 184 | + |
| 185 | + - name: Deploy to Vercel (Staging) |
| 186 | + uses: amondnet/vercel-action@v25 |
| 187 | + id: vercel-deploy |
| 188 | + with: |
| 189 | + vercel-token: ${{ secrets.VERCEL_TOKEN }} |
| 190 | + vercel-org-id: ${{ secrets.VERCEL_ORG_ID }} |
| 191 | + vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }} |
| 192 | + scope: ${{ secrets.VERCEL_ORG_ID }} |
| 193 | + working-directory: ./ |
| 194 | + continue-on-error: true |
| 195 | + |
| 196 | + - name: Comment on PR with deployment URL |
| 197 | + if: github.event_name == 'pull_request' |
| 198 | + uses: actions/github-script@v6 |
| 199 | + with: |
| 200 | + script: | |
| 201 | + github.rest.issues.createComment({ |
| 202 | + issue_number: context.issue.number, |
| 203 | + owner: context.repo.owner, |
| 204 | + repo: context.repo.repo, |
| 205 | + body: '✅ Staging deployment complete!\n\nURL: ${{ steps.vercel-deploy.outputs.preview-url }}' |
| 206 | + }) |
| 207 | + continue-on-error: true |
| 208 | + |
| 209 | + # Deploy to production (main branch only, manual approval required) |
| 210 | + deploy-production: |
| 211 | + name: Deploy to Production |
| 212 | + needs: [build, security] |
| 213 | + if: github.ref == 'refs/heads/main' && github.event_name == 'push' |
| 214 | + runs-on: ubuntu-latest |
| 215 | + environment: |
| 216 | + name: production |
| 217 | + url: https://interact.vercel.app |
| 218 | + |
| 219 | + steps: |
| 220 | + - name: Checkout code |
| 221 | + uses: actions/checkout@v4 |
| 222 | + |
| 223 | + - name: Download build artifacts |
| 224 | + uses: actions/download-artifact@v3 |
| 225 | + with: |
| 226 | + name: dist-${{ github.sha }} |
| 227 | + path: dist/ |
| 228 | + |
| 229 | + - name: Deploy to Vercel (Production) |
| 230 | + uses: amondnet/vercel-action@v25 |
| 231 | + with: |
| 232 | + vercel-token: ${{ secrets.VERCEL_TOKEN }} |
| 233 | + vercel-org-id: ${{ secrets.VERCEL_ORG_ID }} |
| 234 | + vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }} |
| 235 | + vercel-args: '--prod' |
| 236 | + scope: ${{ secrets.VERCEL_ORG_ID }} |
| 237 | + working-directory: ./ |
| 238 | + continue-on-error: true |
| 239 | + |
| 240 | + - name: Create deployment notification |
| 241 | + run: | |
| 242 | + echo "🚀 Production deployment completed!" |
| 243 | + echo "Commit: ${{ github.sha }}" |
| 244 | + echo "Deployed by: ${{ github.actor }}" |
| 245 | + continue-on-error: true |
0 commit comments