@commercetools-frontend/deployment-cli 1.0.0 â 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var cac = require('cac');
|
|
6
|
+
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
6
7
|
var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
|
|
7
8
|
var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
|
|
8
9
|
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
|
|
9
10
|
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
|
|
10
11
|
var _startsWithInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/starts-with');
|
|
11
|
-
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
12
12
|
var cosmiconfig = require('cosmiconfig');
|
|
13
13
|
var merge = require('lodash/merge');
|
|
14
14
|
var prompts = require('prompts');
|
|
@@ -21,12 +21,12 @@ var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/string
|
|
|
21
21
|
|
|
22
22
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
23
23
|
|
|
24
|
+
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
24
25
|
var _findInstanceProperty__default = /*#__PURE__*/_interopDefault(_findInstanceProperty);
|
|
25
26
|
var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
|
|
26
27
|
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
|
27
28
|
var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
|
|
28
29
|
var _startsWithInstanceProperty__default = /*#__PURE__*/_interopDefault(_startsWithInstanceProperty);
|
|
29
|
-
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
30
30
|
var merge__default = /*#__PURE__*/_interopDefault(merge);
|
|
31
31
|
var prompts__default = /*#__PURE__*/_interopDefault(prompts);
|
|
32
32
|
var pRetry__default = /*#__PURE__*/_interopDefault(pRetry);
|
|
@@ -37,7 +37,7 @@ var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
|
|
|
37
37
|
|
|
38
38
|
var pkgJson = {
|
|
39
39
|
name: "@commercetools-frontend/deployment-cli",
|
|
40
|
-
version: "1.0.
|
|
40
|
+
version: "1.0.1",
|
|
41
41
|
description: "CLI to manage Custom Applications deployments in Google Storage.",
|
|
42
42
|
keywords: [
|
|
43
43
|
"commercetools",
|
|
@@ -69,11 +69,11 @@ var pkgJson = {
|
|
|
69
69
|
prompts: "2.4.2"
|
|
70
70
|
},
|
|
71
71
|
devDependencies: {
|
|
72
|
-
"@tsconfig/node20": "20.1.
|
|
72
|
+
"@tsconfig/node20": "20.1.4",
|
|
73
73
|
"@types/lodash": "^4.14.198",
|
|
74
|
-
"@types/node": "20.
|
|
74
|
+
"@types/node": "20.12.7",
|
|
75
75
|
"@types/prompts": "2.4.9",
|
|
76
|
-
msw: "1.3.
|
|
76
|
+
msw: "1.3.3",
|
|
77
77
|
typescript: "5.2.2"
|
|
78
78
|
},
|
|
79
79
|
engines: {
|
|
@@ -108,7 +108,7 @@ async function loadConfig() {
|
|
|
108
108
|
};
|
|
109
109
|
try {
|
|
110
110
|
const cosmiconfigResult = await deploymentConfigExplorer.search();
|
|
111
|
-
const mergedConfig = merge__default["default"](defaultConfig, cosmiconfigResult
|
|
111
|
+
const mergedConfig = merge__default["default"](defaultConfig, cosmiconfigResult === null || cosmiconfigResult === void 0 ? void 0 : cosmiconfigResult.config);
|
|
112
112
|
return mergedConfig;
|
|
113
113
|
} catch (e) {
|
|
114
114
|
console.warn(e);
|
|
@@ -117,13 +117,13 @@ async function loadConfig() {
|
|
|
117
117
|
}
|
|
118
118
|
function throwIfConfigurationLacksRequiredValues(parsedConfiguration) {
|
|
119
119
|
if (!parsedConfiguration.CircleCI.projectName) {
|
|
120
|
-
throw new Error(
|
|
120
|
+
throw new Error("Missing 'projectName' in 'CircleCI' on configuration. Make sure it exists!");
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
function throwIfRequiredEnvironmentVariableIsUnset(requiredEnvironmentVariables) {
|
|
124
124
|
_forEachInstanceProperty__default["default"](requiredEnvironmentVariables).call(requiredEnvironmentVariables, nameOfRequiredEnvironmentVariable => {
|
|
125
125
|
const valueOfRequiredEnvironmentVariable = process.env[nameOfRequiredEnvironmentVariable];
|
|
126
|
-
if (!valueOfRequiredEnvironmentVariable) throw new Error(
|
|
126
|
+
if (!valueOfRequiredEnvironmentVariable) throw new Error("Missing '".concat(nameOfRequiredEnvironmentVariable, "' environment variable"));
|
|
127
127
|
});
|
|
128
128
|
}
|
|
129
129
|
const promptOptions = {
|
|
@@ -149,19 +149,23 @@ const promptOptions = {
|
|
|
149
149
|
type: 'select',
|
|
150
150
|
name: 'deploymentPipeline',
|
|
151
151
|
message: 'Select the revision you would like to deploy',
|
|
152
|
-
choices: _mapInstanceProperty__default["default"](deploymentPipelines).call(deploymentPipelines, deploymentPipeline =>
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
152
|
+
choices: _mapInstanceProperty__default["default"](deploymentPipelines).call(deploymentPipelines, deploymentPipeline => {
|
|
153
|
+
var _context, _context2;
|
|
154
|
+
return {
|
|
155
|
+
title: _concatInstanceProperty__default["default"](_context = _concatInstanceProperty__default["default"](_context2 = "".concat(deploymentPipeline.vcs.revision.substring(0, 7), " - ")).call(_context2, deploymentPipeline.vcs.commit.subject, " <")).call(_context, deploymentPipeline.trigger.actor.login, ">"),
|
|
156
|
+
value: deploymentPipeline
|
|
157
|
+
};
|
|
158
|
+
})
|
|
156
159
|
};
|
|
157
160
|
},
|
|
158
161
|
deploymentConfirmation: _ref4 => {
|
|
162
|
+
var _context3;
|
|
159
163
|
let approvalJob = _ref4.approvalJob,
|
|
160
164
|
revision = _ref4.revision;
|
|
161
165
|
return {
|
|
162
166
|
type: 'toggle',
|
|
163
167
|
name: 'confirmed',
|
|
164
|
-
message:
|
|
168
|
+
message: _concatInstanceProperty__default["default"](_context3 = "Are you sure you want to deploy by approving ".concat(approvalJob, " at ")).call(_context3, revision, "?"),
|
|
165
169
|
initial: false,
|
|
166
170
|
active: 'Yes',
|
|
167
171
|
inactive: 'No'
|
|
@@ -178,7 +182,7 @@ async function paginateToDeploymentPipeline(_ref5) {
|
|
|
178
182
|
let nextPageToken;
|
|
179
183
|
// eslint-disable-next-line no-plusplus
|
|
180
184
|
for (let i = 0; i < maxPages; i++) {
|
|
181
|
-
var
|
|
185
|
+
var _context4, _context5;
|
|
182
186
|
// eslint-disable-next-line no-await-in-loop
|
|
183
187
|
|
|
184
188
|
const pipelineRequest = circleCiApis.pipelines({
|
|
@@ -189,18 +193,19 @@ async function paginateToDeploymentPipeline(_ref5) {
|
|
|
189
193
|
debug
|
|
190
194
|
});
|
|
191
195
|
nextPageToken = pipelines.next_page_token;
|
|
192
|
-
const nonScheduledPipelines = _filterInstanceProperty__default["default"](
|
|
196
|
+
const nonScheduledPipelines = _filterInstanceProperty__default["default"](_context4 = _filterInstanceProperty__default["default"](_context5 = pipelines.items).call(_context5, isNonScheduledPipeline)).call(_context4, isNonErroredPipeline);
|
|
193
197
|
if (buildRevision) {
|
|
194
|
-
|
|
198
|
+
var _context6, _context7;
|
|
199
|
+
console.log(_concatInstanceProperty__default["default"](_context6 = _concatInstanceProperty__default["default"](_context7 = "\uD83D\uDD04 Trying to find pipeline with revision ".concat(buildRevision, ". Attempt ")).call(_context7, i + 1, " out of ")).call(_context6, maxPages, "."));
|
|
195
200
|
deploymentPipeline = _findInstanceProperty__default["default"](nonScheduledPipelines).call(nonScheduledPipelines, pipeline => {
|
|
196
|
-
var
|
|
197
|
-
return _startsWithInstanceProperty__default["default"](
|
|
201
|
+
var _context8;
|
|
202
|
+
return _startsWithInstanceProperty__default["default"](_context8 = pipeline.vcs.revision).call(_context8, buildRevision);
|
|
198
203
|
});
|
|
199
204
|
} else {
|
|
200
205
|
deploymentPipeline = nonScheduledPipelines[0];
|
|
201
206
|
}
|
|
202
207
|
if (deploymentPipeline) {
|
|
203
|
-
console.log(
|
|
208
|
+
console.log("\u2139\uFE0F Using pipeline for deployment with revision ".concat(deploymentPipeline.vcs.revision, "."));
|
|
204
209
|
break;
|
|
205
210
|
}
|
|
206
211
|
}
|
|
@@ -215,7 +220,7 @@ async function collectDeploymentPipelines(_ref6) {
|
|
|
215
220
|
let nextPageToken;
|
|
216
221
|
// eslint-disable-next-line no-plusplus
|
|
217
222
|
for (let i = 0; i < pagesForPipelineSelection; i++) {
|
|
218
|
-
var
|
|
223
|
+
var _context9, _context10;
|
|
219
224
|
// eslint-disable-next-line no-await-in-loop
|
|
220
225
|
const pipelinesRequest = circleCiApis.pipelines({
|
|
221
226
|
pageToken: nextPageToken,
|
|
@@ -224,7 +229,7 @@ async function collectDeploymentPipelines(_ref6) {
|
|
|
224
229
|
const pipelines = await pipelinesRequest.execute({
|
|
225
230
|
debug
|
|
226
231
|
});
|
|
227
|
-
const nonScheduledPipelines = _filterInstanceProperty__default["default"](
|
|
232
|
+
const nonScheduledPipelines = _filterInstanceProperty__default["default"](_context9 = _filterInstanceProperty__default["default"](_context10 = pipelines.items).call(_context10, isNonScheduledPipeline)).call(_context9, isNonErroredPipeline);
|
|
228
233
|
deploymentPipelines = _concatInstanceProperty__default["default"](deploymentPipelines).call(deploymentPipelines, nonScheduledPipelines);
|
|
229
234
|
}
|
|
230
235
|
return deploymentPipelines;
|
|
@@ -263,11 +268,12 @@ async function waitForConfirmationPrompt(_ref8) {
|
|
|
263
268
|
}));
|
|
264
269
|
}
|
|
265
270
|
function getJobUrl(_ref9) {
|
|
271
|
+
var _context11, _context12, _context13;
|
|
266
272
|
let pipelineNumber = _ref9.pipelineNumber,
|
|
267
273
|
workflowId = _ref9.workflowId,
|
|
268
274
|
jobNumber = _ref9.jobNumber,
|
|
269
275
|
projectName = _ref9.projectName;
|
|
270
|
-
return
|
|
276
|
+
return _concatInstanceProperty__default["default"](_context11 = _concatInstanceProperty__default["default"](_context12 = _concatInstanceProperty__default["default"](_context13 = "https://app.circleci.com/pipelines/github/commercetools/".concat(projectName, "/")).call(_context13, pipelineNumber, "/workflows/")).call(_context12, workflowId, "/jobs/")).call(_context11, jobNumber);
|
|
271
277
|
}
|
|
272
278
|
function isNonScheduledPipeline(pipeline) {
|
|
273
279
|
return pipeline.trigger.type !== 'schedule' && pipeline.trigger.type !== 'scheduled_pipeline';
|
|
@@ -281,14 +287,14 @@ async function waitForDeploymentJobNumber(_ref10, _ref11) {
|
|
|
281
287
|
circleCiApis = _ref10.circleCiApis;
|
|
282
288
|
let debug = _ref11.debug;
|
|
283
289
|
const fetchDeploymentJobNumber = async () => {
|
|
284
|
-
var
|
|
290
|
+
var _context14;
|
|
285
291
|
const jobsRequest = circleCiApis.jobs({
|
|
286
292
|
workflowId
|
|
287
293
|
});
|
|
288
294
|
const jobs = await jobsRequest.execute({
|
|
289
295
|
debug
|
|
290
296
|
});
|
|
291
|
-
const applicationDeploymentJob = _findInstanceProperty__default["default"](
|
|
297
|
+
const applicationDeploymentJob = _findInstanceProperty__default["default"](_context14 = jobs.items).call(_context14, job => job.name === deploymentJob);
|
|
292
298
|
if (!applicationDeploymentJob || applicationDeploymentJob.status === 'blocked') {
|
|
293
299
|
throw new Error('Deployment job not yet running. Retrying.');
|
|
294
300
|
}
|
|
@@ -296,7 +302,8 @@ async function waitForDeploymentJobNumber(_ref10, _ref11) {
|
|
|
296
302
|
};
|
|
297
303
|
const deploymentJobNumber = await pRetry__default["default"](fetchDeploymentJobNumber, {
|
|
298
304
|
onFailedAttempt: error => {
|
|
299
|
-
|
|
305
|
+
var _context15;
|
|
306
|
+
console.log(_concatInstanceProperty__default["default"](_context15 = "\uD83D\uDD04 Trying to find deployment job. Attempt ".concat(error.attemptNumber, " with ")).call(_context15, error.retriesLeft, " retries left."));
|
|
300
307
|
},
|
|
301
308
|
retries: 10
|
|
302
309
|
});
|
|
@@ -304,63 +311,65 @@ async function waitForDeploymentJobNumber(_ref10, _ref11) {
|
|
|
304
311
|
}
|
|
305
312
|
|
|
306
313
|
async function approve(cliFlags, config, circleCiApis) {
|
|
307
|
-
var
|
|
314
|
+
var _config$CircleCI$pagi, _config$CircleCI$pagi2, _config$CircleCI$pagi3, _config$CircleCI$pagi4, _context2, _context3, _context5, _confirmationPrompt;
|
|
308
315
|
let approvalJob;
|
|
309
316
|
let deploymentJob;
|
|
310
317
|
if (cliFlags.deployment) {
|
|
311
|
-
|
|
318
|
+
var _config$deployments, _context;
|
|
319
|
+
const requestedDeployment = (_config$deployments = config.deployments) === null || _config$deployments === void 0 ? void 0 : _config$deployments[cliFlags.deployment];
|
|
312
320
|
if (!requestedDeployment) {
|
|
313
|
-
throw new Error(
|
|
321
|
+
throw new Error("\u26A0\uFE0F Deployment ".concat(cliFlags.deployment, " not found in configuration. Make sure it exists."));
|
|
314
322
|
}
|
|
315
323
|
approvalJob = requestedDeployment.jobs.approval;
|
|
316
324
|
deploymentJob = requestedDeployment.jobs.deployment;
|
|
317
|
-
console.log(
|
|
325
|
+
console.log(_concatInstanceProperty__default["default"](_context = "\u2139\uFE0F Approving requested deployment ".concat(cliFlags.deployment, " with approval job ")).call(_context, approvalJob, "."));
|
|
318
326
|
} else {
|
|
319
327
|
approvalJob = cliFlags.approvalJob;
|
|
320
328
|
deploymentJob = cliFlags.deploymentJob;
|
|
321
|
-
console.log(
|
|
329
|
+
console.log("\u2139\uFE0F Approving with approval job ".concat(approvalJob, "."));
|
|
322
330
|
}
|
|
323
331
|
const deploymentPipeline = cliFlags.yes ? await paginateToDeploymentPipeline({
|
|
324
332
|
circleCiApis,
|
|
325
333
|
buildRevision: cliFlags.buildRevision,
|
|
326
334
|
branch: cliFlags.branch,
|
|
327
335
|
debug: cliFlags.debug,
|
|
328
|
-
maxPages: config.CircleCI.pagination
|
|
336
|
+
maxPages: (_config$CircleCI$pagi = (_config$CircleCI$pagi2 = config.CircleCI.pagination) === null || _config$CircleCI$pagi2 === void 0 ? void 0 : _config$CircleCI$pagi2.maxPages) !== null && _config$CircleCI$pagi !== void 0 ? _config$CircleCI$pagi : 1
|
|
329
337
|
}) : await waitForDeploymentPipelinePrompt({
|
|
330
338
|
branch: cliFlags.branch,
|
|
331
339
|
circleCiApis,
|
|
332
|
-
pagesForPipelineSelection: config.CircleCI.pagination
|
|
340
|
+
pagesForPipelineSelection: (_config$CircleCI$pagi3 = (_config$CircleCI$pagi4 = config.CircleCI.pagination) === null || _config$CircleCI$pagi4 === void 0 ? void 0 : _config$CircleCI$pagi4.pagesForPipelineSelection) !== null && _config$CircleCI$pagi3 !== void 0 ? _config$CircleCI$pagi3 : 1,
|
|
333
341
|
debug: cliFlags.debug
|
|
334
342
|
});
|
|
335
343
|
if (!deploymentPipeline) {
|
|
336
|
-
throw new Error(
|
|
344
|
+
throw new Error("\u26A0\uFE0F No workflow called ".concat(config.CircleCI.deploymentWorkflowName, " found in any pipeline for deployment."));
|
|
337
345
|
}
|
|
338
|
-
console.log(
|
|
346
|
+
console.log("\u2139\uFE0F Found pipeline for deployment with revision ".concat(deploymentPipeline.vcs.revision, "."));
|
|
339
347
|
const workflowsRequest = circleCiApis.workflows({
|
|
340
348
|
pipelineId: deploymentPipeline.id
|
|
341
349
|
});
|
|
342
350
|
const workflows = await workflowsRequest.execute({
|
|
343
351
|
debug: cliFlags.debug
|
|
344
352
|
});
|
|
345
|
-
const buildAndDeployWorkflow = _findInstanceProperty__default["default"](
|
|
353
|
+
const buildAndDeployWorkflow = _findInstanceProperty__default["default"](_context2 = workflows.items).call(_context2, workflow => workflow.name === config.CircleCI.deploymentWorkflowName);
|
|
346
354
|
if (!buildAndDeployWorkflow) {
|
|
347
|
-
throw new Error(
|
|
355
|
+
throw new Error("\u26A0\uFE0F No workflow called ".concat(config.CircleCI.deploymentWorkflowName, " found for deployment."));
|
|
348
356
|
}
|
|
349
357
|
const workflowId = buildAndDeployWorkflow.id;
|
|
350
|
-
console.log(
|
|
358
|
+
console.log("\u2139\uFE0F Found workflow to build and deploy with id ".concat(workflowId, "."));
|
|
351
359
|
const jobsRequest = circleCiApis.jobs({
|
|
352
360
|
workflowId
|
|
353
361
|
});
|
|
354
362
|
const jobs = await jobsRequest.execute({
|
|
355
363
|
debug: cliFlags.debug
|
|
356
364
|
});
|
|
357
|
-
console.log(
|
|
358
|
-
const applicationApprovalJob = _findInstanceProperty__default["default"](
|
|
359
|
-
const applicationApprovalJobId = applicationApprovalJob
|
|
365
|
+
console.log("\u2139\uFE0F Found jobs for workflow.");
|
|
366
|
+
const applicationApprovalJob = _findInstanceProperty__default["default"](_context3 = jobs.items).call(_context3, job => job.name === approvalJob);
|
|
367
|
+
const applicationApprovalJobId = applicationApprovalJob === null || applicationApprovalJob === void 0 ? void 0 : applicationApprovalJob.id;
|
|
360
368
|
if (!applicationApprovalJobId) {
|
|
361
|
-
|
|
369
|
+
var _context4;
|
|
370
|
+
throw new Error(_concatInstanceProperty__default["default"](_context4 = "\u270C\uFE0F Could not find deployment approval job named ".concat(approvalJob, " at revision ")).call(_context4, deploymentPipeline.vcs.revision, ". Maybe try again later."));
|
|
362
371
|
}
|
|
363
|
-
console.log(
|
|
372
|
+
console.log(_concatInstanceProperty__default["default"](_context5 = "\u2139\uFE0F Found deployment approval job named ".concat(approvalJob, " with id ")).call(_context5, applicationApprovalJobId, "."));
|
|
364
373
|
let confirmationPrompt;
|
|
365
374
|
if (!cliFlags.yes) {
|
|
366
375
|
confirmationPrompt = await waitForConfirmationPrompt({
|
|
@@ -368,11 +377,11 @@ async function approve(cliFlags, config, circleCiApis) {
|
|
|
368
377
|
revision: deploymentPipeline.vcs.revision
|
|
369
378
|
});
|
|
370
379
|
}
|
|
371
|
-
if (cliFlags.yes || confirmationPrompt
|
|
380
|
+
if (cliFlags.yes || (_confirmationPrompt = confirmationPrompt) !== null && _confirmationPrompt !== void 0 && _confirmationPrompt.confirmed) {
|
|
372
381
|
if (cliFlags.dryRun) {
|
|
373
|
-
console.log(
|
|
382
|
+
console.log("\uD83D\uDE4A Not approving deployment job due to dry run.");
|
|
374
383
|
} else {
|
|
375
|
-
console.log(
|
|
384
|
+
console.log("\u2139\uFE0F Approving deployment job.");
|
|
376
385
|
}
|
|
377
386
|
const approvalRequest = circleCiApis.approve({
|
|
378
387
|
workflowId,
|
|
@@ -383,10 +392,11 @@ async function approve(cliFlags, config, circleCiApis) {
|
|
|
383
392
|
skip: cliFlags.dryRun
|
|
384
393
|
});
|
|
385
394
|
if (cliFlags.yes) {
|
|
386
|
-
console.log(
|
|
395
|
+
console.log("\u2139\uFE0F Skipping determining deployment job approved by ".concat(approvalJob, " due to '--yes' flag. Please check CircleCI manually."));
|
|
387
396
|
} else if (cliFlags.dryRun) {
|
|
388
|
-
console.log(
|
|
397
|
+
console.log("\u270C\uFE0F Dry running hence could not determine deployment job approved by ".concat(approvalJob, "."));
|
|
389
398
|
} else if (deploymentJob) {
|
|
399
|
+
var _context6, _context7;
|
|
390
400
|
const deploymentJobNumber = await waitForDeploymentJobNumber({
|
|
391
401
|
workflowId,
|
|
392
402
|
deploymentJob,
|
|
@@ -396,22 +406,23 @@ async function approve(cliFlags, config, circleCiApis) {
|
|
|
396
406
|
dryRun: cliFlags.dryRun,
|
|
397
407
|
yes: cliFlags.yes
|
|
398
408
|
});
|
|
399
|
-
console.log(
|
|
409
|
+
console.log(_concatInstanceProperty__default["default"](_context6 = _concatInstanceProperty__default["default"](_context7 = "\uD83D\uDE4C The deployment via ".concat(approvalJob, " at revision ")).call(_context7, deploymentPipeline.vcs.revision, " is running at: ")).call(_context6, getJobUrl({
|
|
400
410
|
projectName: config.CircleCI.projectName,
|
|
401
411
|
pipelineNumber: deploymentPipeline.number,
|
|
402
412
|
workflowId,
|
|
403
413
|
jobNumber: deploymentJobNumber
|
|
404
|
-
})
|
|
414
|
+
})));
|
|
405
415
|
} else {
|
|
406
|
-
console.log(
|
|
416
|
+
console.log("\u2139\uFE0F Skipping determining deployment job as no '--deployment-job' name to wait for was passed. Please check CircleCI manually.");
|
|
407
417
|
}
|
|
408
418
|
} else {
|
|
409
|
-
console.log(
|
|
419
|
+
console.log("\u2139\uFE0F Not approving deployment job. Confirm the prompt or use '--yes' option.");
|
|
410
420
|
}
|
|
411
421
|
}
|
|
412
422
|
|
|
413
423
|
async function processCircleCiResponse(response) {
|
|
414
424
|
if (!response.ok) {
|
|
425
|
+
var _context, _context2;
|
|
415
426
|
/**
|
|
416
427
|
* NOTE:
|
|
417
428
|
* Trying to handle known but undocumented responses of the CircleCI API.
|
|
@@ -436,8 +447,7 @@ async function processCircleCiResponse(response) {
|
|
|
436
447
|
} catch {
|
|
437
448
|
// Ignore JSON parsing errors
|
|
438
449
|
}
|
|
439
|
-
throw new Error(
|
|
440
|
-
Status text is ${response.statusText} and text is ${error}.`);
|
|
450
|
+
throw new Error(_concatInstanceProperty__default["default"](_context = _concatInstanceProperty__default["default"](_context2 = "".concat(response.status, ": Network response was not ok.\n\n Status text is ")).call(_context2, response.statusText, " and text is ")).call(_context, error, "."));
|
|
441
451
|
}
|
|
442
452
|
return response.json();
|
|
443
453
|
}
|
|
@@ -445,10 +455,11 @@ function createCircleCiClient(_ref) {
|
|
|
445
455
|
let projectName = _ref.projectName,
|
|
446
456
|
apiBaseUrl = _ref.apiBaseUrl;
|
|
447
457
|
async function execute(api) {
|
|
458
|
+
var _context3;
|
|
448
459
|
let _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
449
460
|
skip = _ref2.skip,
|
|
450
461
|
debug = _ref2.debug;
|
|
451
|
-
let url =
|
|
462
|
+
let url = _concatInstanceProperty__default["default"](_context3 = "".concat(apiBaseUrl)).call(_context3, api.url);
|
|
452
463
|
if (api.params && api.method === 'GET') {
|
|
453
464
|
const urlSearchParams = new _URLSearchParams__default["default"]();
|
|
454
465
|
for (const _ref3 of _Object$entries__default["default"](api.params)) {
|
|
@@ -459,18 +470,18 @@ function createCircleCiClient(_ref) {
|
|
|
459
470
|
urlSearchParams.append(key, value);
|
|
460
471
|
}
|
|
461
472
|
}
|
|
462
|
-
url +=
|
|
473
|
+
url += "?".concat(urlSearchParams.toString());
|
|
463
474
|
}
|
|
464
475
|
if (skip) {
|
|
465
476
|
if (debug) {
|
|
466
|
-
console.log(
|
|
477
|
+
console.log("\uD83C\uDFED Skipping CircleCI call API at: ".concat(url, "."));
|
|
467
478
|
}
|
|
468
479
|
|
|
469
480
|
// @ts-expect-error
|
|
470
481
|
return _Promise__default["default"].resolve();
|
|
471
482
|
}
|
|
472
483
|
if (debug) {
|
|
473
|
-
console.log(
|
|
484
|
+
console.log("\uD83C\uDFED Calling CircleCI API at: ".concat(url, "."));
|
|
474
485
|
}
|
|
475
486
|
try {
|
|
476
487
|
const response = await fetch(url, {
|
|
@@ -481,7 +492,7 @@ function createCircleCiClient(_ref) {
|
|
|
481
492
|
const processedCircleCiResponse = await processCircleCiResponse(response);
|
|
482
493
|
return processedCircleCiResponse;
|
|
483
494
|
} catch (error) {
|
|
484
|
-
console.log(
|
|
495
|
+
console.log("\u26A0\uFE0F Calling CircleCI API at: ".concat(url, " failed."));
|
|
485
496
|
throw error;
|
|
486
497
|
}
|
|
487
498
|
}
|
|
@@ -490,12 +501,12 @@ function createCircleCiClient(_ref) {
|
|
|
490
501
|
let _ref5 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
491
502
|
pageToken = _ref5.pageToken,
|
|
492
503
|
_ref5$projectSlug = _ref5.projectSlug,
|
|
493
|
-
projectSlug = _ref5$projectSlug === void 0 ?
|
|
504
|
+
projectSlug = _ref5$projectSlug === void 0 ? "gh/commercetools/".concat(projectName) : _ref5$projectSlug,
|
|
494
505
|
_ref5$branch = _ref5.branch,
|
|
495
506
|
branch = _ref5$branch === void 0 ? 'main' : _ref5$branch;
|
|
496
507
|
return {
|
|
497
508
|
execute: options => execute({
|
|
498
|
-
url:
|
|
509
|
+
url: "/project/".concat(projectSlug, "/pipeline"),
|
|
499
510
|
headers: {
|
|
500
511
|
'Content-Type': 'application/json',
|
|
501
512
|
// The CLI throws if this is not present on environment
|
|
@@ -513,7 +524,7 @@ function createCircleCiClient(_ref) {
|
|
|
513
524
|
let pipelineId = _ref6.pipelineId;
|
|
514
525
|
return {
|
|
515
526
|
execute: options => execute({
|
|
516
|
-
url:
|
|
527
|
+
url: "/pipeline/".concat(pipelineId, "/workflow"),
|
|
517
528
|
headers: {
|
|
518
529
|
'Content-Type': 'application/json',
|
|
519
530
|
// The CLI throws if this is not present on environment
|
|
@@ -527,7 +538,7 @@ function createCircleCiClient(_ref) {
|
|
|
527
538
|
let workflowId = _ref7.workflowId;
|
|
528
539
|
return {
|
|
529
540
|
execute: options => execute({
|
|
530
|
-
url:
|
|
541
|
+
url: "/workflow/".concat(workflowId, "/job"),
|
|
531
542
|
headers: {
|
|
532
543
|
'Content-Type': 'application/json',
|
|
533
544
|
// The CLI throws if this is not present on environment
|
|
@@ -541,15 +552,18 @@ function createCircleCiClient(_ref) {
|
|
|
541
552
|
let workflowId = _ref8.workflowId,
|
|
542
553
|
approvalRequestId = _ref8.approvalRequestId;
|
|
543
554
|
return {
|
|
544
|
-
execute: options =>
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
555
|
+
execute: options => {
|
|
556
|
+
var _context4;
|
|
557
|
+
return execute({
|
|
558
|
+
url: _concatInstanceProperty__default["default"](_context4 = "/workflow/".concat(workflowId, "/approve/")).call(_context4, approvalRequestId, " "),
|
|
559
|
+
headers: {
|
|
560
|
+
'Content-Type': 'application/json',
|
|
561
|
+
// The CLI throws if this is not present on environment
|
|
562
|
+
'Circle-Token': process.env.CIRCLE_TOKEN
|
|
563
|
+
},
|
|
564
|
+
method: 'POST'
|
|
565
|
+
}, options);
|
|
566
|
+
}
|
|
553
567
|
};
|
|
554
568
|
}
|
|
555
569
|
};
|
|
@@ -577,13 +591,13 @@ async function run() {
|
|
|
577
591
|
|
|
578
592
|
// Command: Approve
|
|
579
593
|
const usageApprove = 'Approves a job and by this triggers a deployment of a component. It requires a "CIRCLE_TOKEN" environment variable (https://circleci.com/docs/2.0/managing-api-tokens/).';
|
|
580
|
-
cli.command('approve', usageApprove).usage(
|
|
594
|
+
cli.command('approve', usageApprove).usage("approve \n\n ".concat(usageApprove)).option('--approval-job <string>', 'The name of the approval job to approve a deployment with.').option('--deployment-job [string]', '(optional) The name of the deployment job triggered by the approval job. If passed the CLI will print a URL to the deployment triggered on CircleCI.').option('--deployment [string]', '(optional) The name of a deployment configured in the configuration file.').option('--build-revision [git-sha]', '(optional) The git commit SHA that needs to be deployed. If not specified, the last successful pipeline is used.').option('--branch [string]', '(optional) The git branch to deploy from. If not specified.', {
|
|
581
595
|
default: 'main'
|
|
582
596
|
}).option('--yes', '(optional) Skip all confirmation prompts. Useful in Continuous integration (CI) to automatically answer confirmation questions.', {
|
|
583
597
|
default: false
|
|
584
598
|
}).action(async options => {
|
|
585
599
|
if (options.dryRun) {
|
|
586
|
-
console.log(
|
|
600
|
+
console.log("\uD83D\uDE4A Do not worry. This is a dry run!");
|
|
587
601
|
}
|
|
588
602
|
throwIfRequiredEnvironmentVariableIsUnset(['CIRCLE_TOKEN']);
|
|
589
603
|
await approve(options, config, circleCiApis);
|