test(infra): enhance test infrastructure with comprehensive mocks and… #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI/CD Pipeline | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| pull_request: | |
| branches: [ main ] | |
| env: | |
| NODE_VERSION: '20' | |
| NEXT_TELEMETRY_DISABLED: 1 | |
| jobs: | |
| # Security and Code Quality | |
| security-scan: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Run security audit | |
| run: npm audit --audit-level moderate | |
| - name: Run ESLint | |
| run: npm run lint | |
| - name: Run Prettier check | |
| run: npm run format:check | |
| - name: Run TypeScript check | |
| run: npm run type-check | |
| - name: Check for unused code (knip) | |
| run: npx knip --production | |
| # Unit and Integration Tests | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Run unit tests | |
| run: npm run test:unit -- --coverage --watchAll=false | |
| - name: Upload coverage to Codecov | |
| uses: codecov/codecov-action@v3 | |
| with: | |
| file: ./coverage/lcov.info | |
| flags: unittests | |
| name: codecov-umbrella | |
| # E2E Tests | |
| e2e-test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Install Playwright browsers | |
| run: npx playwright install --with-deps | |
| - name: Build application | |
| run: npm run build | |
| - name: Run E2E tests | |
| run: npm run test:e2e | |
| - name: Upload E2E test results | |
| uses: actions/upload-artifact@v3 | |
| if: always() | |
| with: | |
| name: playwright-report | |
| path: playwright-report/ | |
| retention-days: 30 | |
| # Performance and Accessibility | |
| performance-test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build application | |
| run: npm run build | |
| - name: Run Lighthouse CI | |
| run: npm run build && npm run lhci autorun | |
| env: | |
| LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }} | |
| - name: Run bundle analysis | |
| run: npm run analyze | |
| - name: Check bundle size limits | |
| run: npm run size-limit | |
| # Build and Deploy | |
| build-and-deploy: | |
| needs: [security-scan, test, e2e-test, performance-test] | |
| runs-on: ubuntu-latest | |
| if: github.ref == 'refs/heads/main' | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build application | |
| run: npm run build | |
| env: | |
| NEXT_PUBLIC_SENTRY_DSN: ${{ secrets.SENTRY_DSN }} | |
| NEXT_PUBLIC_ENVIRONMENT: production | |
| - name: Run production build test | |
| run: npm run start & sleep 5 && curl -f http://localhost:3000 || exit 1 | |
| - name: Deploy to staging | |
| if: github.ref == 'refs/heads/develop' | |
| run: | | |
| echo "Deploying to staging environment..." | |
| # Add your staging deployment logic here | |
| - name: Deploy to production | |
| if: github.ref == 'refs/heads/main' | |
| run: | | |
| echo "Deploying to production environment..." | |
| # Add your production deployment logic here | |
| - name: Notify deployment | |
| uses: 8398a7/action-slack@v3 | |
| if: always() | |
| with: | |
| status: ${{ job.status }} | |
| channel: '#deployments' | |
| webhook_url: ${{ secrets.SLACK_WEBHOOK }} | |
| # Database Migration (if needed) | |
| migrate: | |
| needs: [security-scan, test] | |
| runs-on: ubuntu-latest | |
| if: github.ref == 'refs/heads/main' | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Run database migrations | |
| run: | | |
| echo "Running database migrations..." | |
| # Add migration logic here | |
| # Feature Flag Validation | |
| feature-flags: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Validate feature flags | |
| run: | | |
| echo "Validating feature flag configuration..." | |
| # Add feature flag validation logic here | |
| # Dependency Update Check | |
| dependency-update: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| cache: 'npm' | |
| - name: Check for outdated dependencies | |
| run: npm outdated || true | |
| - name: Create PR for dependency updates | |
| if: contains(steps.outdated.outputs.stdout, 'Package') | |
| uses: peter-evans/create-pull-request@v5 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| commit-message: 'chore: update dependencies' | |
| title: 'Dependency Updates' | |
| body: 'Automated dependency updates' | |
| branch: dependency-updates |