Skip to content

Commit 512bf5c

Browse files
committed
.
1 parent 4274e69 commit 512bf5c

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

.github/generate-dist-files-size-diff.mjs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ if (!process.env.BASE_DIST_FILES) {
1818
if (!process.env.PR_DIST_FILES) {
1919
throw new Error('Missing or invalid "PR_DIST_FILES" env variable.');
2020
}
21+
if (!process.env.GITHUB_HEAD_REF) {
22+
throw new Error('Missing or invalid "GITHUB_HEAD_REF" env variable.');
23+
}
2124

2225
/**
2326
* Adapted from https://gist.github.com/zentala/1e6f72438796d74531803cc3833c039c?permalink_comment_id=4455218#gistcomment-4455218
@@ -85,14 +88,25 @@ export function main() {
8588
return output;
8689
}
8790

91+
const displayedPackageRow = new Set();
8892
output += 'Thanks for the PR! Here is the difference in size of the dist files between the base and the PR.\n';
8993
output += 'Please review the changes and make sure they are expected.\n\n';
9094
output += `<table>
9195
<thead><tr><th>File</th><th>Diff (B)</th><th>Diff (%)</th></tr></thead>
9296
<tbody>`;
9397
for (const [file, details] of files.entries()) {
98+
const isBridge = file.includes('src/Bridge');
99+
const packageName = file.split('/')[1];
100+
const bridgeName = isBridge ? file.split('/')[4] : '';
101+
const fileShort = file.replace(isBridge ? `src/${packageName}/src/Bridge/${bridgeName}/assets/dist/` : `src/${packageName}/assets/dist/`, '');
102+
const row = isBridge ? `${packageName} (Bridge ${bridgeName})` : packageName;
103+
if (!displayedPackageRow.has(row)) {
104+
displayedPackageRow.add(row);
105+
output += `<tr><td colspan="3"><b>${row}</b></td></tr>`;
106+
}
107+
94108
output += `<tr>
95-
<td><code>${file}</code> ${details.state === 'added' ? '(new)' : (details.state === 'removed' ? '(deleted)' : '')}</td>
109+
<td><code>${fileShort}</code> ${details.state === 'added' ? '(new)' : (details.state === 'removed' ? '(deleted)' : '')}</td>
96110
<td>
97111
Size: <code>${formatBytes(base[file]?.size || 0)}</code> → <code>${formatBytes(pr[file]?.size || 0)}</code><br>
98112
Gzip: <code>${formatBytes(base[file]?.size_gz || 0)}</code> → <code>${formatBytes(pr[file]?.size_gz || 0)}</code><br>

.github/workflows/dist-files-size-diff.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ name: Dist Files Size Diff
33
on:
44
pull_request:
55
paths:
6-
- 'src/*/**'
7-
- '!src/*/doc/**'
8-
- '.github/**'
6+
- 'src/*/assets/dist/**'
7+
- 'src/*/src/Bridge/*/assets/dist/**'
98

109
jobs:
1110
dist-files-size-diff:
@@ -60,6 +59,8 @@ jobs:
6059
with:
6160
result-encoding: string
6261
script: |
62+
console.log(process.env);
63+
console.log(context);
6364
const { main } = await import('${{ github.workspace }}/.github/generate-dist-files-size-diff.mjs')
6465
6566
return await main()

0 commit comments

Comments
 (0)