🔧 Update check-size utility, fix bugs.

This commit is contained in:
pheralb 2023-12-16 21:16:52 +00:00
parent 19da26d9de
commit 49dab68575

View File

@ -7,7 +7,7 @@ const core = require('@actions/core');
// 🔎 Settings: // 🔎 Settings:
const dir = '../static/library'; const dir = '../static/library';
const sizeLimit = 20000; // 20kb; const sizeLimit = 25000; // 20kb;
function convertBytes(bytes, format = 'KB') { function convertBytes(bytes, format = 'KB') {
if (format === 'KB') { if (format === 'KB') {
@ -30,18 +30,19 @@ async function checkSize() {
const filePath = join(dir, file); const filePath = join(dir, file);
const stats = await stat(filePath); const stats = await stat(filePath);
if (stats.size > maxSize) { if (stats.size >= sizeLimit) {
maxSize = stats.size;
maxFiles.push({ maxFiles.push({
filename: file, filename: file,
size: maxSize size: stats.size
}); });
if (stats.size > maxSize) {
maxSize = stats.size;
}
} }
} }
if (maxFiles.length === 0) { if (maxFiles.length === 0) {
message = `- ✅ All files are smaller than ${convertBytes(sizeLimit)}`; message = `- ✅ All files are smaller than ${convertBytes(sizeLimit)}`;
console.log(message);
core.setOutput('message', message); core.setOutput('message', message);
} else { } else {
message = `- ❌ There are files bigger than ${convertBytes(sizeLimit)}.`; message = `- ❌ There are files bigger than ${convertBytes(sizeLimit)}.`;
@ -59,7 +60,9 @@ async function checkSize() {
console.log('⚙️ Settings:'); console.log('⚙️ Settings:');
console.log(`- 📁 Directory: ${dir}`); console.log(`- 📁 Directory: ${dir}`);
console.log(`- 🧱 Size limit: ${convertBytes(sizeLimit)} bytes`); console.log(`- 🧱 Size limit: ${convertBytes(sizeLimit)} bytes`);
console.log(`- 🔔 Max size found: ${convertBytes(maxSize, 'MB')}`); if (maxSize > 0) {
console.log(`- 🔔 Max size found: ${convertBytes(maxSize, 'KB')}`);
}
} }
} }