Skip to content
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
48 changes: 23 additions & 25 deletions .github/actions/file-diff/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,33 +149,31 @@ async function run() {
]
: []),
],
...fileMap.entries(),
]
.reduce(
(
table,
[readableFilename, { byteSize = 0, diffByteSize = 0 }]
) => {
// @todo readable filename can be linked to html diff of the file?
// https://github.com/adobe/spectrum-css/pull/2093/files#diff-6badd53e481452b5af234953767029ef2e364427dd84cdeed25f5778b6fca2e6
const row = [
readableFilename,
byteSize === 0 ? "**removed**" : bytesToSize(byteSize),
diffByteSize === 0 ? "" : bytesToSize(diffByteSize),
];

if (hasDiff && diffByteSize > 0) {
if (byteSize === 0) row.push("", "");
else {
row.push(printChange(diffByteSize - byteSize), "");
}
].map((row) => `| ${row.join(" | ")} |`),
...fileMap.entries().reduce(
(
table,
[readableFilename, { byteSize = 0, diffByteSize = 0 }]
) => {
// @todo readable filename can be linked to html diff of the file?
// https://github.com/adobe/spectrum-css/pull/2093/files#diff-6badd53e481452b5af234953767029ef2e364427dd84cdeed25f5778b6fca2e6
const row = [
readableFilename,
byteSize === 0 ? "**removed**" : bytesToSize(byteSize),
diffByteSize === 0 ? "" : bytesToSize(diffByteSize),
];

if (hasDiff && diffByteSize > 0) {
if (byteSize === 0) row.push("", "");
else {
row.push(printChange(diffByteSize - byteSize), "");
}
}

return [...table, row];
},
[]
)
.map((row) => `| ${row.join(" | ")} |`),
return [...table, row];
},
[]
).map((row) => `| ${row.join(" | ")} |`),
);

markdown.push(...md);
Expand Down
10 changes: 9 additions & 1 deletion .github/actions/file-diff/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,20 @@ function debugEmptyDirectory(path, pattern, { core }) {
* @returns {string} The size in human readable format
*/
exports.bytesToSize = function (bytes) {
if (!bytes) return "-";
if (bytes === 0) return "0";

const sizes = ["bytes", "KB", "MB", "GB", "TB"];

// Determine the size identifier to use (KB, MB, etc)
const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
if (i === 0) return (bytes / 1000).toFixed(2) + " " + sizes[1];

if (i === 0) {
const value = (bytes / 1000).toFixed(2);
if (value === "0.00") return "< 0.01 KB";
return value + " " + sizes[1];
}

return (bytes / Math.pow(1024, i)).toFixed(2) + " " + sizes[i];
};

Expand Down