Skip to content

Commit

Permalink
feat(publish): enable a choice between soft (new default) and hard pu…
Browse files Browse the repository at this point in the history
  • Loading branch information
trieloff committed Sep 9, 2019
1 parent 2db907d commit b9aecd3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ module.exports = function strain() {
describe: 'Version of the dispatch action to use.',
type: 'string',
})
.option('purge', {
describe: 'How to purge the cache after deployment',
choices: ['soft', 'hard', 'skip'],
default: 'soft',
})
.conflicts('only', 'exclude')
.demandOption(
'fastly-auth',
Expand Down Expand Up @@ -120,6 +125,7 @@ module.exports = function strain() {
.withFilter(argv.only, argv.exclude)
.withCustomVCLs(argv.customVCL)
.withDispatchVersion(argv.dispatchVersion)
.withPurge(argv.purge)
.run();
},
};
Expand Down
25 changes: 21 additions & 4 deletions src/remotepublish.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class RemotePublishCommand extends AbstractCommand {
this._configPurgeAPI = 'https://app.project-helix.io/config/purge';
this._vcl = null;
this._dispatchVersion = null;
this._purge = null;
}

tick(ticks = 1, message, name) {
Expand Down Expand Up @@ -121,6 +122,10 @@ class RemotePublishCommand extends AbstractCommand {
return this;
}

withPurge(value) {
this._purge = value;
}

withFilter(only, exclude) {
if (!(only || exclude)) {
return this;
Expand Down Expand Up @@ -237,19 +242,31 @@ class RemotePublishCommand extends AbstractCommand {
}

purgeFastly() {
if (this._dryRun) {
if (this._dryRun || !(this._purge === 'soft' || this._purge === 'hard')) {
this.tick(1, 'skipping cache purge');
return false;
}
return this._fastly.purgeAll()
if (this._purge === 'hard') {
return this._fastly.purgeAll()
.then(() => {
this.tick(1, 'purged cache hard', true);
return true;
})
.catch((e) => {
this.tick(1, 'failed to purge cache', true);
this.log.error(`Cache could not get purged ${e}`);
throw new Error('Unable to purge cache hard: ');
});
}
return this._fastly.softPurgeKey('all')
.then(() => {
this.tick(1, 'purged cache', true);
this.tick(1, 'soft purged cache', true);
return true;
})
.catch((e) => {
this.tick(1, 'failed to purge cache', true);
this.log.error(`Cache could not get purged ${e}`);
throw new Error('Unable to purge cache: ');
throw new Error('Unable to soft purge cache: ');
});
}

Expand Down
3 changes: 3 additions & 0 deletions test/testPublishCli.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe('hlx publish', () => {
mockPublish.withFilter.returnsThis();
mockPublish.withCustomVCLs.returnsThis();
mockPublish.withDispatchVersion.returnsThis();
mockPublish.withPurge.returnsThis();
mockPublish.run.returnsThis();
});

Expand Down Expand Up @@ -85,6 +86,7 @@ describe('hlx publish', () => {
'--wsk-namespace', 'hlx',
'--fastly-auth', 'secret-key',
'--fastly-namespace', 'hlx',
'--purge', 'hard',
]);

sinon.assert.calledWith(mockPublish.withWskHost, 'adobeioruntime.net');
Expand All @@ -94,6 +96,7 @@ describe('hlx publish', () => {
sinon.assert.calledWith(mockPublish.withFastlyAuth, 'secret-key');
sinon.assert.calledWith(mockPublish.withCustomVCLs, []);
sinon.assert.calledWith(mockPublish.withDispatchVersion, undefined);
sinon.assert.calledWith(mockPublish.withPurge, 'hard');
sinon.assert.calledOnce(mockPublish.run);
});

Expand Down

0 comments on commit b9aecd3

Please sign in to comment.