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