name: CI/CD Pipeline on: push: branches: [main] pull_request: branches: [main] jobs: # ═══════════════════════════════════════════════════════════ # Lint & Type Check # ═══════════════════════════════════════════════════════════ lint: name: Lint & Type Check runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: pnpm/action-setup@v3 with: version: 9 - uses: actions/setup-node@v4 with: node-version: 20 cache: 'pnpm' - run: pnpm install --frozen-lockfile - run: pnpm lint - run: pnpm build # ═══════════════════════════════════════════════════════════ # Backend Tests # ═══════════════════════════════════════════════════════════ test-server: name: Backend Tests runs-on: ubuntu-latest services: postgres: image: postgres:16-alpine env: POSTGRES_DB: codesync_test POSTGRES_USER: test POSTGRES_PASSWORD: test ports: - 5432:5432 options: >- --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 steps: - uses: actions/checkout@v4 - uses: pnpm/action-setup@v3 with: version: 9 - uses: actions/setup-node@v4 with: node-version: 20 cache: 'pnpm' - run: pnpm install --frozen-lockfile - name: Run migrations working-directory: apps/server run: npx prisma migrate deploy env: DATABASE_URL: postgresql://test:test@localhost:5432/codesync_test - name: Run tests working-directory: apps/server run: pnpm test env: DATABASE_URL: postgresql://test:test@localhost:5432/codesync_test JWT_ACCESS_SECRET: test-secret-for-ci JWT_REFRESH_SECRET: test-refresh-for-ci UPSTASH_REDIS_URL: http://localhost:6379 UPSTASH_REDIS_TOKEN: test # ═══════════════════════════════════════════════════════════ # Deploy # ═══════════════════════════════════════════════════════════ deploy: name: Deploy runs-on: ubuntu-latest needs: [lint, test-server] if: github.ref == 'refs/heads/main' && github.event_name == 'push' steps: - uses: actions/checkout@v4 # Deploy frontend to Vercel - name: Deploy Frontend uses: amondnet/vercel-action@v25 with: vercel-token: ${{ secrets.VERCEL_TOKEN }} vercel-org-id: ${{ secrets.VERCEL_ORG_ID }} vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }} working-directory: apps/web vercel-args: '--prod' # Deploy backend to Railway - name: Deploy Backend uses: bervProject/railway-deploy@main with: railway_token: ${{ secrets.RAILWAY_TOKEN }} service: codesync-server