|
1 | 1 | name: PR Quality Gate |
2 | 2 |
|
3 | 3 | on: |
| 4 | + pull_request: |
| 5 | + branches: [ "leader" ] |
4 | 6 | workflow_dispatch: |
| 7 | + inputs: |
| 8 | + branch: |
| 9 | + description: 'Branch to check' |
| 10 | + required: true |
| 11 | + default: 'leader' |
| 12 | + |
| 13 | +env: |
| 14 | + FORCE_COLOR: 1 |
| 15 | + # Browsers are installed INSIDE the workspace so they persist with clean: false |
| 16 | + PLAYWRIGHT_BROWSERS_PATH: ${{ github.workspace }}/.cache/ms-playwright |
5 | 17 |
|
6 | 18 | jobs: |
7 | | - pr-quality: |
8 | | - runs-on: ubuntu-latest |
9 | | - |
| 19 | + # =========================================================================== |
| 20 | + # JOB 1: INFRASTRUCTURE SETUP (The "Clean Slate") |
| 21 | + # Wipes workspace, installs deps, and prepares the environment for all jobs. |
| 22 | + # =========================================================================== |
| 23 | + infra-setup: |
| 24 | + name: 🏗️ Infra Setup |
| 25 | + runs-on: self-hosted |
| 26 | + timeout-minutes: 10 |
| 27 | + steps: |
| 28 | + - name: Checkout |
| 29 | + uses: actions/checkout@v4 |
| 30 | + with: |
| 31 | + ref: ${{ inputs.branch || github.ref }} |
| 32 | + fetch-depth: 0 |
| 33 | + clean: true # 🧹 Wipes previous run artifacts to ensure a fresh start |
| 34 | + |
| 35 | + # --- GLOBAL PERSISTENCE CONFIG --- |
| 36 | + - name: Install pnpm |
| 37 | + uses: pnpm/action-setup@v4 |
| 38 | + with: |
| 39 | + run_install: false |
| 40 | + |
| 41 | + - name: Configure Persistent Store |
| 42 | + shell: bash |
| 43 | + run: | |
| 44 | + mkdir -p ~/.local/share/pnpm/store |
| 45 | + pnpm config set store-dir ~/.local/share/pnpm/store |
| 46 | + pnpm config set side-effects-cache true |
| 47 | +
|
| 48 | + - name: Setup Node.js |
| 49 | + uses: actions/setup-node@v4 |
| 50 | + with: |
| 51 | + node-version: "20.x" |
| 52 | + # --------------------------------- |
| 53 | + |
| 54 | + - name: Create Runtime Envs |
| 55 | + run: | |
| 56 | + mkdir -p logs |
| 57 | + echo "NEXTAUTH_URL=http://127.0.0.1:3000" > .env.local |
| 58 | + echo "NEXTAUTH_SECRET=ci-secret" >> .env.local |
| 59 | +
|
| 60 | + - name: Run Setup Script |
| 61 | + run: | |
| 62 | + chmod +x ./scripts/setup.sh |
| 63 | + ./scripts/setup.sh |
| 64 | + # This installs dependencies into ./node_modules |
| 65 | + |
| 66 | + - name: Install Playwright (Binary Only) |
| 67 | + run: pnpm exec playwright install chromium |
| 68 | + # Installs into ./.cache/ms-playwright (inside workspace) |
| 69 | + |
| 70 | + # =========================================================================== |
| 71 | + # JOB 2: QUALITY CHECKS |
| 72 | + # Reuses the workspace from Job 1 (No re-install needed) |
| 73 | + # =========================================================================== |
| 74 | + quality-check: |
| 75 | + name: 🛡️ Quality Check |
| 76 | + needs: infra-setup |
| 77 | + runs-on: self-hosted |
| 78 | + timeout-minutes: 10 |
10 | 79 | steps: |
11 | | - - name: Checkout code |
12 | | - uses: actions/checkout@v4 |
13 | | - with: |
14 | | - fetch-depth: 0 |
15 | | - |
16 | | - - name: Setup Node.js |
17 | | - uses: actions/setup-node@v4 |
18 | | - with: |
19 | | - node-version: "20.x" |
20 | | - cache: "npm" |
21 | | - |
22 | | - - name: Install dependencies |
23 | | - run: npm ci |
24 | | - |
25 | | - - name: Check PR title format |
26 | | - run: | |
27 | | - # This check is informational for manual runs. |
28 | | - # In a real PR context, you would use github.event.pull_request.title |
29 | | - echo "Note: This check is for a manual run. In a PR, it would validate the title." |
30 | | -
|
31 | | - - name: Check for large files |
32 | | - run: | |
33 | | - find . -type f -size +1M -not -path "./node_modules/*" -not -path "./.git/*" | while read file; do |
34 | | - echo "::warning::Large file detected: $file ($(du -h "$file" | cut -f1))" |
35 | | - done |
36 | | - |
37 | | - - name: Lint commit messages |
38 | | - run: | |
39 | | - echo "Note: This check is for a manual run. In a PR, it would lint commit messages." |
40 | | - if git rev-parse --verify HEAD~1 >/dev/null 2>&1; then |
41 | | - git log --oneline HEAD~1..HEAD | while read line; do |
42 | | - if [[ ! "$line" =~ ^[a-f0-9]+\ (feat|fix|docs|style|refactor|test|chore|perf|ci)(\(.+\))?: ]]; then |
43 | | - echo "::warning::Commit message should follow conventional commits: $line" |
44 | | - fi |
45 | | - done |
46 | | - fi |
| 80 | + - uses: actions/checkout@v4 |
| 81 | + with: |
| 82 | + ref: ${{ inputs.branch || github.ref }} |
| 83 | + clean: false # ⚡ KEEP WORKSPACE (Preserves node_modules & browsers) |
| 84 | + |
| 85 | + # We still set up pnpm/node just to ensure the binaries are in PATH |
| 86 | + - uses: pnpm/action-setup@v4 |
| 87 | + with: { run_install: false } |
| 88 | + - uses: actions/setup-node@v4 |
| 89 | + with: { node-version: "20.x" } |
| 90 | + |
| 91 | + - name: Lint Code |
| 92 | + run: pnpm run lint |
| 93 | + |
| 94 | + - name: Verify Build |
| 95 | + run: pnpm run build |
| 96 | + |
| 97 | + # =========================================================================== |
| 98 | + # JOB 3: CORE LOGIC TESTS |
| 99 | + # Reuses workspace. Runs functional tests. |
| 100 | + # =========================================================================== |
| 101 | + core-tests: |
| 102 | + name: 🧪 Core Logic |
| 103 | + needs: quality-check |
| 104 | + runs-on: self-hosted |
| 105 | + timeout-minutes: 15 |
| 106 | + steps: |
| 107 | + - uses: actions/checkout@v4 |
| 108 | + with: |
| 109 | + ref: ${{ inputs.branch || github.ref }} |
| 110 | + clean: false # ⚡ KEEP WORKSPACE |
| 111 | + |
| 112 | + - uses: pnpm/action-setup@v4 |
| 113 | + with: { run_install: false } |
| 114 | + - uses: actions/setup-node@v4 |
| 115 | + with: { node-version: "20.x" } |
| 116 | + |
| 117 | + - name: Configure Envs |
| 118 | + run: | |
| 119 | + # Re-write envs just in case, but folder is persisted |
| 120 | + echo "NEXTAUTH_URL=http://127.0.0.1:3000" > .env.local |
| 121 | + echo "NEXTAUTH_SECRET=ci-secret" >> .env.local |
| 122 | +
|
| 123 | + - name: Run Infra Tests |
| 124 | + run: pnpm run test:infra |
| 125 | + |
| 126 | + - name: Run Unit Tests |
| 127 | + run: pnpm run test:unit |
| 128 | + |
| 129 | + # =========================================================================== |
| 130 | + # JOB 4: VISUAL REGRESSION TESTS |
| 131 | + # Reuses workspace. Runs visual tests. |
| 132 | + # =========================================================================== |
| 133 | + visual-tests: |
| 134 | + name: 🎨 Visual Regression |
| 135 | + needs: core-tests |
| 136 | + runs-on: self-hosted |
| 137 | + timeout-minutes: 15 |
| 138 | + steps: |
| 139 | + - uses: actions/checkout@v4 |
| 140 | + with: |
| 141 | + ref: ${{ inputs.branch || github.ref }} |
| 142 | + clean: false # ⚡ KEEP WORKSPACE |
| 143 | + |
| 144 | + - uses: pnpm/action-setup@v4 |
| 145 | + with: { run_install: false } |
| 146 | + - uses: actions/setup-node@v4 |
| 147 | + with: { node-version: "20.x" } |
| 148 | + |
| 149 | + - name: Configure Envs |
| 150 | + run: | |
| 151 | + echo "NEXTAUTH_URL=http://127.0.0.1:3000" > .env.local |
| 152 | + echo "NEXTAUTH_SECRET=ci-secret" >> .env.local |
| 153 | +
|
| 154 | + - name: Run Visual Tests |
| 155 | + run: pnpm run test:json |
47 | 156 |
|
| 157 | + - name: Upload Report on Failure |
| 158 | + if: failure() |
| 159 | + uses: actions/upload-artifact@v4 |
| 160 | + with: |
| 161 | + name: playwright-report-visual |
| 162 | + path: playwright-report/ |
| 163 | + retention-days: 5 |
0 commit comments