ci: add 6 new workflows, Blacksmith runners, and CI speed optimizations #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Bundle Size Analysis | |
| on: | |
| pull_request: | |
| branches: [main] | |
| push: | |
| branches: [main] | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| jobs: | |
| analyze: | |
| name: Analyze Bundle Size | |
| runs-on: blacksmith-4vcpu-ubuntu-2404 | |
| timeout-minutes: 15 | |
| env: | |
| EXPO_PUBLIC_CAL_API_KEY: ${{ secrets.CI_EXPO_PUBLIC_CAL_API_KEY || vars.CI_EXPO_PUBLIC_CAL_API_KEY || vars.EXPO_PUBLIC_CAL_API_KEY }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v1 | |
| with: | |
| bun-version: 1.3.0 | |
| cache: true | |
| cache-dependency-path: bun.lock | |
| - name: Install dependencies | |
| run: bun install --frozen-lockfile | |
| - name: Build browser extension | |
| run: bun run ext:build | |
| - name: Calculate extension bundle size | |
| id: ext_size | |
| run: | | |
| if [ -d ".output" ]; then | |
| EXT_SIZE=$(du -sb .output | cut -f1) | |
| EXT_SIZE_KB=$((EXT_SIZE / 1024)) | |
| echo "size_bytes=$EXT_SIZE" >> "$GITHUB_OUTPUT" | |
| echo "size_kb=$EXT_SIZE_KB" >> "$GITHUB_OUTPUT" | |
| echo "Extension bundle size: ${EXT_SIZE_KB}KB" | |
| else | |
| echo "size_bytes=0" >> "$GITHUB_OUTPUT" | |
| echo "size_kb=0" >> "$GITHUB_OUTPUT" | |
| echo "No extension output directory found" | |
| fi | |
| - name: Upload bundle stats | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: bundle-stats | |
| path: .output/ | |
| retention-days: 90 | |
| - name: Download base branch stats | |
| if: github.event_name == 'pull_request' | |
| uses: dawidd6/action-download-artifact@v6 | |
| continue-on-error: true | |
| with: | |
| workflow: bundle-analysis.yml | |
| branch: main | |
| name: bundle-stats | |
| path: .base-output/ | |
| id: download_base | |
| - name: Compare bundle sizes | |
| if: github.event_name == 'pull_request' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const { execSync } = require('child_process'); | |
| let currentSize = parseInt('${{ steps.ext_size.outputs.size_bytes }}') || 0; | |
| let baseSize = 0; | |
| if ('${{ steps.download_base.outcome }}' === 'success' && fs.existsSync('.base-output')) { | |
| try { | |
| baseSize = parseInt(execSync('du -sb .base-output').toString().split('\t')[0]) || 0; | |
| } catch (e) { | |
| console.log('Could not calculate base size:', e.message); | |
| } | |
| } | |
| const diff = currentSize - baseSize; | |
| const diffKB = (diff / 1024).toFixed(2); | |
| const currentKB = (currentSize / 1024).toFixed(2); | |
| const baseKB = (baseSize / 1024).toFixed(2); | |
| const emoji = diff > 0 ? (diff > 51200 ? '🔴' : '🟡') : '🟢'; | |
| let body = `## ${emoji} Bundle Size Analysis\n\n`; | |
| body += `| | Size |\n|---|---|\n`; | |
| body += `| **Extension (current)** | ${currentKB} KB |\n`; | |
| if (baseSize > 0) { | |
| const pctChange = ((diff / baseSize) * 100).toFixed(2); | |
| body += `| **Extension (main)** | ${baseKB} KB |\n`; | |
| body += `| **Diff** | ${diff >= 0 ? '+' : ''}${diffKB} KB (${diff >= 0 ? '+' : ''}${pctChange}%) |\n`; | |
| } else { | |
| body += `| **Extension (main)** | N/A (no baseline yet) |\n`; | |
| } | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| body, | |
| }); |