@rharkor/caching-for-turbo 2.3.3 → 2.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.js +20 -20
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -204287,29 +204287,29 @@ const parseFileSize = (size) => {
|
|
|
204287
204287
|
|
|
204288
204288
|
|
|
204289
204289
|
async function cleanup(ctx, tracker) {
|
|
204290
|
-
const maxAge = core_core.getInput(
|
|
204291
|
-
const maxFiles = core_core.getInput(
|
|
204292
|
-
const maxSize = core_core.getInput(
|
|
204290
|
+
const maxAge = core_core.getInput('max-age') || process.env.MAX_AGE;
|
|
204291
|
+
const maxFiles = core_core.getInput('max-files') || process.env.MAX_FILES;
|
|
204292
|
+
const maxSize = core_core.getInput('max-size') || process.env.MAX_SIZE;
|
|
204293
204293
|
if (!maxAge && !maxFiles && !maxSize) {
|
|
204294
|
-
ctx.log.info(
|
|
204294
|
+
ctx.log.info('No cleanup options provided, skipping cleanup');
|
|
204295
204295
|
return;
|
|
204296
204296
|
}
|
|
204297
204297
|
const { maxAgeParsed, maxFilesParsed, maxSizeParsed } = {
|
|
204298
204298
|
maxAgeParsed: maxAge ? parse(maxAge) : undefined,
|
|
204299
204299
|
maxFilesParsed: maxFiles ? parseInt(maxFiles) : undefined,
|
|
204300
|
-
maxSizeParsed: maxSize ? parseFileSize(maxSize) : undefined
|
|
204300
|
+
maxSizeParsed: maxSize ? parseFileSize(maxSize) : undefined
|
|
204301
204301
|
};
|
|
204302
204302
|
if (maxAge && !maxAgeParsed) {
|
|
204303
|
-
core_core.error(
|
|
204304
|
-
throw new Error(
|
|
204303
|
+
core_core.error('Invalid max-age provided');
|
|
204304
|
+
throw new Error('Invalid max-age provided');
|
|
204305
204305
|
}
|
|
204306
204306
|
if (maxFiles && !maxFilesParsed) {
|
|
204307
|
-
core_core.error(
|
|
204308
|
-
throw new Error(
|
|
204307
|
+
core_core.error('Invalid max-files provided');
|
|
204308
|
+
throw new Error('Invalid max-files provided');
|
|
204309
204309
|
}
|
|
204310
204310
|
if (maxSize && !maxSizeParsed) {
|
|
204311
|
-
core_core.error(
|
|
204312
|
-
throw new Error(
|
|
204311
|
+
core_core.error('Invalid max-size provided');
|
|
204312
|
+
throw new Error('Invalid max-size provided');
|
|
204313
204313
|
}
|
|
204314
204314
|
const provider = getProvider(tracker);
|
|
204315
204315
|
let files = [];
|
|
@@ -204327,15 +204327,15 @@ Exiting early, no files were cleaned up.`;
|
|
|
204327
204327
|
const now = new Date();
|
|
204328
204328
|
const age = new Date(now.getTime() - maxAgeParsed);
|
|
204329
204329
|
fileToDelete.push(...files
|
|
204330
|
-
.filter(
|
|
204331
|
-
.map(
|
|
204330
|
+
.filter(file => new Date(file.createdAt) < age)
|
|
204331
|
+
.map(file => ({ ...file, reason: 'max-age' })));
|
|
204332
204332
|
}
|
|
204333
204333
|
if (maxFilesParsed && files.length > maxFilesParsed) {
|
|
204334
204334
|
const sortedByDate = [...files].sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
|
|
204335
204335
|
const excessFiles = sortedByDate.slice(0, files.length - maxFilesParsed);
|
|
204336
|
-
excessFiles.forEach(
|
|
204337
|
-
if (!fileToDelete.some(
|
|
204338
|
-
fileToDelete.push({ ...file, reason:
|
|
204336
|
+
excessFiles.forEach(file => {
|
|
204337
|
+
if (!fileToDelete.some(f => f.path === file.path)) {
|
|
204338
|
+
fileToDelete.push({ ...file, reason: 'max-files' });
|
|
204339
204339
|
}
|
|
204340
204340
|
});
|
|
204341
204341
|
}
|
|
@@ -204346,15 +204346,15 @@ Exiting early, no files were cleaned up.`;
|
|
|
204346
204346
|
for (const file of sortedByDate) {
|
|
204347
204347
|
if (totalSize <= maxSizeParsed)
|
|
204348
204348
|
break;
|
|
204349
|
-
if (!fileToDelete.some(
|
|
204350
|
-
fileToDelete.push({ ...file, reason:
|
|
204349
|
+
if (!fileToDelete.some(f => f.path === file.path)) {
|
|
204350
|
+
fileToDelete.push({ ...file, reason: 'max-size' });
|
|
204351
204351
|
totalSize -= file.size;
|
|
204352
204352
|
}
|
|
204353
204353
|
}
|
|
204354
204354
|
}
|
|
204355
204355
|
}
|
|
204356
204356
|
if (fileToDelete.length > 0) {
|
|
204357
|
-
ctx.log.info(`Cleaning up ${fileToDelete.length} files (${fileToDelete.map(
|
|
204357
|
+
ctx.log.info(`Cleaning up ${fileToDelete.length} files (${fileToDelete.map(f => `${f.path} (${f.reason})`)})`);
|
|
204358
204358
|
for (const file of fileToDelete) {
|
|
204359
204359
|
try {
|
|
204360
204360
|
await provider.delete(file.path);
|
|
@@ -204366,7 +204366,7 @@ Exiting early, no files were cleaned up.`;
|
|
|
204366
204366
|
}
|
|
204367
204367
|
}
|
|
204368
204368
|
else {
|
|
204369
|
-
ctx.log.info(
|
|
204369
|
+
ctx.log.info('No files to clean up');
|
|
204370
204370
|
}
|
|
204371
204371
|
}
|
|
204372
204372
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rharkor/caching-for-turbo",
|
|
3
3
|
"description": "Sets up Turborepo Remote Caching to work with GitHub Actions built-in cache",
|
|
4
|
-
"version": "2.3.
|
|
4
|
+
"version": "2.3.4",
|
|
5
5
|
"private": false,
|
|
6
6
|
"homepage": "https://github.com/rharkor/caching-for-turbo",
|
|
7
7
|
"repository": {
|