Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Show diff in bytes instead of percentage #25630

Merged
merged 2 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/read-size.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ jobs:
TREESHAKEN=$(stat --format=%s test/treeshake/index.bundle.min.js)
gzip -k test/treeshake/index.bundle.min.js
TREESHAKEN_GZIP=$(stat --format=%s test/treeshake/index.bundle.min.js.gz)
PR=${{ github.event.pull_request.number }}

# write the output in a json file to upload it as artifact
node -pe "JSON.stringify({ filesize: $FILESIZE, gzip: $FILESIZE_GZIP, treeshaken: $TREESHAKEN, treeshakenGzip: $TREESHAKEN_GZIP, pr: ${{ github.event.pull_request.number }} })" > sizes.json
node -pe "JSON.stringify({ filesize: $FILESIZE, gzip: $FILESIZE_GZIP, treeshaken: $TREESHAKEN, treeshakenGzip: $TREESHAKEN_GZIP, pr: $PR })" > sizes.json
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/report-size.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ jobs:
run: |
FILESIZE_BASE=$(stat --format=%s test/treeshake/three.module.min.js)
TREESHAKEN_BASE=$(stat --format=%s test/treeshake/index.bundle.min.js)

# log to console
echo "FILESIZE_BASE=$FILESIZE_BASE"
echo "TREESHAKEN_BASE=$TREESHAKEN_BASE"

echo "FILESIZE_BASE=$FILESIZE_BASE" >> $GITHUB_OUTPUT
echo "TREESHAKEN_BASE=$TREESHAKEN_BASE" >> $GITHUB_OUTPUT

Expand Down Expand Up @@ -117,9 +122,9 @@ jobs:
edit-mode: replace
body: |
### 📦 Bundle size

_Full ESM build, minified and gzipped._

| Filesize | Gzipped | Diff from `${{ github.ref_name }}` |
|----------|---------|------|
| ${{ steps.format.outputs.FILESIZE }} | ${{ steps.format.outputs.FILESIZE_GZIP }} | ${{ steps.format.outputs.FILESIZE_DIFF }} |
Expand Down
6 changes: 3 additions & 3 deletions test/treeshake/utils/format-diff.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// used in report-size.yml
import { formatBytes } from './formatBytes.js';

const filesize = Number( process.argv[ 2 ] );
const filesizeBase = Number( process.argv[ 3 ] );

const diff = ( filesize - filesizeBase ) * 100 / filesizeBase;
const diffString = diff.toFixed( 2 ).slice( - 1 ) === '0' ? diff.toFixed( 1 ) : diff.toFixed( 2 );
const formatted = `${diff >= 0 ? '+' : ''}${diffString}%`;
const diff = filesize - filesizeBase;
const formatted = `${diff >= 0 ? '+' : '-'}${formatBytes( Math.abs( diff ), 2 )}`;

console.log( formatted );
15 changes: 1 addition & 14 deletions test/treeshake/utils/format-size.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
// used in report-size.yml

export function formatBytes( bytes, decimals = 1 ) {

if ( bytes === 0 ) return '0 B';

const k = 1000;
const dm = decimals < 0 ? 0 : decimals;
const sizes = [ 'B', 'kB', 'MB', 'GB' ];

const i = Math.floor( Math.log( bytes ) / Math.log( k ) );

return parseFloat( ( bytes / Math.pow( k, i ) ).toFixed( dm ) ) + ' ' + sizes[ i ];

}
import { formatBytes } from './formatBytes.js';

const n = Number( process.argv[ 2 ] );
const formatted = formatBytes( n );
Expand Down
13 changes: 13 additions & 0 deletions test/treeshake/utils/formatBytes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export function formatBytes( bytes, decimals = 1 ) {

if ( bytes === 0 ) return '0 B';

const k = 1000;
const dm = decimals < 0 ? 0 : decimals;
const sizes = [ 'B', 'kB', 'MB', 'GB' ];

const i = Math.floor( Math.log( bytes ) / Math.log( k ) );

return parseFloat( ( bytes / Math.pow( k, i ) ).toFixed( dm ) ) + ' ' + sizes[ i ];

}