Skip to content

Commit

Permalink
refactor(CLI): Modern logs for rollback command
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrzesik committed Oct 7, 2021
1 parent d071c5f commit f0970e0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/plugins/aws/lib/updateStack.js
Expand Up @@ -138,12 +138,13 @@ module.exports = {
cfData = await this.provider.request('CloudFormation', 'updateStack', params);
} catch (e) {
if (e.message.includes(NO_UPDATE_MESSAGE)) {
return;
return false;
}
throw e;
}

await this.monitorStack('update', cfData);
return true;
},

async updateStack() {
Expand Down
37 changes: 35 additions & 2 deletions lib/plugins/aws/rollback.js
Expand Up @@ -5,6 +5,9 @@ const updateStack = require('./lib/updateStack');
const monitorStack = require('./lib/monitorStack');
const findAndGroupDeployments = require('./utils/findAndGroupDeployments');
const ServerlessError = require('../../serverless-error');
const { style, log, progress, legacy } = require('@serverless/utils/log');

const mainProgress = progress.get('main');

class AwsRollback {
constructor(serverless, options) {
Expand All @@ -19,19 +22,49 @@ class AwsRollback {

'rollback:rollback': async () => {
if (!this.options.timestamp) {
this.serverless.cli.log(
legacy.log(
[
'Use a timestamp from the deploy list below to rollback to a specific version.',
'Run `sls rollback -t YourTimeStampHere`',
].join('\n')
);
log.notice(
'Select a timestamp from the deploy list below and run "sls rollback -t <timestamp>" to rollback your service to a specific version.'
);
log.notice();
await this.serverless.pluginManager.spawn('deploy:list');
return;
}

log.notice();
log.notice(
`Rolling back ${this.serverless.service.service} to timestamp "${this.options.timestamp}"`
);
log.info(); // Ensure gap between verbose logging

await this.setBucketName();
await this.setStackToUpdate();
await this.updateStack();
mainProgress.notice('Validating', { isMainEvent: true });
const result = await this.updateStack();

log.notice();
if (result) {
log.notice.success(
`Service rolled back to timestamp "${this.options.timestamp}" ${style.aside(
`(${Math.floor(
(Date.now() - this.serverless.pluginManager.commandRunStartTime) / 1000
)}s)`
)}`
);
} else {
log.notice.skip(
`No updates to be performed. Rollback skipped. ${style.aside(
`(${Math.floor(
(Date.now() - this.serverless.pluginManager.commandRunStartTime) / 1000
)}s)`
)}`
);
}
},
};
}
Expand Down

0 comments on commit f0970e0

Please sign in to comment.