1010 required : true
1111 default : ' leader'
1212
13+ env :
14+ FORCE_COLOR : 1
15+ # Global cache location for all jobs
16+ PLAYWRIGHT_BROWSERS_PATH : ${{ github.workspace }}/.cache/ms-playwright
17+
1318jobs :
14- quality-gate :
19+ # ===========================================================================
20+ # JOB 1: INFRASTRUCTURE & BUILD
21+ # Checks: Linting, Typos, Build Compilation, Commit Messages
22+ # ===========================================================================
23+ infra-check :
24+ name : 🏗️ Infra & Build
1525 runs-on : self-hosted
16- timeout-minutes : 20
17-
18- env :
19- FORCE_COLOR : 1
20- # Critical: Tell Playwright where to look for the cached binaries
21- PLAYWRIGHT_BROWSERS_PATH : ${{ github.workspace }}/.cache/ms-playwright
22-
26+ timeout-minutes : 10
2327 steps :
24- - name : Checkout & Prep
28+ - name : Checkout
2529 uses : actions/checkout@v4
26- with :
27- ref : ${{ inputs.branch || github.ref }}
28- fetch-depth : 0
29- clean : true
30+ with : { ref: ${{ inputs.branch || github.ref }}, fetch-depth: 0, clean: true }
3031
31- # 1. Setup pnpm (Package Manager)
32+ # --- REPEATED SETUP (No Reusable Workflow) ---
3233 - name : Install pnpm
3334 uses : pnpm/action-setup@v4
34- with :
35- # Version inferred from package.json "packageManager"
36- run_install : false
35+ with : { run_install: false }
3736
38- # 2. Get Dynamic Store Path (Fixes "0% Cache Hit")
3937 - name : Get pnpm store directory
4038 id : pnpm-cache
4139 shell : bash
42- run : |
43- echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_OUTPUT
40+ run : echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_OUTPUT
4441
45- # 3. Explicit pnpm Store Cache
4642 - name : Setup pnpm cache
4743 uses : actions/cache@v4
4844 with :
@@ -51,69 +47,147 @@ jobs:
5147 restore-keys : |
5248 ${{ runner.os }}-pnpm-store-
5349
54- # 4. Setup Node.js (Linking to the cache we just set up)
5550 - name : Setup Node.js
5651 uses : actions/setup-node@v4
57- with :
58- node-version : " 20.x"
59- cache-dependency-path : pnpm-lock.yaml
60- # We handle store caching manually above for better reliability on self-hosted
52+ with : { node-version: "20.x", cache-dependency-path: pnpm-lock.yaml }
53+
54+ - name : Configure pnpm & Install
55+ run : |
56+ pnpm config set side-effects-cache true
57+ pnpm install --frozen-lockfile --prefer-offline
58+ # ---------------------------------------------
59+
60+ - name : Create Runtime Envs
61+ run : |
62+ mkdir -p logs
63+ echo "NEXTAUTH_URL=http://127.0.0.1:3000" > .env.local
64+ echo "NEXTAUTH_SECRET=ci-secret" >> .env.local
65+
66+ - name : Lint Code
67+ run : pnpm run lint
6168
62- # 5. Cache Next.js Build
63- - name : Cache Next.js
69+ - name : Verify Build
70+ run : pnpm run build
71+
72+ - name : Lint Commits
73+ run : |
74+ RANGE="origin/leader..HEAD"
75+ if ! git rev-parse --verify origin/leader >/dev/null 2>&1; then RANGE="HEAD"; fi
76+ git log --format=%s $RANGE | while read line; do
77+ if [[ ! "$line" =~ ^(feat|fix|docs|style|refactor|test|chore|perf|ci)(\(.+\))?: ]]; then
78+ echo "::error::Invalid Commit Message: $line"
79+ exit 1
80+ fi
81+ done
82+
83+ # ===========================================================================
84+ # JOB 2: CORE LOGIC TESTS
85+ # Checks: Functional tests (API, Auth, State) - Skips visuals
86+ # ===========================================================================
87+ core-tests :
88+ name : 🧪 Core Logic
89+ runs-on : self-hosted
90+ timeout-minutes : 15
91+ steps :
92+ - name : Checkout
93+ uses : actions/checkout@v4
94+ with : { ref: ${{ inputs.branch || github.ref }}, clean: true }
95+
96+ # --- REPEATED SETUP ---
97+ - uses : pnpm/action-setup@v4
98+ with : { run_install: false }
99+ - id : pnpm-cache
100+ run : echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_OUTPUT
101+ - uses : actions/cache@v4
102+ with :
103+ path : ${{ steps.pnpm-cache.outputs.STORE_PATH }}
104+ key : ${{ runner.os }}-pnpm-store-${{ hashFiles('pnpm-lock.yaml') }}
105+ restore-keys : ${{ runner.os }}-pnpm-store-
106+ - uses : actions/setup-node@v4
107+ with : { node-version: "20.x", cache-dependency-path: pnpm-lock.yaml }
108+
109+ - name : Cache Browsers
110+ id : playwright-cache
64111 uses : actions/cache@v4
65112 with :
66- path : |
67- ${{ github.workspace }}/.next/cache
68- key : ${{ runner.os }}-nextjs-${{ hashFiles('pnpm-lock.yaml') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
69- restore-keys : |
70- ${{ runner.os }}-nextjs-${{ hashFiles('pnpm-lock.yaml') }}-
113+ path : ${{ env.PLAYWRIGHT_BROWSERS_PATH }}
114+ key : ${{ runner.os }}-playwright-${{ hashFiles('pnpm-lock.yaml') }}
115+ restore-keys : ${{ runner.os }}-playwright-
71116
72- # 6. Cache Playwright Browsers
73- - name : Cache Playwright Browsers
74- uses : actions/cache@v4
117+ - run : |
118+ pnpm config set side-effects-cache true
119+ pnpm install --frozen-lockfile --prefer-offline
120+
121+ - name : Install Playwright (Binary Only)
122+ if : steps.playwright-cache.outputs.cache-hit != 'true'
123+ run : pnpm exec playwright install chromium
124+ # ----------------------
125+
126+ - name : Create Runtime Envs
127+ run : |
128+ echo "NEXTAUTH_URL=http://127.0.0.1:3000" > .env.local
129+ echo "NEXTAUTH_SECRET=ci-secret" >> .env.local
130+
131+ - name : Run Core Tests (Skip Visuals)
132+ # Using CLI flag --grep-invert to skip tests tagged with @visual
133+ run : pnpm exec playwright test --project=chromium --grep-invert "@visual"
134+
135+ # ===========================================================================
136+ # JOB 3: VISUAL REGRESSION TESTS
137+ # Checks: Screenshot comparisons
138+ # ===========================================================================
139+ visual-tests :
140+ name : 🎨 Visual Regression
141+ runs-on : self-hosted
142+ timeout-minutes : 15
143+ steps :
144+ - name : Checkout
145+ uses : actions/checkout@v4
146+ with : { ref: ${{ inputs.branch || github.ref }}, clean: true }
147+
148+ # --- REPEATED SETUP ---
149+ - uses : pnpm/action-setup@v4
150+ with : { run_install: false }
151+ - id : pnpm-cache
152+ run : echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_OUTPUT
153+ - uses : actions/cache@v4
154+ with :
155+ path : ${{ steps.pnpm-cache.outputs.STORE_PATH }}
156+ key : ${{ runner.os }}-pnpm-store-${{ hashFiles('pnpm-lock.yaml') }}
157+ restore-keys : ${{ runner.os }}-pnpm-store-
158+ - uses : actions/setup-node@v4
159+ with : { node-version: "20.x", cache-dependency-path: pnpm-lock.yaml }
160+
161+ - name : Cache Browsers
75162 id : playwright-cache
163+ uses : actions/cache@v4
76164 with :
77165 path : ${{ env.PLAYWRIGHT_BROWSERS_PATH }}
78166 key : ${{ runner.os }}-playwright-${{ hashFiles('pnpm-lock.yaml') }}
79- restore-keys : |
80- ${{ runner.os }}-playwright-
167+ restore-keys : ${{ runner.os }}-playwright-
81168
82- - name : Create Runtime Directories
83- run : |
84- mkdir -p logs
85- echo "✅ Created 'logs' directory"
169+ - run : |
170+ pnpm config set side-effects-cache true
171+ pnpm install --frozen-lockfile --prefer-offline
86172
87- - name : Configure .env.local
88- run : |
89- echo "📝 Creating .env.local with development defaults..."
90- cat > .env.local <<EOL
91- NEXTAUTH_URL=http://127.0.0.1:3000
92- NEXTAUTH_SECRET=jules-dev-environment-secret-123
93- SPOTIFY_CLIENT_ID=placeholder_id
94- SPOTIFY_CLIENT_SECRET=placeholder_secret
95- EOL
96-
97- # 7. Optimized Dependency Install
98- - name : Configure pnpm settings
99- run : pnpm config set side-effects-cache true
100-
101- - name : Install Dependencies
102- # --prefer-offline: Trust the store cache we just restored
103- run : pnpm install --frozen-lockfile --prefer-offline
104-
105- # 8. Install Playwright (No Sudo / User Space Only)
106- - name : Install Playwright Browsers
173+ - name : Install Playwright (Binary Only)
107174 if : steps.playwright-cache.outputs.cache-hit != 'true'
108- # Only installs the binary to our cached folder.
109- # Assumes OS libraries (libgbm, etc.) are already on the runner.
110175 run : pnpm exec playwright install chromium
176+ # ----------------------
111177
112- - name : Lint Code
113- run : pnpm run lint
178+ - name : Create Runtime Envs
179+ run : |
180+ echo "NEXTAUTH_URL=http://127.0.0.1:3000" > .env.local
181+ echo "NEXTAUTH_SECRET=ci-secret" >> .env.local
114182
115- - name : Verify Build
116- run : pnpm run build
183+ - name : Run Visual Tests
184+ # Using CLI flag --grep to ONLY run tests tagged with @visual
185+ run : pnpm exec playwright test --project=chromium --grep "@visual"
117186
118- - name : Run Tests
119- run : pnpm run test
187+ - name : Upload Report on Failure
188+ if : failure()
189+ uses : actions/upload-artifact@v4
190+ with :
191+ name : playwright-report-visual
192+ path : playwright-report/
193+ retention-days : 5
0 commit comments