chore: optimizations #18
Workflow file for this run
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 Analysis | |
| on: | |
| pull_request: | |
| paths: | |
| - packages/bits-ui/** | |
| - bundle-analyzer/** | |
| types: [opened, synchronize, reopened] | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.event.number }} | |
| cancel-in-progress: true | |
| jobs: | |
| bundle-analysis: | |
| name: Bundle Size Analysis | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - uses: pnpm/action-setup@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: pnpm | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Build packages | |
| run: pnpm build:packages | |
| - name: Run bundle analysis on PR | |
| run: pnpm bundle:analyze | |
| - name: Create temp directory and save PR bundle report | |
| run: | | |
| mkdir -p /tmp/bundle-analysis | |
| cp ./bundle-analyzer/bundle-reports/latest.json /tmp/bundle-analysis/pr-current.json | |
| - name: Checkout target branch | |
| run: | | |
| git fetch origin ${{ github.base_ref }} | |
| git checkout origin/${{ github.base_ref }} | |
| - name: Get target branch bundle report | |
| id: check-target-bundle | |
| run: | | |
| if git cat-file -e HEAD:bundle-analyzer/bundle-reports/latest.json 2>/dev/null; then | |
| echo "exists=true" >> $GITHUB_OUTPUT | |
| git show HEAD:bundle-analyzer/bundle-reports/latest.json > /tmp/bundle-analysis/target-baseline.json | |
| else | |
| echo "exists=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Checkout PR branch | |
| run: git checkout ${{ github.head_ref }} | |
| - name: Generate target baseline if missing | |
| if: steps.check-target-bundle.outputs.exists == 'false' | |
| run: | | |
| git checkout origin/${{ github.base_ref }} | |
| pnpm install --frozen-lockfile | |
| pnpm build:packages | |
| pnpm bundle:analyze || echo "Bundle analysis failed" | |
| if [ -f "./bundle-analyzer/bundle-reports/latest.json" ]; then | |
| cp ./bundle-analyzer/bundle-reports/latest.json /tmp/bundle-analysis/target-baseline.json | |
| else | |
| echo '{"timestamp":"","results":[]}' > /tmp/bundle-analysis/target-baseline.json | |
| fi | |
| git checkout ${{ github.head_ref }} | |
| - name: Generate bundle comparison comment | |
| id: bundle-comment | |
| run: | | |
| node ./bundle-analyzer/generate-pr-comment.js \ | |
| /tmp/bundle-analysis/pr-current.json \ | |
| /tmp/bundle-analysis/target-baseline.json | |
| - name: Find existing comment | |
| uses: peter-evans/find-comment@a723a15ad60cf9419c01a6b8c9548ddd15e79531 | |
| id: existing-comment | |
| with: | |
| issue-number: ${{ github.event.pull_request.number }} | |
| comment-author: "github-actions[bot]" | |
| body-includes: "## 📦 Bundle Size Analysis" | |
| - name: Update or create comment | |
| uses: peter-evans/create-or-update-comment@be17e0c03de886b7aff3fb3224d28bfb6fc5d114 | |
| with: | |
| comment-id: ${{ steps.existing-comment.outputs.comment-id }} | |
| issue-number: ${{ github.event.pull_request.number }} | |
| body-path: /tmp/bundle-analysis/comment.md | |
| edit-mode: replace |