Skip to content

Commit 26a6fc2

Browse files
committed
.
1 parent 4274e69 commit 26a6fc2

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

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

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
Usage:
77
```shell
88
BASE_DIST_FILES='{"src/Autocomplete/assets/dist/controller.js":{"size":15382,"size_gz":3716,"size_brotli":3125},"src/Chartjs/assets/dist/controller.js":{"size":2281,"size_gz":771,"size_brotli":642},"src/Cropperjs/assets/dist/controller.js":{"size":1044,"size_gz":475,"size_brotli":371}}' \
9-
PR_DIST_FILES='{"src/Chartjs/assets/dist/controller.js":{"size":2281,"size_gz":771,"size_brotli":642},"src/Cropperjs/assets/dist/controller.js":{"size":1044,"size_gz":475,"size_brotli":371},"src/Cropperjs/assets/dist/style.min.css":{"size":32,"size_gz":66,"size_brotli":34},"src/Dropzone/assets/dist/controller.js":{"size":3199,"size_gz":816,"size_brotli":634}}' \
9+
PR_DIST_FILES='{"src/Chartjs/assets/dist/controller.js":{"size":1281,"size_gz":171,"size_brotli":641},"src/Cropperjs/assets/dist/controller.js":{"size":1044,"size_gz":475,"size_brotli":371},"src/Cropperjs/assets/dist/style.min.css":{"size":32,"size_gz":66,"size_brotli":34},"src/Dropzone/assets/dist/controller.js":{"size":3199,"size_gz":816,"size_brotli":634},"src/Map/src/Bridge/Google/assets/dist/foo.js":{"size":3199,"size_gz":816,"size_brotli":634}}' \
10+
GITHUB_REPOSITORY='symfony/ux' \
11+
GITHUB_HEAD_REF='my-branch-name' \
1012
node .github/generate-dist-files-size-diff.mjs
1113
```
1214
*/
@@ -19,6 +21,14 @@ if (!process.env.PR_DIST_FILES) {
1921
throw new Error('Missing or invalid "PR_DIST_FILES" env variable.');
2022
}
2123

24+
if (!process.env.GITHUB_REPOSITORY) {
25+
throw new Error('Missing or invalid "GITHUB_REPOSITORY" env variable.');
26+
}
27+
28+
if (!process.env.GITHUB_HEAD_REF) {
29+
throw new Error('Missing or invalid "GITHUB_HEAD_REF" env variable.');
30+
}
31+
2232
/**
2333
* Adapted from https://gist.github.com/zentala/1e6f72438796d74531803cc3833c039c?permalink_comment_id=4455218#gistcomment-4455218
2434
* @param {number} bytes
@@ -57,6 +67,8 @@ function formatDiffPercent(percent) {
5767
}
5868

5969
export function main() {
70+
const repoUrl = `https://github.com/${process.env.GITHUB_REPOSITORY}`;
71+
6072
let base = JSON.parse(process.env.BASE_DIST_FILES);
6173
let pr = JSON.parse(process.env.PR_DIST_FILES);
6274
let output = '<h1>📊 Dist files size difference</h1>\n\n';
@@ -85,14 +97,30 @@ export function main() {
8597
return output;
8698
}
8799

100+
const displayedPackageRow = new Set();
88101
output += 'Thanks for the PR! Here is the difference in size of the dist files between the base and the PR.\n';
89102
output += 'Please review the changes and make sure they are expected.\n\n';
90103
output += `<table>
91104
<thead><tr><th>File</th><th>Diff (B)</th><th>Diff (%)</th></tr></thead>
92105
<tbody>`;
93106
for (const [file, details] of files.entries()) {
107+
const isBridge = file.includes('src/Bridge');
108+
const packageName = file.split('/')[1];
109+
const bridgeName = isBridge ? file.split('/')[4] : '';
110+
const fileShort = file.replace(isBridge ? `src/${packageName}/src/Bridge/${bridgeName}/assets/dist/` : `src/${packageName}/assets/dist/`, '');
111+
const row = isBridge ? `${packageName} (Bridge ${bridgeName})` : packageName;
112+
if (!displayedPackageRow.has(row)) {
113+
displayedPackageRow.add(row);
114+
const urlRow = isBridge
115+
? `${repoUrl}/tree/${process.env.GITHUB_HEAD_REF}/src/${packageName}/src/Bridge/${bridgeName}/assets/dist`
116+
: `${repoUrl}/tree/${process.env.GITHUB_HEAD_REF}/src/${packageName}/assets/dist`;
117+
output += `<tr><td colspan="3"><a href="${urlRow}"><b>${row}</b></a></td></tr>`;
118+
}
119+
120+
const urlFile = `${repoUrl}/blob/${process.env.GITHUB_HEAD_REF}/${file}`;
121+
94122
output += `<tr>
95-
<td><code>${file}</code> ${details.state === 'added' ? '(new)' : (details.state === 'removed' ? '(deleted)' : '')}</td>
123+
<td><a href="${urlFile}"><code>${fileShort}</code></a> ${details.state === 'added' ? '(new)' : (details.state === 'removed' ? '(deleted)' : '')}</td>
96124
<td>
97125
Size: <code>${formatBytes(base[file]?.size || 0)}</code> → <code>${formatBytes(pr[file]?.size || 0)}</code><br>
98126
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)