|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, develop] |
| 6 | + pull_request: |
| 7 | + branches: [main, develop] |
| 8 | + |
| 9 | +jobs: |
| 10 | + lint-and-build: |
| 11 | + name: Lint and Build |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + strategy: |
| 15 | + matrix: |
| 16 | + node-version: [18.x, 20.x] |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Checkout code |
| 20 | + uses: actions/checkout@v4 |
| 21 | + |
| 22 | + - name: Setup Node.js ${{ matrix.node-version }} |
| 23 | + uses: actions/setup-node@v4 |
| 24 | + with: |
| 25 | + node-version: ${{ matrix.node-version }} |
| 26 | + |
| 27 | + - name: Setup pnpm |
| 28 | + uses: pnpm/action-setup@v3 |
| 29 | + with: |
| 30 | + version: 8 |
| 31 | + |
| 32 | + - name: Get pnpm store directory |
| 33 | + shell: bash |
| 34 | + run: | |
| 35 | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV |
| 36 | +
|
| 37 | + - name: Cache pnpm dependencies |
| 38 | + uses: actions/cache@v4 |
| 39 | + with: |
| 40 | + path: ${{ env.STORE_PATH }} |
| 41 | + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} |
| 42 | + restore-keys: | |
| 43 | + ${{ runner.os }}-pnpm-store- |
| 44 | +
|
| 45 | + - name: Cache Next.js build |
| 46 | + uses: actions/cache@v4 |
| 47 | + with: |
| 48 | + path: | |
| 49 | + ~/.npm |
| 50 | + ${{ github.workspace }}/.next/cache |
| 51 | + key: ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }} |
| 52 | + restore-keys: | |
| 53 | + ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}- |
| 54 | +
|
| 55 | + - name: Install dependencies |
| 56 | + run: pnpm install --frozen-lockfile |
| 57 | + |
| 58 | + - name: Run ESLint |
| 59 | + run: pnpm run lint |
| 60 | + |
| 61 | + - name: Type check |
| 62 | + run: pnpm run type-check |
| 63 | + |
| 64 | + - name: Build project |
| 65 | + run: pnpm run build |
| 66 | + env: |
| 67 | + NODE_ENV: production |
| 68 | + |
| 69 | + - name: Upload build artifacts |
| 70 | + if: matrix.node-version == '20.x' |
| 71 | + uses: actions/upload-artifact@v4 |
| 72 | + with: |
| 73 | + name: build-output |
| 74 | + path: .next |
| 75 | + retention-days: 7 |
| 76 | + |
| 77 | + code-quality: |
| 78 | + name: Code Quality Checks |
| 79 | + runs-on: ubuntu-latest |
| 80 | + |
| 81 | + steps: |
| 82 | + - name: Checkout code |
| 83 | + uses: actions/checkout@v4 |
| 84 | + |
| 85 | + - name: Setup Node.js |
| 86 | + uses: actions/setup-node@v4 |
| 87 | + with: |
| 88 | + node-version: 20.x |
| 89 | + |
| 90 | + - name: Setup pnpm |
| 91 | + uses: pnpm/action-setup@v3 |
| 92 | + with: |
| 93 | + version: 8 |
| 94 | + |
| 95 | + - name: Install dependencies |
| 96 | + run: pnpm install --frozen-lockfile |
| 97 | + |
| 98 | + - name: Check for console statements |
| 99 | + run: | |
| 100 | + echo "Checking for console statements..." |
| 101 | + ! git grep -n "console\." -- "*.ts" "*.tsx" "*.js" "*.jsx" || echo "Warning: Console statements found" |
| 102 | + continue-on-error: true |
| 103 | + |
| 104 | + - name: Check for TODO comments |
| 105 | + run: | |
| 106 | + echo "Checking for TODO comments..." |
| 107 | + git grep -n "TODO" -- "*.ts" "*.tsx" "*.js" "*.jsx" || echo "No TODOs found" |
| 108 | + continue-on-error: true |
| 109 | + |
| 110 | + status-check: |
| 111 | + name: All Checks Passed |
| 112 | + runs-on: ubuntu-latest |
| 113 | + needs: [lint-and-build, code-quality] |
| 114 | + if: always() |
| 115 | + |
| 116 | + steps: |
| 117 | + - name: Check if all jobs passed |
| 118 | + if: needs.lint-and-build.result != 'success' || needs.code-quality.result != 'success' |
| 119 | + run: | |
| 120 | + echo "One or more checks failed" |
| 121 | + exit 1 |
| 122 | +
|
| 123 | + - name: All checks passed |
| 124 | + run: echo "✅ All CI checks passed successfully!" |
0 commit comments