Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skip cleanup of files that don't match the regex #169

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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