|
| 1 | +name: Binary Size Check |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: ["opened", "reopened", "synchronize"] |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + |
| 10 | +env: |
| 11 | + CI: 1 |
| 12 | + CARGO_INCREMENTAL: 0 |
| 13 | + CARGO_TERM_COLOR: "always" |
| 14 | + RUST_LOG: "off" |
| 15 | + SKIP_YARN_COREPACK_CHECK: 1 |
| 16 | + |
| 17 | +concurrency: |
| 18 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 19 | + cancel-in-progress: true |
| 20 | + |
| 21 | +jobs: |
| 22 | + measure-binary-size: |
| 23 | + name: Measure Binary Size |
| 24 | + runs-on: ubuntu-latest |
| 25 | + permissions: |
| 26 | + pull-requests: write |
| 27 | + contents: read |
| 28 | + steps: |
| 29 | + - uses: actions/checkout@v4 |
| 30 | + |
| 31 | + - name: Install Rust |
| 32 | + uses: dtolnay/rust-toolchain@stable |
| 33 | + |
| 34 | + - name: Setup Node.js |
| 35 | + uses: actions/setup-node@v4 |
| 36 | + with: |
| 37 | + node-version: "20" |
| 38 | + cache: "yarn" |
| 39 | + |
| 40 | + - name: Enable corepack |
| 41 | + run: corepack enable |
| 42 | + |
| 43 | + - name: Install wasm-pack |
| 44 | + run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh |
| 45 | + |
| 46 | + - name: Prepare build |
| 47 | + run: | |
| 48 | + rustup target add wasm32-wasip1 |
| 49 | + echo '[patch.crates-io]' >> bindings/Cargo.toml |
| 50 | + ./scripts/cargo/patch-section.sh >> bindings/Cargo.toml |
| 51 | + cd bindings && cargo update -p swc_core -p swc_ts_fast_strip |
| 52 | +
|
| 53 | + - name: Install dependencies |
| 54 | + run: yarn |
| 55 | + |
| 56 | + - name: Build |
| 57 | + run: yarn build |
| 58 | + |
| 59 | + - name: Measure binary sizes |
| 60 | + id: measure |
| 61 | + run: | |
| 62 | + echo "## Binary Sizes" > size_report.md |
| 63 | + echo "" >> size_report.md |
| 64 | + echo "| File | Size |" >> size_report.md |
| 65 | + echo "|------|------|" >> size_report.md |
| 66 | +
|
| 67 | + for file in ./packages/core/swc.*.node; do |
| 68 | + if [ -f "$file" ]; then |
| 69 | + filename=$(basename "$file") |
| 70 | + size=$(ls -lh "$file" | awk '{print $5}') |
| 71 | + size_bytes=$(stat -c%s "$file" 2>/dev/null || stat -f%z "$file") |
| 72 | + echo "| \`$filename\` | $size ($size_bytes bytes) |" >> size_report.md |
| 73 | + fi |
| 74 | + done |
| 75 | +
|
| 76 | + echo "" >> size_report.md |
| 77 | + echo "*Commit: ${{ github.sha }}*" >> size_report.md |
| 78 | +
|
| 79 | + - name: Find existing comment |
| 80 | + if: github.event_name == 'pull_request' |
| 81 | + uses: peter-evans/find-comment@v3 |
| 82 | + id: find-comment |
| 83 | + with: |
| 84 | + issue-number: ${{ github.event.pull_request.number }} |
| 85 | + comment-author: "github-actions[bot]" |
| 86 | + body-includes: "## Binary Sizes" |
| 87 | + |
| 88 | + - name: Create or update PR comment |
| 89 | + if: github.event_name == 'pull_request' |
| 90 | + uses: peter-evans/create-or-update-comment@v4 |
| 91 | + with: |
| 92 | + comment-id: ${{ steps.find-comment.outputs.comment-id }} |
| 93 | + issue-number: ${{ github.event.pull_request.number }} |
| 94 | + body-path: size_report.md |
| 95 | + edit-mode: replace |
| 96 | + |
| 97 | + - name: Find existing commit comment |
| 98 | + if: github.event_name == 'push' |
| 99 | + id: find-commit-comment |
| 100 | + run: | |
| 101 | + COMMENTS=$(gh api repos/${{ github.repository }}/commits/${{ github.sha }}/comments \ |
| 102 | + --jq '.[] | select(.body | contains("## Binary Sizes")) | .id' | head -n 1) |
| 103 | +
|
| 104 | + if [ -n "$COMMENTS" ]; then |
| 105 | + echo "comment_id=$COMMENTS" >> $GITHUB_OUTPUT |
| 106 | + else |
| 107 | + echo "comment_id=" >> $GITHUB_OUTPUT |
| 108 | + fi |
| 109 | + env: |
| 110 | + GH_TOKEN: ${{ github.token }} |
| 111 | + |
| 112 | + - name: Create or update commit comment |
| 113 | + if: github.event_name == 'push' |
| 114 | + run: | |
| 115 | + BODY=$(cat size_report.md) |
| 116 | +
|
| 117 | + if [ -n "${{ steps.find-commit-comment.outputs.comment_id }}" ]; then |
| 118 | + gh api \ |
| 119 | + --method PATCH \ |
| 120 | + -H "Accept: application/vnd.github+json" \ |
| 121 | + repos/${{ github.repository }}/comments/${{ steps.find-commit-comment.outputs.comment_id }} \ |
| 122 | + -f body="$BODY" |
| 123 | + else |
| 124 | + gh api \ |
| 125 | + --method POST \ |
| 126 | + -H "Accept: application/vnd.github+json" \ |
| 127 | + repos/${{ github.repository }}/commits/${{ github.sha }}/comments \ |
| 128 | + -f body="$BODY" |
| 129 | + fi |
| 130 | + env: |
| 131 | + GH_TOKEN: ${{ github.token }} |
0 commit comments