Merge pull request #9 from crup/next #41
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: Size | |
| on: | |
| pull_request: | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| env: | |
| FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true | |
| jobs: | |
| compare: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: 1. Checkout head | |
| uses: actions/checkout@v4 | |
| with: | |
| path: head | |
| - name: 2. Checkout main baseline | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: main | |
| path: base | |
| - name: 3. Setup pnpm | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| version: 10.30.2 | |
| - name: 4. Setup Node 24 | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 24 | |
| - name: 5. Build head package | |
| working-directory: head | |
| run: | | |
| pnpm install --frozen-lockfile | |
| pnpm build | |
| node scripts/size-report.mjs --json > ../head-size.json | |
| - name: 6. Build main baseline | |
| working-directory: base | |
| continue-on-error: true | |
| run: | | |
| pnpm install --frozen-lockfile | |
| pnpm build | |
| node scripts/size-report.mjs --json > ../base-size.json | |
| - name: 7. Compare bundle size | |
| id: compare | |
| run: | | |
| if [ -f base-size.json ]; then | |
| node head/scripts/size-compare.mjs base-size.json head-size.json | tee size-summary.md >> "$GITHUB_STEP_SUMMARY" | |
| else | |
| echo "Base branch does not have size tooling yet. Head size:" >> "$GITHUB_STEP_SUMMARY" | |
| cat head-size.json >> "$GITHUB_STEP_SUMMARY" | |
| { | |
| echo "Base branch does not have size tooling yet. Head size:" | |
| cat head-size.json | |
| } > size-summary.md | |
| fi | |
| - name: 8. Comment size report | |
| if: github.event_name == 'pull_request' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('node:fs'); | |
| const marker = '<!-- react-timer-hook-size-report -->'; | |
| const body = `${marker} | |
| ## Bundle size report | |
| ${fs.readFileSync('size-summary.md', 'utf8')}`; | |
| const { owner, repo } = context.repo; | |
| const issue_number = context.issue.number; | |
| const comments = await github.rest.issues.listComments({ owner, repo, issue_number, per_page: 100 }); | |
| const existing = comments.data.find(comment => comment.body?.includes(marker)); | |
| if (existing) { | |
| await github.rest.issues.updateComment({ owner, repo, comment_id: existing.id, body }); | |
| } else { | |
| await github.rest.issues.createComment({ owner, repo, issue_number, body }); | |
| } |