|
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' |
5 | 12 |
|
6 | 13 | jobs: |
7 | | - pr-quality: |
8 | | - runs-on: ubuntu-latest |
9 | | - |
| 14 | + quality-gate: |
| 15 | + runs-on: self-hosted |
| 16 | + timeout-minutes: 20 |
| 17 | + |
| 18 | + env: |
| 19 | + FORCE_COLOR: 1 |
| 20 | + # Recommended for caching consistency |
| 21 | + PLAYWRIGHT_BROWSERS_PATH: ${{ github.workspace }}/.cache/ms-playwright |
| 22 | + |
10 | 23 | 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" |
| 24 | + - name: Checkout & Prep |
| 25 | + uses: actions/checkout@v4 |
| 26 | + with: |
| 27 | + ref: ${{ inputs.branch || github.ref }} |
| 28 | + fetch-depth: 0 |
| 29 | + clean: true |
| 30 | + |
| 31 | + # 1. Setup pnpm (Package Manager) |
| 32 | + - name: Install pnpm |
| 33 | + uses: pnpm/action-setup@v4 |
| 34 | + with: |
| 35 | + # Version inferred from package.json "packageManager" |
| 36 | + run_install: false |
| 37 | + |
| 38 | + # 2. Setup Node.js with Dependency Caching |
| 39 | + # 'cache: pnpm' automatically caches the pnpm store based on pnpm-lock.yaml |
| 40 | + - name: Setup Node.js |
| 41 | + uses: actions/setup-node@v4 |
| 42 | + with: |
| 43 | + node-version: "20.x" |
| 44 | + cache-dependency-path: pnpm-lock.yaml |
| 45 | + cache: "pnpm" |
| 46 | + |
| 47 | + # 3. Cache Next.js Build |
| 48 | + # Caches the .next/cache folder to speed up 'pnpm run build' |
| 49 | + - name: Cache Next.js |
| 50 | + uses: actions/cache@v4 |
| 51 | + with: |
| 52 | + path: | |
| 53 | + ${{ github.workspace }}/.next/cache |
| 54 | + key: ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }} |
| 55 | + restore-keys: | |
| 56 | + ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}- |
| 57 | +
|
| 58 | + # 4. Cache Playwright Browsers |
| 59 | + # Caches the large browser binaries to avoid downloading them every run |
| 60 | + - name: Cache Playwright Browsers |
| 61 | + uses: actions/cache@v4 |
| 62 | + id: playwright-cache |
| 63 | + with: |
| 64 | + path: ${{ env.PLAYWRIGHT_BROWSERS_PATH }} |
| 65 | + key: ${{ runner.os }}-playwright-${{ hashFiles('**/pnpm-lock.yaml') }} |
| 66 | + restore-keys: | |
| 67 | + ${{ runner.os }}-playwright- |
| 68 | +
|
| 69 | + - name: Create Runtime Directories |
| 70 | + run: | |
| 71 | + mkdir -p logs |
| 72 | + echo "✅ Created 'logs' directory" |
| 73 | +
|
| 74 | + - name: Configure .env.local |
| 75 | + run: | |
| 76 | + echo "📝 Creating .env.local with development defaults..." |
| 77 | + cat > .env.local <<EOL |
| 78 | + NEXTAUTH_URL=http://127.0.0.1:3000 |
| 79 | + NEXTAUTH_SECRET=jules-dev-environment-secret-123 |
| 80 | + SPOTIFY_CLIENT_ID=placeholder_id |
| 81 | + SPOTIFY_CLIENT_SECRET=placeholder_secret |
| 82 | + EOL |
| 83 | +
|
| 84 | + - name: Install Dependencies |
| 85 | + run: pnpm install --frozen-lockfile |
| 86 | + |
| 87 | + # 5. Install Playwright (Conditional) |
| 88 | + # Only runs if cache missed. '--with-deps' ensures OS-level libs are present. |
| 89 | + - name: Install Playwright Browsers |
| 90 | + if: steps.playwright-cache.outputs.cache-hit != 'true' |
| 91 | + run: pnpm exec playwright install chromium --with-deps |
| 92 | + |
| 93 | + # 6. Install OS Dependencies (Always Needed) |
| 94 | + # Even if binaries are cached, system libs might be missing on clean runners. |
| 95 | + - name: Install Playwright OS Deps |
| 96 | + if: steps.playwright-cache.outputs.cache-hit == 'true' |
| 97 | + run: pnpm exec playwright install-deps chromium |
| 98 | + |
| 99 | + - name: Lint Code |
| 100 | + run: pnpm run lint |
| 101 | + |
| 102 | + - name: Verify Build |
| 103 | + run: pnpm run build |
| 104 | + |
| 105 | + - name: Lint commit messages |
| 106 | + run: | |
| 107 | + echo "🔍 Verifying Conventional Commits..." |
| 108 | + RANGE="origin/leader..HEAD" |
| 109 | + if ! git rev-parse --verify origin/leader >/dev/null 2>&1; then RANGE="HEAD"; fi |
| 110 | + |
| 111 | + git log --format=%s $RANGE | while read line; do |
| 112 | + if [[ ! "$line" =~ ^(feat|fix|docs|style|refactor|test|chore|perf|ci)(\(.+\))?: ]]; then |
| 113 | + echo "::error::Invalid Commit Message: $line" |
| 114 | + exit 1 |
44 | 115 | fi |
45 | 116 | done |
46 | | - fi |
47 | | -
|
|
0 commit comments