Skip to content

Commit

Permalink
Report normal bundle size as well
Browse files Browse the repository at this point in the history
  • Loading branch information
marcofugaro committed Mar 3, 2023
1 parent 60e51c6 commit 5a8bf6c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/read-size.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ permissions:
contents: read

jobs:
treeshaking:
read-size:
name: Tree-shaking
runs-on: ubuntu-latest
steps:
Expand All @@ -34,12 +34,15 @@ jobs:
- name: Read tree-shaken size
id: read-size
run: |
FILESIZE=$(stat --format=%s test/treeshake/index.bundle.min.js)
FILESIZE=$(stat --format=%s test/treeshake/three.module.min.js)
gzip -k test/treeshake/three.module.min.js
FILESIZE_GZIP=$(stat --format=%s test/treeshake/three.module.min.js.gz)
TREESHAKEN=$(stat --format=%s test/treeshake/index.bundle.min.js)
gzip -k test/treeshake/index.bundle.min.js
FILESIZE_GZIP=$(stat --format=%s test/treeshake/index.bundle.min.js.gz)
TREESHAKEN_GZIP=$(stat --format=%s test/treeshake/index.bundle.min.js.gz)
# write the output in a json file to upload it as artifact
node -pe "JSON.stringify({ filesize: $FILESIZE, gzip: $FILESIZE_GZIP })" > sizes.json
node -pe "JSON.stringify({ filesize: $FILESIZE, gzip: $FILESIZE_GZIP, treeshaken: $TREESHAKEN, treeshakenGzip: $TREESHAKEN_GZIP })" > sizes.json
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
Expand Down
27 changes: 23 additions & 4 deletions .github/workflows/report-size.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ permissions:
pull-requests: write

jobs:
treeshaking:
name: Tree-shaking
report-size:
name: Comment on PR
runs-on: ubuntu-latest
if: github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
Expand Down Expand Up @@ -66,22 +66,36 @@ jobs:
- name: Read tree-shaken size
id: read-size
run: |
FILESIZE_BASE=$(stat --format=%s test/treeshake/index.bundle.min.js)
FILESIZE_BASE=$(stat --format=%s test/treeshake/three.module.min.js)
TREESHAKEN_BASE=$(stat --format=%s test/treeshake/index.bundle.min.js)
echo "FILESIZE_BASE=$FILESIZE_BASE" >> $GITHUB_OUTPUT
echo "TREESHAKEN_BASE=$TREESHAKEN_BASE" >> $GITHUB_OUTPUT
- name: Format sizes
id: format
# It's important these are passed as env variables.
# https://securitylab.github.com/research/github-actions-untrusted-input/
env:
FILESIZE: ${{ fromJSON(steps.download-artifact.outputs.result).filesize }}
FILESIZE_GZIP: ${{ fromJSON(steps.download-artifact.outputs.result).gzip }}
FILESIZE_BASE: ${{ steps.read-size.outputs.FILESIZE_BASE }}
TREESHAKEN: ${{ fromJSON(steps.download-artifact.outputs.result).treeshaken }}
TREESHAKEN_GZIP: ${{ fromJSON(steps.download-artifact.outputs.result).treeshakenGzip }}
TREESHAKEN_BASE: ${{ steps.read-size.outputs.TREESHAKEN_BASE }}
run: |
FILESIZE_FORM=$(node ./test/treeshake/utils/format-size.js "$FILESIZE")
FILESIZE_GZIP_FORM=$(node ./test/treeshake/utils/format-size.js "$FILESIZE_GZIP")
FILESIZE_DIFF=$(node ./test/treeshake/utils/format-diff.js "$FILESIZE" "$FILESIZE_BASE")
TREESHAKEN_FORM=$(node ./test/treeshake/utils/format-size.js "$TREESHAKEN")
TREESHAKEN_GZIP_FORM=$(node ./test/treeshake/utils/format-size.js "$TREESHAKEN_GZIP")
TREESHAKEN_DIFF=$(node ./test/treeshake/utils/format-diff.js "$TREESHAKEN" "$TREESHAKEN_BASE")
echo "FILESIZE=$FILESIZE_FORM" >> $GITHUB_OUTPUT
echo "FILESIZE_GZIP=$FILESIZE_GZIP_FORM" >> $GITHUB_OUTPUT
echo "FILESIZE_DIFF=$FILESIZE_DIFF" >> $GITHUB_OUTPUT
echo "TREESHAKEN=$TREESHAKEN_FORM" >> $GITHUB_OUTPUT
echo "TREESHAKEN_GZIP=$TREESHAKEN_GZIP_FORM" >> $GITHUB_OUTPUT
echo "TREESHAKEN_DIFF=$TREESHAKEN_DIFF" >> $GITHUB_OUTPUT
- name: Find existing comment
uses: peter-evans/find-comment@v2
Expand All @@ -97,7 +111,12 @@ jobs:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
edit-mode: replace
body: |
### 📦 Bundle size after tree-shaking
### 📦 Bundle size
| Filesize | Gzipped | Diff from `${{ github.ref_name }}` |
|----------|---------|------|
| ${{ steps.format.outputs.FILESIZE }} | ${{ steps.format.outputs.FILESIZE_GZIP }} | ${{ steps.format.outputs.FILESIZE_DIFF }} |
### 🌳 Bundle size after tree-shaking
| Filesize | Gzipped | Diff from `${{ github.ref_name }}` |
|----------|---------|------|
| ${{ steps.format.outputs.TREESHAKEN }} | ${{ steps.format.outputs.TREESHAKEN_GZIP }} | ${{ steps.format.outputs.TREESHAKEN_DIFF }} |
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ test/unit/build
test/treeshake/index.bundle.js
test/treeshake/index.bundle.min.js
test/treeshake/index-src.bundle.min.js
test/treeshake/three.module.min.js
test/treeshake/stats.html
test/e2e/chromium
test/e2e/output-screenshots
Expand Down
13 changes: 13 additions & 0 deletions test/rollup.treeshake.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,17 @@ export default [
}
]
},
// esm bundle size minified, used in read-size.yml
{
input: 'build/three.module.js',
plugins: [
terser(),
],
output: [
{
format: 'esm',
file: 'test/treeshake/three.module.min.js'
}
]
},
];

0 comments on commit 5a8bf6c

Please sign in to comment.