Feat/improved rewards tab #750
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, staging] | |
| pull_request: | |
| branches: [main, develop, staging] | |
| workflow_dispatch: # Allow manual triggering | |
| env: | |
| NODE_VERSION: '20' | |
| PNPM_VERSION: '8' | |
| jobs: | |
| # Code Quality Checks | |
| code-quality: | |
| name: Code Quality & Linting | |
| 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 TypeScript type checking | |
| run: npm run type-check | |
| - name: Run ESLint | |
| run: npm run lint | |
| - name: Check Prettier formatting | |
| run: npm run format:check | |
| - name: Check for console.log statements | |
| run: | | |
| echo "π Checking for console.log statements..." | |
| if grep -r "console\.log" --include="*.ts" --include="*.tsx" --include="*.js" --include="*.jsx" src/ components/ hooks/ lib/ app/; then | |
| echo "β Found console.log statements. Please remove them before committing." | |
| exit 1 | |
| else | |
| echo "β No console.log statements found." | |
| fi | |
| - name: Check for TODO/FIXME comments | |
| run: | | |
| echo "π Checking for TODO/FIXME comments..." | |
| if grep -r "TODO\|FIXME" --include="*.ts" --include="*.tsx" --include="*.js" --include="*.jsx" src/ components/ hooks/ lib/ app/; then | |
| echo "β οΈ Found TODO/FIXME comments. Please address them before merging." | |
| # Don't fail the build, just warn | |
| else | |
| echo "β No TODO/FIXME comments found." | |
| fi | |
| # Build & Test | |
| build: | |
| name: Build & Test | |
| runs-on: ubuntu-latest | |
| needs: code-quality | |
| 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: Set up environment variables | |
| run: | | |
| echo "π§ Setting up environment variables for build..." | |
| echo "NEXT_PUBLIC_API_URL=http://localhost:3000/api" >> .env.local | |
| echo "NEXT_PUBLIC_APP_URL=http://localhost:3000" >> .env.local | |
| echo "NEXTAUTH_SECRET=ci-test-secret-key" >> .env.local | |
| echo "NEXTAUTH_URL=http://localhost:3000" >> .env.local | |
| echo "DATABASE_URL=postgresql://test:test@localhost:5432/test_db" >> .env.local | |
| - name: Build application | |
| run: npm run build | |
| continue-on-error: true | |
| - name: Upload build artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: build-files | |
| path: .next/ | |
| retention-days: 7 | |
| # Security Audit | |
| security: | |
| name: Security Audit | |
| 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: Check for known vulnerabilities | |
| run: | | |
| echo "π Checking for known vulnerabilities..." | |
| npm audit --audit-level=moderate --json > audit-report.json | |
| if jq -e '(.metadata.vulnerabilities.moderate + .metadata.vulnerabilities.high + .metadata.vulnerabilities.critical) > 0' audit-report.json; then | |
| echo "β Found security vulnerabilities. Please fix them before merging." | |
| cat audit-report.json | jq '.metadata.vulnerabilities' | |
| exit 1 | |
| else | |
| echo "β No security vulnerabilities found." | |
| fi | |
| # Commit Message Validation | |
| commit-message: | |
| name: Commit Message Validation | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'pull_request' | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Validate commit messages | |
| run: | | |
| echo "π Validating commit messages..." | |
| # Conventional commit regex | |
| commit_regex='^(feat|fix|docs|style|refactor|test|chore|perf|ci|build|revert)(\(.+\))?: .{1,50}' | |
| # Get all commits in the PR | |
| commits=$(git log --pretty=format:"%H %s" origin/main..HEAD) | |
| invalid_commits="" | |
| while IFS= read -r commit; do | |
| hash=$(echo "$commit" | cut -d' ' -f1) | |
| message=$(echo "$commit" | cut -d' ' -f2-) | |
| # Skip git-generated merge commits | |
| if echo "$message" | grep -qE "^Merge (branch|pull request|remote-tracking branch|[0-9a-f]{7,40}) "; then | |
| continue | |
| fi | |
| if ! echo "$message" | grep -qE "$commit_regex"; then | |
| invalid_commits="$invalid_commits\n$hash: $message" | |
| fi | |
| done <<< "$commits" | |
| if [ -n "$invalid_commits" ]; then | |
| echo "β Invalid commit messages found:" | |
| echo -e "$invalid_commits" | |
| echo "" | |
| echo "β Please use conventional commit format:" | |
| echo " <type>(<scope>): <description>" | |
| echo "" | |
| echo "π Examples:" | |
| echo " feat: add new feature" | |
| echo " fix(wallet): resolve issue" | |
| echo " docs: update documentation" | |
| echo " style: format code" | |
| exit 1 | |
| else | |
| echo "β All commit messages follow conventional format." | |
| fi | |
| # # Bundle Analysis | |
| # bundle-analysis: | |
| # name: Bundle Analysis | |
| # runs-on: ubuntu-latest | |
| # needs: build | |
| # if: github.event_name == 'pull_request' | |
| # 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: Set up environment variables | |
| # run: | | |
| # echo "π§ Setting up environment variables for build..." | |
| # echo "NEXT_PUBLIC_API_URL=http://localhost:3000/api" >> .env.local | |
| # echo "NEXT_PUBLIC_APP_URL=http://localhost:3000" >> .env.local | |
| # echo "NEXTAUTH_SECRET=ci-test-secret-key" >> .env.local | |
| # echo "NEXTAUTH_URL=http://localhost:3000" >> .env.local | |
| # echo "DATABASE_URL=postgresql://test:test@localhost:5432/test_db" >> .env.local | |
| # - name: Build with bundle analysis | |
| # run: | | |
| # npm run build | |
| # npx @next/bundle-analyzer .next/static/chunks/**/*.js --out dist/bundle-analysis.html | |
| # - name: Upload bundle analysis | |
| # uses: actions/upload-artifact@v4 | |
| # with: | |
| # name: bundle-analysis | |
| # path: dist/bundle-analysis.html | |
| # retention-days: 30 | |
| # # Performance Testing | |
| # performance: | |
| # name: Performance Testing | |
| # runs-on: ubuntu-latest | |
| # needs: build | |
| # if: github.event_name == 'pull_request' | |
| # 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: Set up environment variables | |
| # run: | | |
| # echo "π§ Setting up environment variables for build..." | |
| # echo "NEXT_PUBLIC_API_URL=http://localhost:3000/api" >> .env.local | |
| # echo "NEXT_PUBLIC_APP_URL=http://localhost:3000" >> .env.local | |
| # echo "NEXTAUTH_SECRET=ci-test-secret-key" >> .env.local | |
| # echo "NEXTAUTH_URL=http://localhost:3000" >> .env.local | |
| # echo "DATABASE_URL=postgresql://test:test@localhost:5432/test_db" >> .env.local | |
| # - name: Build application | |
| # run: npm run build | |
| # - name: Check bundle size | |
| # run: | | |
| # echo "π¦ Checking bundle size..." | |
| # # Get the main bundle size | |
| # main_bundle_size=$(du -s .next/static/chunks/ | grep main | awk '{print $1}') | |
| # # Set threshold (in KB) | |
| # threshold=500 | |
| # if [ "$main_bundle_size" -gt "$threshold" ]; then | |
| # echo "β οΈ Bundle size ($main_bundle_size KB) exceeds threshold ($threshold KB)" | |
| # echo "Consider optimizing your bundle size." | |
| # else | |
| # echo "β Bundle size ($main_bundle_size KB) is within acceptable limits." | |
| # fi | |
| # # Deploy to Staging (if on develop branch) | |
| # deploy-staging: | |
| # name: Deploy to Staging | |
| # runs-on: ubuntu-latest | |
| # needs: [code-quality, build, security] | |
| # if: github.ref == 'refs/heads/develop' && github.event_name == 'push' | |
| # environment: staging | |
| # 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: Set up environment variables | |
| # run: | | |
| # echo "π§ Setting up environment variables for build..." | |
| # echo "NEXT_PUBLIC_API_URL=http://localhost:3000/api" >> .env.local | |
| # echo "NEXT_PUBLIC_APP_URL=http://localhost:3000" >> .env.local | |
| # echo "NEXTAUTH_SECRET=ci-test-secret-key" >> .env.local | |
| # echo "NEXTAUTH_URL=http://localhost:3000" >> .env.local | |
| # echo "DATABASE_URL=postgresql://test:test@localhost:5432/test_db" >> .env.local | |
| # - name: Build application | |
| # run: npm run build | |
| # - name: Deploy to staging | |
| # run: | | |
| # echo "π Deploying to staging environment..." | |
| # # Add your staging deployment commands here | |
| # # Example: npm run deploy:staging | |
| # echo "β Successfully deployed to staging!" | |
| # # Deploy to Production (if on main branch) | |
| # deploy-production: | |
| # name: Deploy to Production | |
| # runs-on: ubuntu-latest | |
| # needs: [code-quality, build, security, commit-message] | |
| # if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| # environment: production | |
| # 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: Set up environment variables | |
| # run: | | |
| # echo "π§ Setting up environment variables for build..." | |
| # echo "NEXT_PUBLIC_API_URL=http://localhost:3000/api" >> .env.local | |
| # echo "NEXT_PUBLIC_APP_URL=http://localhost:3000" >> .env.local | |
| # echo "NEXTAUTH_SECRET=ci-test-secret-key" >> .env.local | |
| # echo "NEXTAUTH_URL=http://localhost:3000" >> .env.local | |
| # echo "DATABASE_URL=postgresql://test:test@localhost:5432/test_db" >> .env.local | |
| # - name: Build application | |
| # run: npm run build | |
| # - name: Deploy to production | |
| # run: | | |
| # echo "π Deploying to production environment..." | |
| # # Add your production deployment commands here | |
| # # Example: npm run deploy:production | |
| # echo "β Successfully deployed to production!" | |
| # Notify on Failure | |
| notify-failure: | |
| name: Notify on Failure | |
| runs-on: ubuntu-latest | |
| needs: [code-quality, build, security] | |
| if: failure() | |
| steps: | |
| - name: Notify failure | |
| run: | | |
| echo "β CI/CD pipeline failed!" | |
| echo "Please check the logs and fix the issues before merging." | |
| # Add your notification logic here (Slack, email, etc.) |