diff --git a/deploy/lib/cleanupDeploymentBucket.js b/deploy/lib/cleanupDeploymentBucket.js index c5084d4..6a51b2a 100644 --- a/deploy/lib/cleanupDeploymentBucket.js +++ b/deploy/lib/cleanupDeploymentBucket.js @@ -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);