name: CI on: push: branches: [main, develop] pull_request: branches: [main, develop] jobs: # Job 1: Lint and Typecheck (Fast feedback) lint-typecheck: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Setup Node.js uses: actions/setup-node@v3 with: node-version: "20" cache: "npm" - name: Install dependencies run: npm ci - name: Run ESLint run: npm run lint - name: Run Typecheck run: npm run typecheck # Job 2: Unit and Integration Tests tests: runs-on: ubuntu-latest needs: lint-typecheck steps: - uses: actions/checkout@v3 - name: Setup Node.js uses: actions/setup-node@v3 with: node-version: "20" cache: "npm" - name: Install dependencies run: npm ci - name: Run Unit Tests run: npm run test:unit - name: Run Integration Tests run: npm run test:integration # Job 3: Contract Tests (API/Website compatibility) contract-tests: runs-on: ubuntu-latest needs: lint-typecheck steps: - uses: actions/checkout@v3 - name: Setup Node.js uses: actions/setup-node@v3 with: node-version: "20" cache: "npm" - name: Install dependencies run: npm ci - name: Run API Contract Validation run: npm run test:api:contracts - name: Generate OpenAPI spec run: npm run api:generate-spec - name: Generate TypeScript types run: npm run api:generate-types - name: Run Contract Compatibility Check run: npm run test:contract:compatibility - name: Verify Website Type Checking run: npm run website:type-check - name: Upload generated types as artifacts uses: actions/upload-artifact@v3 with: name: generated-types path: apps/website/lib/types/generated/ retention-days: 7 # Job 4: E2E Tests (Only on main/develop push, not on PRs) e2e-tests: runs-on: ubuntu-latest needs: [lint-typecheck, tests, contract-tests] if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop') steps: - uses: actions/checkout@v3 - name: Setup Node.js uses: actions/setup-node@v3 with: node-version: "20" cache: "npm" - name: Install dependencies run: npm ci - name: Run E2E Tests run: npm run test:e2e # Job 5: Comment PR with results (Only on PRs) comment-pr: runs-on: ubuntu-latest needs: [lint-typecheck, tests, contract-tests] if: github.event_name == 'pull_request' steps: - name: Comment PR with results uses: actions/github-script@v6 with: script: | const fs = require('fs'); const path = require('path'); // Read any contract change reports const reportPath = path.join(process.cwd(), 'contract-report.json'); if (fs.existsSync(reportPath)) { const report = JSON.parse(fs.readFileSync(reportPath, 'utf8')); const comment = ` ## 🔍 CI Results ✅ **All checks passed!** ### Changes Summary: - Total changes: ${report.totalChanges} - Breaking changes: ${report.breakingChanges} - Added: ${report.added} - Removed: ${report.removed} - Modified: ${report.modified} Generated types are available as artifacts. `; github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body: comment }); } # Job 6: Commit generated types (Only on main branch push) commit-types: runs-on: ubuntu-latest needs: [lint-typecheck, tests, contract-tests] if: github.event_name == 'push' && github.ref == 'refs/heads/main' steps: - uses: actions/checkout@v3 - name: Setup Node.js uses: actions/setup-node@v3 with: node-version: "20" cache: "npm" - name: Install dependencies run: npm ci - name: Generate and snapshot types run: | npm run api:generate-spec npm run api:generate-types - name: Commit generated types run: | git config --local user.email "github-actions[bot]@users.noreply.github.com" git config --local user.name "github-actions[bot]" git add apps/website/lib/types/generated/ git diff --staged --quiet || git commit -m "chore: update generated API types [skip ci]" git push