Skip to content
Open
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
19 changes: 15 additions & 4 deletions deploy/lib/cleanupDeploymentBucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,25 @@ module.exports = {

const files = response.items;

// 4 old ones + the one which will be uploaded after the cleanup = 5
const objectsToKeepCount = 4;
const oldFileRegex = /(serverless)\/(.+)\/(.+)\/(\d+)-(.+)\/(.+\.zip)/;

// filter out files that are in the bucket but don't match files created by the plugin
const filteredFiles = _.filter(files, (file) => {
if (file.name.match(oldFileRegex)) {
// the file matches the ones we want to clean up
return true;
}
return false;
});

const orderedObjects = _.orderBy(files, (file) => {
const timestamp = file.name.match(/(serverless)\/(.+)\/(.+)\/(\d+)-(.+)\/(.+\.zip)/)[4];
const orderedObjects = _.orderBy(filteredFiles, (file) => {
const timestamp = file.name.match(oldFileRegex)[4];
return timestamp;
}, ['asc']);

// 4 old ones + the one which will be uploaded after the cleanup = 5
const objectsToKeepCount = 4;

const objectsToKeep = _.takeRight(orderedObjects, objectsToKeepCount);
const objectsToRemove = _.pullAllWith(files, objectsToKeep, _.isEqual);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const objectsToRemove = _.pullAllWith(files, objectsToKeep, _.isEqual);
const objectsToRemove = _.pullAllWith(filteredFiles, objectsToKeep, _.isEqual);

You can't just use all files list because there are directory paths that has other files that we want to keep in objectsToKeep, then I suggest this change on the code


Expand Down