Skip to content

Commit 3c73204

Browse files
feat(update): add support for automatically rolling back failed updates
1 parent 0b4b606 commit 3c73204

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

lib/commands/update.js

+29-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,12 @@ class UpdateCommand extends Command {
114114
return;
115115
}
116116

117-
return this.ui.listr(tasks, context);
117+
return this.ui.listr(tasks, context).catch(error =>
118+
this.rollbackFromFail(error, {
119+
argv,
120+
version: context.vesion
121+
})
122+
);
118123
});
119124
});
120125
}
@@ -196,6 +201,24 @@ class UpdateCommand extends Command {
196201
});
197202
}
198203

204+
rollbackFromFail(error, ctx) {
205+
const oldVer = this.system.getInstance().cliConfig.get('previous-version');
206+
const newVer = ctx.version;
207+
this.ui.error(error);
208+
const question = `Unable to upgrade Ghost from v${oldVer} to v${newVer} - Would you like to revert back to v${oldVer}?`;
209+
const promise = ctx.argv['auto-rollback'] ? Promise.resolve(true) : this.ui.confirm(question, true);
210+
211+
return promise.then(answer => {
212+
if (!answer) {
213+
return Promise.resolve();
214+
}
215+
216+
return this.run({
217+
rollback: true
218+
});
219+
});
220+
}
221+
199222
link(context) {
200223
const symlinkSync = require('symlink-or-copy').sync;
201224

@@ -233,6 +256,11 @@ UpdateCommand.options = {
233256
describe: 'Limit update to Ghost 1.x releases',
234257
type: 'boolean',
235258
default: false
259+
},
260+
'auto-rollback': {
261+
description: '[--no-auto-rollback] Enable/Disable automatically rolling back Ghost if updating fails',
262+
type: 'boolean',
263+
default: false
236264
}
237265
};
238266
UpdateCommand.checkVersion = true;

0 commit comments

Comments
 (0)