Skip to content

Commit d0753a9

Browse files
Merge branch 'main' into rslib/webpack-bundler-runtime
2 parents 7dcea95 + b1dac16 commit d0753a9

File tree

3 files changed

+445
-0
lines changed

3 files changed

+445
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Bundle Size Comment
2+
3+
on:
4+
workflow_run:
5+
workflows: ['Bundle Size']
6+
types: [completed]
7+
8+
permissions:
9+
pull-requests: write
10+
actions: read
11+
12+
jobs:
13+
comment:
14+
if: github.event.workflow_run.conclusion == 'success'
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Download bundle size stats
18+
uses: actions/download-artifact@v4
19+
with:
20+
name: bundle-size-stats
21+
run-id: ${{ github.event.workflow_run.id }}
22+
github-token: ${{ secrets.GITHUB_TOKEN }}
23+
24+
- name: Get PR number
25+
id: pr
26+
run: |
27+
PR_NUMBER=$(gh pr list --repo "$GITHUB_REPOSITORY" --search "${{ github.event.workflow_run.head_sha }}" --state open --json number --jq '.[0].number')
28+
if [ -z "$PR_NUMBER" ]; then
29+
echo "Could not find PR for SHA ${{ github.event.workflow_run.head_sha }}"
30+
exit 1
31+
fi
32+
echo "number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
33+
env:
34+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35+
36+
- name: Read stats
37+
id: stats
38+
run: |
39+
{
40+
echo 'body<<STATS_EOF'
41+
echo '<!-- bundle-size-comment -->'
42+
cat stats.txt
43+
echo ''
44+
echo 'STATS_EOF'
45+
} >> "$GITHUB_OUTPUT"
46+
47+
- name: Find existing comment
48+
uses: peter-evans/find-comment@v3
49+
id: find
50+
with:
51+
issue-number: ${{ steps.pr.outputs.number }}
52+
body-includes: '<!-- bundle-size-comment -->'
53+
54+
- name: Create or update comment
55+
uses: peter-evans/create-or-update-comment@v4
56+
with:
57+
issue-number: ${{ steps.pr.outputs.number }}
58+
comment-id: ${{ steps.find.outputs.comment-id }}
59+
edit-mode: replace
60+
body: ${{ steps.stats.outputs.body }}

.github/workflows/bundle-size.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Bundle Size
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
7+
permissions:
8+
contents: read
9+
10+
concurrency:
11+
group: bundle-size-${{ github.event.pull_request.number }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
measure:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout PR
19+
uses: actions/checkout@v4
20+
21+
- name: Setup pnpm
22+
uses: pnpm/action-setup@v4
23+
24+
- name: Setup Node.js
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: 20
28+
cache: pnpm
29+
30+
- name: Install dependencies (PR)
31+
run: pnpm install --frozen-lockfile
32+
33+
- name: Build packages (PR)
34+
run: npx nx run-many --targets=build --projects=tag:type:pkg --parallel=4 --skip-nx-cache
35+
36+
- name: Measure bundle sizes (PR)
37+
run: node scripts/bundle-size-report.mjs --output current.json
38+
39+
- name: Checkout base branch
40+
uses: actions/checkout@v4
41+
with:
42+
ref: ${{ github.event.pull_request.base.sha }}
43+
path: base
44+
45+
- name: Install dependencies (base)
46+
run: cd base && pnpm install --frozen-lockfile
47+
48+
- name: Build packages (base)
49+
run: cd base && npx nx run-many --targets=build --projects=tag:type:pkg --parallel=4 --skip-nx-cache
50+
51+
- name: Measure bundle sizes (base)
52+
run: node scripts/bundle-size-report.mjs --output base.json --packages-dir base/packages
53+
54+
- name: Compare bundle sizes
55+
run: node scripts/bundle-size-report.mjs --compare base.json --current current.json --output stats.txt
56+
57+
- name: Upload bundle size stats
58+
uses: actions/upload-artifact@v4
59+
with:
60+
name: bundle-size-stats
61+
path: stats.txt
62+
retention-days: 5

0 commit comments

Comments
 (0)