|
| 1 | +name: Console Performance Budget |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, develop] |
| 6 | + paths: |
| 7 | + - 'packages/**' |
| 8 | + - 'apps/console/**' |
| 9 | + - 'pnpm-lock.yaml' |
| 10 | + pull_request: |
| 11 | + branches: [main, develop] |
| 12 | + paths: |
| 13 | + - 'packages/**' |
| 14 | + - 'apps/console/**' |
| 15 | + - 'pnpm-lock.yaml' |
| 16 | + |
| 17 | +permissions: |
| 18 | + contents: read |
| 19 | + pull-requests: write |
| 20 | + |
| 21 | +jobs: |
| 22 | + performance-budget: |
| 23 | + name: Performance Budget Check |
| 24 | + runs-on: ubuntu-latest |
| 25 | + steps: |
| 26 | + - name: Checkout code |
| 27 | + uses: actions/checkout@v6 |
| 28 | + |
| 29 | + - name: Setup pnpm |
| 30 | + uses: pnpm/action-setup@v4 |
| 31 | + |
| 32 | + - name: Setup Node.js |
| 33 | + uses: actions/setup-node@v6 |
| 34 | + with: |
| 35 | + node-version: '20.x' |
| 36 | + cache: 'pnpm' |
| 37 | + |
| 38 | + - name: Turbo Cache |
| 39 | + uses: actions/cache@v5 |
| 40 | + with: |
| 41 | + path: node_modules/.cache/turbo |
| 42 | + key: turbo-${{ runner.os }}-${{ github.sha }} |
| 43 | + restore-keys: | |
| 44 | + turbo-${{ runner.os }}- |
| 45 | +
|
| 46 | + - name: Install dependencies |
| 47 | + run: pnpm install --frozen-lockfile |
| 48 | + |
| 49 | + - name: Build Console (server mode) |
| 50 | + run: pnpm --filter @object-ui/console build:server |
| 51 | + |
| 52 | + - name: Check performance budget |
| 53 | + id: budget |
| 54 | + run: | |
| 55 | + # Performance budget: main entry must be < 60 KB gzip |
| 56 | + MAX_ENTRY_GZIP_KB=60 |
| 57 | +
|
| 58 | + DIST_DIR="apps/console/dist/assets" |
| 59 | + if [ ! -d "$DIST_DIR" ]; then |
| 60 | + echo "❌ Build output not found at $DIST_DIR" |
| 61 | + exit 1 |
| 62 | + fi |
| 63 | +
|
| 64 | + # Find the main entry chunk (index-*.js) |
| 65 | + ENTRY_FILE=$(find "$DIST_DIR" -name 'index-*.js' -not -name '*.gz' -not -name '*.br' | head -1) |
| 66 | + if [ -z "$ENTRY_FILE" ]; then |
| 67 | + echo "⚠️ Could not find main entry chunk, checking all JS files..." |
| 68 | + ENTRY_FILE=$(find "$DIST_DIR" -name '*.js' -not -name '*.gz' -not -name '*.br' | sort | head -1) |
| 69 | + fi |
| 70 | +
|
| 71 | + if [ -z "$ENTRY_FILE" ]; then |
| 72 | + echo "❌ No JS files found in $DIST_DIR" |
| 73 | + exit 1 |
| 74 | + fi |
| 75 | +
|
| 76 | + echo "📦 Main entry file: $(basename $ENTRY_FILE)" |
| 77 | +
|
| 78 | + # Calculate gzip size |
| 79 | + GZIP_BYTES=$(gzip -c "$ENTRY_FILE" | wc -c) |
| 80 | + GZIP_KB=$(awk "BEGIN {printf \"%.1f\", $GZIP_BYTES / 1024}") |
| 81 | +
|
| 82 | + echo " Raw size: $(awk "BEGIN {printf \"%.1f\", $(wc -c < "$ENTRY_FILE") / 1024}") KB" |
| 83 | + echo " Gzip size: ${GZIP_KB} KB" |
| 84 | + echo " Budget: ${MAX_ENTRY_GZIP_KB} KB" |
| 85 | +
|
| 86 | + echo "gzip_kb=$GZIP_KB" >> "$GITHUB_OUTPUT" |
| 87 | + echo "budget_kb=$MAX_ENTRY_GZIP_KB" >> "$GITHUB_OUTPUT" |
| 88 | + echo "entry_file=$(basename $ENTRY_FILE)" >> "$GITHUB_OUTPUT" |
| 89 | +
|
| 90 | + # Check budget |
| 91 | + OVER=$(awk "BEGIN {print ($GZIP_KB > $MAX_ENTRY_GZIP_KB) ? 1 : 0}") |
| 92 | + if [ "$OVER" -eq 1 ]; then |
| 93 | + echo "" |
| 94 | + echo "❌ BUDGET EXCEEDED: Main entry is ${GZIP_KB} KB gzip (limit: ${MAX_ENTRY_GZIP_KB} KB)" |
| 95 | + echo "budget_status=fail" >> "$GITHUB_OUTPUT" |
| 96 | + exit 1 |
| 97 | + else |
| 98 | + echo "" |
| 99 | + echo "✅ Budget OK: Main entry is ${GZIP_KB} KB gzip (limit: ${MAX_ENTRY_GZIP_KB} KB)" |
| 100 | + echo "budget_status=pass" >> "$GITHUB_OUTPUT" |
| 101 | + fi |
| 102 | +
|
| 103 | + - name: Comment PR with budget result |
| 104 | + if: github.event_name == 'pull_request' && always() |
| 105 | + uses: actions/github-script@v8 |
| 106 | + with: |
| 107 | + script: | |
| 108 | + const status = '${{ steps.budget.outputs.budget_status }}'; |
| 109 | + const gzipKb = '${{ steps.budget.outputs.gzip_kb }}'; |
| 110 | + const budgetKb = '${{ steps.budget.outputs.budget_kb }}'; |
| 111 | + const entryFile = '${{ steps.budget.outputs.entry_file }}'; |
| 112 | + const icon = status === 'pass' ? '✅' : '❌'; |
| 113 | +
|
| 114 | + const body = `## ${icon} Console Performance Budget |
| 115 | +
|
| 116 | + | Metric | Value | Budget | |
| 117 | + |--------|-------|--------| |
| 118 | + | Main entry (gzip) | **${gzipKb} KB** | ${budgetKb} KB | |
| 119 | + | Entry file | \`${entryFile}\` | — | |
| 120 | + | Status | **${status === 'pass' ? 'PASS' : 'FAIL'}** | — | |
| 121 | + `; |
| 122 | +
|
| 123 | + github.rest.issues.createComment({ |
| 124 | + issue_number: context.issue.number, |
| 125 | + owner: context.repo.owner, |
| 126 | + repo: context.repo.repo, |
| 127 | + body |
| 128 | + }); |
0 commit comments