Skip to content

Commit

Permalink
Merge 270791b into 1c15ac3
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew-Smith committed Jun 4, 2019
2 parents 1c15ac3 + 270791b commit e788a94
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions deploy/lib/cleanupDeploymentBucket.js
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);

Expand Down

0 comments on commit e788a94

Please sign in to comment.