Skip to content

Commit 6b72a87

Browse files
committed
bundle size delta
1 parent 12e5fce commit 6b72a87

File tree

5 files changed

+116
-2
lines changed

5 files changed

+116
-2
lines changed

.github/workflows/ci.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,41 @@ jobs:
115115
uses: actions/checkout@v3
116116
- name: Run shellcheck
117117
uses: ludeeus/[email protected]
118+
# Show WASM bundle size summary as a message in the pull request
119+
bundle-size:
120+
if: ${{ github.event_name == 'pull_request' }}
121+
runs-on: ubuntu-latest
122+
steps:
123+
- name: Checking out
124+
uses: actions/checkout@v3
125+
- name: Install Rust toolchain
126+
uses: ./.github/actions/rust-cargo-run
127+
with:
128+
command: version
129+
github_token: ${{ secrets.GITHUB_TOKEN }}
130+
save_cache: true
131+
- name: Generate bundle delta summary
132+
id: bundle-summary
133+
run: |
134+
echo 'bundle-summary<<EOF' >> $GITHUB_ENV
135+
make bundle-size | tail -n3 >> $GITHUB_ENV
136+
echo 'EOF' >> $GITHUB_ENV
137+
# Find a relevant comment from GH bot to update if there is one
138+
- name: Find Comment
139+
uses: peter-evans/find-comment@v2
140+
id: fc
141+
with:
142+
issue-number: ${{ github.event.pull_request.number }}
143+
comment-author: 'github-actions[bot]'
144+
body-regex: "^### WASM bundle summary"
145+
- name: Create or update comment
146+
uses: peter-evans/create-or-update-comment@v2
147+
with:
148+
comment-id: ${{ steps.fc.outputs.comment-id }}
149+
issue-number: ${{ github.event.pull_request.number }}
150+
body: |
151+
### WASM bundle summary 📦
152+
```
153+
${{ env.bundle-summary }}
154+
```
155+
edit-mode: replace
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Update WASM bundle size
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
# Updates the `bundle-size` on the master branch, pushes a commit from the Github
9+
# bot (doesn't trigger the CI thanks to the magic message)
10+
jobs:
11+
bundle-size:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checking out
15+
uses: actions/checkout@v3
16+
with:
17+
ref: ${{ github.head_ref }}
18+
fetch-depth: 0
19+
- name: Install Rust toolchain
20+
uses: ./.github/actions/rust-cargo-run
21+
with:
22+
command: version
23+
github_token: ${{ secrets.GITHUB_TOKEN }}
24+
save_cache: true
25+
- name: Update bundle size
26+
run: |
27+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
28+
git config --local user.name "github-actions[bot]"
29+
make bundle-size
30+
git add bundle-size
31+
git commit -m "[skip ci] update bundle-size" || true
32+
- name: Push changes
33+
uses: ad-m/github-push-action@master
34+
with:
35+
github_token: ${{ secrets.GITHUB_TOKEN }}
36+
branch: ${{ github.head_ref }}

Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ publish:
4242

4343
# Create a bundle in a deterministic location
4444
bundle: deps-build
45-
cargo run -- -o output/builtin-actors.car
45+
cargo run --locked -- -o output/builtin-actors.car
46+
47+
# Update the bundle size file, print the summary
48+
bundle-size: bundle
49+
@bash scripts/update-bundle-size.sh $@ output/builtin-actors.car
4650

4751
# Create all canonical network bundles
4852
all-bundles: bundle-mainnet bundle-caterpillarnet bundle-butterflynet bundle-calibrationnet bundle-devnet bundle-testing bundle-testing
@@ -66,7 +70,8 @@ bundle-testing: deps-build
6670
BUILD_FIL_NETWORK=testing cargo run -- -o output/builtin-actors-testing.car
6771
BUILD_FIL_NETWORK=testing-fake-proofs cargo run -- -o output/builtin-actors-testing-fake-proofs.car
6872

69-
.PHONY: all-bundles bundle-mainnet bundle-caterpillarnet bundle-butterflynet bundle-calibrationnet bundle-devnet bundle-testing
73+
74+
.PHONY: all-bundles bundle-mainnet bundle-caterpillarnet bundle-butterflynet bundle-calibrationnet bundle-devnet bundle-testing bundle-size
7075

7176
# Check if the working tree is clean.
7277
check-clean:

bundle-size

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6030519

scripts/update-bundle-size.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
# Checks and updates bundle size file, printing delta between the previous and current bundle size.
3+
4+
# Check if the user provided both arguments
5+
if [ $# -ne 2 ]; then
6+
echo "Usage: ./update-bundle-size.sh <bundle-size-path> <bundle-path>"
7+
exit 1
8+
fi
9+
10+
# Check if paths exist
11+
if [[ ! -f $1 || ! -f $2 ]]; then
12+
echo "Invalid arguments. Please check that the files exist."
13+
exit 1
14+
fi
15+
16+
bundle_size_path=$1
17+
bundle_path=$2
18+
19+
# Grab the current bundle size
20+
size_old=$(head -n 1 "$bundle_size_path")
21+
22+
# Update bundle size
23+
wc -c < "$bundle_path" > "$bundle_size_path"
24+
25+
# Grab the new bundle size
26+
size_new=$(head -n 1 "$bundle_size_path")
27+
28+
# Calculate the difference
29+
diff=$((size_new - size_old))
30+
31+
# Print stats
32+
echo "Old bundle size: $size_old"
33+
echo "New bundle size: $size_new"
34+
echo "Delta: $diff byte(s)"

0 commit comments

Comments
 (0)