From 6b72a872105dbf6c581bffd72df75fc18ea04858 Mon Sep 17 00:00:00 2001 From: Hubert Bugaj Date: Mon, 12 Dec 2022 15:20:18 +0100 Subject: [PATCH] bundle size delta --- .github/workflows/ci.yml | 38 ++++++++++++++++++++++++ .github/workflows/update-bundle-size.yml | 36 ++++++++++++++++++++++ Makefile | 9 ++++-- bundle-size | 1 + scripts/update-bundle-size.sh | 34 +++++++++++++++++++++ 5 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/update-bundle-size.yml create mode 100644 bundle-size create mode 100644 scripts/update-bundle-size.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b03597148..f6b24fa22 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -115,3 +115,41 @@ jobs: uses: actions/checkout@v3 - name: Run shellcheck uses: ludeeus/action-shellcheck@1.1.0 + # Show WASM bundle size summary as a message in the pull request + bundle-size: + if: ${{ github.event_name == 'pull_request' }} + runs-on: ubuntu-latest + steps: + - name: Checking out + uses: actions/checkout@v3 + - name: Install Rust toolchain + uses: ./.github/actions/rust-cargo-run + with: + command: version + github_token: ${{ secrets.GITHUB_TOKEN }} + save_cache: true + - name: Generate bundle delta summary + id: bundle-summary + run: | + echo 'bundle-summary<> $GITHUB_ENV + make bundle-size | tail -n3 >> $GITHUB_ENV + echo 'EOF' >> $GITHUB_ENV + # Find a relevant comment from GH bot to update if there is one + - name: Find Comment + uses: peter-evans/find-comment@v2 + id: fc + with: + issue-number: ${{ github.event.pull_request.number }} + comment-author: 'github-actions[bot]' + body-regex: "^### WASM bundle summary" + - name: Create or update comment + uses: peter-evans/create-or-update-comment@v2 + with: + comment-id: ${{ steps.fc.outputs.comment-id }} + issue-number: ${{ github.event.pull_request.number }} + body: | + ### WASM bundle summary 📦 + ``` + ${{ env.bundle-summary }} + ``` + edit-mode: replace diff --git a/.github/workflows/update-bundle-size.yml b/.github/workflows/update-bundle-size.yml new file mode 100644 index 000000000..a776e7a68 --- /dev/null +++ b/.github/workflows/update-bundle-size.yml @@ -0,0 +1,36 @@ +name: Update WASM bundle size + +on: + push: + branches: + - master + +# Updates the `bundle-size` on the master branch, pushes a commit from the Github +# bot (doesn't trigger the CI thanks to the magic message) +jobs: + bundle-size: + runs-on: ubuntu-latest + steps: + - name: Checking out + uses: actions/checkout@v3 + with: + ref: ${{ github.head_ref }} + fetch-depth: 0 + - name: Install Rust toolchain + uses: ./.github/actions/rust-cargo-run + with: + command: version + github_token: ${{ secrets.GITHUB_TOKEN }} + save_cache: true + - name: Update bundle size + run: | + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + make bundle-size + git add bundle-size + git commit -m "[skip ci] update bundle-size" || true + - name: Push changes + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: ${{ github.head_ref }} diff --git a/Makefile b/Makefile index db5a24dee..39f99049b 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,11 @@ publish: # Create a bundle in a deterministic location bundle: deps-build - cargo run -- -o output/builtin-actors.car + cargo run --locked -- -o output/builtin-actors.car + +# Update the bundle size file, print the summary +bundle-size: bundle + @bash scripts/update-bundle-size.sh $@ output/builtin-actors.car # Create all canonical network bundles all-bundles: bundle-mainnet bundle-caterpillarnet bundle-butterflynet bundle-calibrationnet bundle-devnet bundle-testing bundle-testing @@ -66,7 +70,8 @@ bundle-testing: deps-build BUILD_FIL_NETWORK=testing cargo run -- -o output/builtin-actors-testing.car BUILD_FIL_NETWORK=testing-fake-proofs cargo run -- -o output/builtin-actors-testing-fake-proofs.car -.PHONY: all-bundles bundle-mainnet bundle-caterpillarnet bundle-butterflynet bundle-calibrationnet bundle-devnet bundle-testing + +.PHONY: all-bundles bundle-mainnet bundle-caterpillarnet bundle-butterflynet bundle-calibrationnet bundle-devnet bundle-testing bundle-size # Check if the working tree is clean. check-clean: diff --git a/bundle-size b/bundle-size new file mode 100644 index 000000000..d323ee146 --- /dev/null +++ b/bundle-size @@ -0,0 +1 @@ +6030519 diff --git a/scripts/update-bundle-size.sh b/scripts/update-bundle-size.sh new file mode 100644 index 000000000..d5f087ebb --- /dev/null +++ b/scripts/update-bundle-size.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# Checks and updates bundle size file, printing delta between the previous and current bundle size. + +# Check if the user provided both arguments +if [ $# -ne 2 ]; then + echo "Usage: ./update-bundle-size.sh " + exit 1 +fi + +# Check if paths exist +if [[ ! -f $1 || ! -f $2 ]]; then + echo "Invalid arguments. Please check that the files exist." + exit 1 +fi + +bundle_size_path=$1 +bundle_path=$2 + +# Grab the current bundle size +size_old=$(head -n 1 "$bundle_size_path") + +# Update bundle size +wc -c < "$bundle_path" > "$bundle_size_path" + +# Grab the new bundle size +size_new=$(head -n 1 "$bundle_size_path") + +# Calculate the difference +diff=$((size_new - size_old)) + +# Print stats +echo "Old bundle size: $size_old" +echo "New bundle size: $size_new" +echo "Delta: $diff byte(s)"