Skip to content

Commit 8ffe164

Browse files
committed
feat(deploy): Add API_RESOLVE_GIT_REF as action param
fixes #1007
1 parent 7e75506 commit 8ffe164

File tree

5 files changed

+80
-7
lines changed

5 files changed

+80
-7
lines changed

src/deploy.cmd.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class DeployCommand extends StaticCommand {
5353
this._createPackages = 'auto';
5454
this._addStrain = null;
5555
this._enableMinify = false;
56+
this._resolveGitRefSvc = 'helix-services/resolve-git-ref@v1';
5657
}
5758

5859
get requireConfigFile() {
@@ -139,6 +140,11 @@ class DeployCommand extends StaticCommand {
139140
return this;
140141
}
141142

143+
withResolveGitRefService(value) {
144+
this._resolveGitRefSvc = value;
145+
return this;
146+
}
147+
142148
actionName(script) {
143149
if (script.main.indexOf(path.resolve(__dirname, 'openwhisk')) === 0) {
144150
return `hlx--${script.name}`;
@@ -389,6 +395,11 @@ Alternatively you can auto-add one using the {grey --add <name>} option.`);
389395
.map(script => fs.readFile(script.zipFile)
390396
.then(action => ({ script, action })));
391397

398+
// get API url of resolve action
399+
if (this._resolveGitRefSvc) {
400+
params.RESOLVE_GITREF_SERVICE = this._resolveGitRefSvc;
401+
}
402+
392403
// create openwhisk package
393404
if (!this._dryRun) {
394405
const parameters = Object.keys(params).map((key) => {
@@ -411,10 +422,10 @@ Alternatively you can auto-add one using the {grey --add <name>} option.`);
411422
tick(`created package ${this._prefix}`, '');
412423
}
413424

414-
let updatestatic;
425+
let bindHelixServices;
415426
// bind helix-services
416-
if (this._bindStatic && !this._dryRun) {
417-
updatestatic = openwhisk.packages.update({
427+
if (!this._dryRun) {
428+
bindHelixServices = openwhisk.packages.update({
418429
package: {
419430
binding: {
420431
namespace: 'helix', // namespace to bind from
@@ -425,10 +436,8 @@ Alternatively you can auto-add one using the {grey --add <name>} option.`);
425436
}).then(() => {
426437
tick('bound helix-services', '');
427438
});
428-
// we don't have to wait for this.
429439
}
430440

431-
432441
// ... and deploy
433442
const deployed = read.map(p => p.then(({ script, action }) => {
434443
const actionoptions = {
@@ -459,7 +468,7 @@ Alternatively you can auto-add one using the {grey --add <name>} option.`);
459468
});
460469
}));
461470

462-
await Promise.all([...deployed, updatestatic]);
471+
await Promise.all([...deployed, bindHelixServices]);
463472

464473

465474
let numErrors = 0;

src/deploy.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ module.exports = function deploy() {
9191
type: 'boolean',
9292
default: false,
9393
})
94+
.option('svc-resolve-git-ref', {
95+
alias: 'svcResolveGitRef',
96+
describe: 'Service name for git-resolve-ref service',
97+
type: 'string',
98+
default: 'helix-services/resolve-git-ref@v1',
99+
})
94100
.array('default')
95101
.nargs('default', 2)
96102
.coerce('default', arg => arg.reduce((result, value, index, array) => {
@@ -160,6 +166,7 @@ module.exports = function deploy() {
160166
.withAddStrain(argv.add)
161167
.withStatic(argv.static)
162168
.withMinify(argv.minify)
169+
.withResolveGitRefService(argv.svcResolveGitRef)
163170
.run();
164171
},
165172

test/fixtures/all.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ HLX_DIRTY = true
4343
HLX_WSK_AUTH = foobar
4444
HLX_WSK_NAMESPACE = 1234
4545
HLX_WSK_HOST = myruntime.net
46+
HLX_SVC_RESOLVE_GIT_REF = resolve.api
4647

4748
#HLX_DEFAULT <forbidden use through env>
4849
#HLX_ADD = <forbidden use through env>

test/testDeployCli.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ describe('hlx deploy', () => {
4848
mockDeploy.withAddStrain.returnsThis();
4949
mockDeploy.withStatic.returnsThis();
5050
mockDeploy.withMinify.returnsThis();
51+
mockDeploy.withResolveGitRefService.returnsThis();
5152
mockDeploy.run.returnsThis();
5253

5354
// disable static functions as well to avoid shelljs executions.
@@ -128,6 +129,7 @@ OpenWhisk Namespace is required`);
128129
sinon.assert.calledWith(mockDeploy.withCircleciAuth, '');
129130
sinon.assert.calledWith(mockDeploy.withDryRun, false);
130131
sinon.assert.calledWith(mockDeploy.withMinify, false);
132+
sinon.assert.calledWith(mockDeploy.withResolveGitRefService, 'helix-services/resolve-git-ref@v1');
131133
sinon.assert.calledOnce(mockDeploy.run);
132134
});
133135

@@ -151,6 +153,7 @@ OpenWhisk Namespace is required`);
151153
sinon.assert.calledWith(mockDeploy.withCircleciAuth, 'foobar');
152154
sinon.assert.calledWith(mockDeploy.withDryRun, true);
153155
sinon.assert.calledWith(mockDeploy.withMinify, true);
156+
sinon.assert.calledWith(mockDeploy.withResolveGitRefService, 'resolve.api');
154157
sinon.assert.calledOnce(mockDeploy.run);
155158
});
156159

@@ -369,4 +372,17 @@ OpenWhisk Namespace is required`);
369372
sinon.assert.calledWith(mockDeploy.withAddStrain, '');
370373
sinon.assert.calledOnce(mockDeploy.run);
371374
});
375+
376+
it('hlx deploy can set the resolve api', () => {
377+
new CLI()
378+
.withCommandExecutor('deploy', mockDeploy)
379+
.run(['deploy',
380+
'--wsk-auth', 'secret-key',
381+
'--wsk-namespace', 'hlx',
382+
'--svc-resolve-git-ref', 'helix-services/foobar',
383+
]);
384+
385+
sinon.assert.calledWith(mockDeploy.withResolveGitRefService, 'helix-services/foobar');
386+
sinon.assert.calledOnce(mockDeploy.run);
387+
});
372388
});

test/testDeployCmd.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,41 @@ describe('hlx deploy (Integration)', () => {
450450
delete res.body;
451451
});
452452
this.polly.server.put(`https://adobeioruntime.net/api/v1/namespaces/hlx/packages/${ref}`).intercept((req, res) => {
453-
res.sendStatus(201);
453+
const body = JSON.parse(req.body);
454+
try {
455+
assert.deepEqual(body, {
456+
publish: true,
457+
parameters: [
458+
{
459+
key: 'FOO',
460+
value: 'bar',
461+
},
462+
{
463+
key: 'LOGGLY_HOST',
464+
value: 'loggly-host',
465+
},
466+
{
467+
key: 'LOGGLY_KEY',
468+
value: 'loggly-auth',
469+
},
470+
{
471+
key: 'RESOLVE_GITREF_SERVICE',
472+
value: 'my-resolver',
473+
},
474+
],
475+
annotations: [
476+
{
477+
key: 'hlx-code-origin',
478+
value: 'ssh://git@github.com/adobe/project-helix.io.git#master',
479+
},
480+
],
481+
});
482+
res.sendStatus(201);
483+
} catch (e) {
484+
// eslint-disable-next-line no-console
485+
console.error(e);
486+
res.sendStatus(500);
487+
}
454488
});
455489
this.polly.server.put('https://adobeioruntime.net/api/v1/namespaces/hlx/actions/hlx--static').intercept((req, res) => {
456490
res.sendStatus(201);
@@ -478,6 +512,12 @@ describe('hlx deploy (Integration)', () => {
478512
.withDryRun(false)
479513
.withTarget(buildDir)
480514
.withMinify(false)
515+
.withLogglyAuth('loggly-auth')
516+
.withLogglyHost('loggly-host')
517+
.withDefault({
518+
FOO: 'bar',
519+
})
520+
.withResolveGitRefService('my-resolver')
481521
.run();
482522

483523
assert.equal(cmd.config.strains.get('default').package, '');

0 commit comments

Comments
 (0)