@commercetools-frontend/deployment-cli 1.0.0 → 2.0.0
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.
package/bin/cli.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const { exit } = require('node:process');
|
|
4
4
|
const { run } = require('@commercetools-frontend/deployment-cli/cli');
|
|
5
5
|
|
|
6
6
|
run().catch((error) => {
|
|
7
7
|
console.error(error.message || error.stack || error);
|
|
8
|
-
|
|
8
|
+
exit(1);
|
|
9
9
|
});
|
|
@@ -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');
|
|
@@ -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
|
|
|
25
|
+
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
24
26
|
var _findInstanceProperty__default = /*#__PURE__*/_interopDefault(_findInstanceProperty);
|
|
25
27
|
var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
|
|
26
28
|
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
|
27
29
|
var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
|
|
28
30
|
var _startsWithInstanceProperty__default = /*#__PURE__*/_interopDefault(_startsWithInstanceProperty);
|
|
29
|
-
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.0",
|
|
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",
|
|
@@ -69,15 +71,15 @@ var pkgJson = {
|
|
|
69
71
|
prompts: "2.4.2"
|
|
70
72
|
},
|
|
71
73
|
devDependencies: {
|
|
72
|
-
"@tsconfig/node20": "20.1.
|
|
74
|
+
"@tsconfig/node20": "20.1.4",
|
|
73
75
|
"@types/lodash": "^4.14.198",
|
|
74
|
-
"@types/node": "20.
|
|
76
|
+
"@types/node": "20.12.12",
|
|
75
77
|
"@types/prompts": "2.4.9",
|
|
76
|
-
msw: "1.3.
|
|
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 === null || cosmiconfigResult === void 0 ? void 0 : 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 '".concat(nameOfRequiredEnvironmentVariable, "' environment variable"));
|
|
127
129
|
});
|
|
128
130
|
}
|
|
129
131
|
const promptOptions = {
|
|
@@ -149,19 +151,23 @@ 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
|
-
|
|
154
|
+
choices: _mapInstanceProperty__default["default"](deploymentPipelines).call(deploymentPipelines, deploymentPipeline => {
|
|
155
|
+
var _context, _context2;
|
|
156
|
+
return {
|
|
157
|
+
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, ">"),
|
|
158
|
+
value: deploymentPipeline
|
|
159
|
+
};
|
|
160
|
+
})
|
|
156
161
|
};
|
|
157
162
|
},
|
|
158
163
|
deploymentConfirmation: _ref4 => {
|
|
164
|
+
var _context3;
|
|
159
165
|
let approvalJob = _ref4.approvalJob,
|
|
160
166
|
revision = _ref4.revision;
|
|
161
167
|
return {
|
|
162
168
|
type: 'toggle',
|
|
163
169
|
name: 'confirmed',
|
|
164
|
-
message:
|
|
170
|
+
message: _concatInstanceProperty__default["default"](_context3 = "Are you sure you want to deploy by approving ".concat(approvalJob, " at ")).call(_context3, revision, "?"),
|
|
165
171
|
initial: false,
|
|
166
172
|
active: 'Yes',
|
|
167
173
|
inactive: 'No'
|
|
@@ -178,7 +184,7 @@ async function paginateToDeploymentPipeline(_ref5) {
|
|
|
178
184
|
let nextPageToken;
|
|
179
185
|
// eslint-disable-next-line no-plusplus
|
|
180
186
|
for (let i = 0; i < maxPages; i++) {
|
|
181
|
-
var
|
|
187
|
+
var _context4, _context5;
|
|
182
188
|
// eslint-disable-next-line no-await-in-loop
|
|
183
189
|
|
|
184
190
|
const pipelineRequest = circleCiApis.pipelines({
|
|
@@ -189,18 +195,19 @@ async function paginateToDeploymentPipeline(_ref5) {
|
|
|
189
195
|
debug
|
|
190
196
|
});
|
|
191
197
|
nextPageToken = pipelines.next_page_token;
|
|
192
|
-
const nonScheduledPipelines = _filterInstanceProperty__default["default"](
|
|
198
|
+
const nonScheduledPipelines = _filterInstanceProperty__default["default"](_context4 = _filterInstanceProperty__default["default"](_context5 = pipelines.items).call(_context5, isNonScheduledPipeline)).call(_context4, isNonErroredPipeline);
|
|
193
199
|
if (buildRevision) {
|
|
194
|
-
|
|
200
|
+
var _context6, _context7;
|
|
201
|
+
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
202
|
deploymentPipeline = _findInstanceProperty__default["default"](nonScheduledPipelines).call(nonScheduledPipelines, pipeline => {
|
|
196
|
-
var
|
|
197
|
-
return _startsWithInstanceProperty__default["default"](
|
|
203
|
+
var _context8;
|
|
204
|
+
return _startsWithInstanceProperty__default["default"](_context8 = pipeline.vcs.revision).call(_context8, buildRevision);
|
|
198
205
|
});
|
|
199
206
|
} else {
|
|
200
207
|
deploymentPipeline = nonScheduledPipelines[0];
|
|
201
208
|
}
|
|
202
209
|
if (deploymentPipeline) {
|
|
203
|
-
console.log(
|
|
210
|
+
console.log("\u2139\uFE0F Using pipeline for deployment with revision ".concat(deploymentPipeline.vcs.revision, "."));
|
|
204
211
|
break;
|
|
205
212
|
}
|
|
206
213
|
}
|
|
@@ -215,7 +222,7 @@ async function collectDeploymentPipelines(_ref6) {
|
|
|
215
222
|
let nextPageToken;
|
|
216
223
|
// eslint-disable-next-line no-plusplus
|
|
217
224
|
for (let i = 0; i < pagesForPipelineSelection; i++) {
|
|
218
|
-
var
|
|
225
|
+
var _context9, _context10;
|
|
219
226
|
// eslint-disable-next-line no-await-in-loop
|
|
220
227
|
const pipelinesRequest = circleCiApis.pipelines({
|
|
221
228
|
pageToken: nextPageToken,
|
|
@@ -224,7 +231,7 @@ async function collectDeploymentPipelines(_ref6) {
|
|
|
224
231
|
const pipelines = await pipelinesRequest.execute({
|
|
225
232
|
debug
|
|
226
233
|
});
|
|
227
|
-
const nonScheduledPipelines = _filterInstanceProperty__default["default"](
|
|
234
|
+
const nonScheduledPipelines = _filterInstanceProperty__default["default"](_context9 = _filterInstanceProperty__default["default"](_context10 = pipelines.items).call(_context10, isNonScheduledPipeline)).call(_context9, isNonErroredPipeline);
|
|
228
235
|
deploymentPipelines = _concatInstanceProperty__default["default"](deploymentPipelines).call(deploymentPipelines, nonScheduledPipelines);
|
|
229
236
|
}
|
|
230
237
|
return deploymentPipelines;
|
|
@@ -263,11 +270,12 @@ async function waitForConfirmationPrompt(_ref8) {
|
|
|
263
270
|
}));
|
|
264
271
|
}
|
|
265
272
|
function getJobUrl(_ref9) {
|
|
273
|
+
var _context11, _context12, _context13;
|
|
266
274
|
let pipelineNumber = _ref9.pipelineNumber,
|
|
267
275
|
workflowId = _ref9.workflowId,
|
|
268
276
|
jobNumber = _ref9.jobNumber,
|
|
269
277
|
projectName = _ref9.projectName;
|
|
270
|
-
return
|
|
278
|
+
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
279
|
}
|
|
272
280
|
function isNonScheduledPipeline(pipeline) {
|
|
273
281
|
return pipeline.trigger.type !== 'schedule' && pipeline.trigger.type !== 'scheduled_pipeline';
|
|
@@ -281,14 +289,14 @@ async function waitForDeploymentJobNumber(_ref10, _ref11) {
|
|
|
281
289
|
circleCiApis = _ref10.circleCiApis;
|
|
282
290
|
let debug = _ref11.debug;
|
|
283
291
|
const fetchDeploymentJobNumber = async () => {
|
|
284
|
-
var
|
|
292
|
+
var _context14;
|
|
285
293
|
const jobsRequest = circleCiApis.jobs({
|
|
286
294
|
workflowId
|
|
287
295
|
});
|
|
288
296
|
const jobs = await jobsRequest.execute({
|
|
289
297
|
debug
|
|
290
298
|
});
|
|
291
|
-
const applicationDeploymentJob = _findInstanceProperty__default["default"](
|
|
299
|
+
const applicationDeploymentJob = _findInstanceProperty__default["default"](_context14 = jobs.items).call(_context14, job => job.name === deploymentJob);
|
|
292
300
|
if (!applicationDeploymentJob || applicationDeploymentJob.status === 'blocked') {
|
|
293
301
|
throw new Error('Deployment job not yet running. Retrying.');
|
|
294
302
|
}
|
|
@@ -296,7 +304,8 @@ async function waitForDeploymentJobNumber(_ref10, _ref11) {
|
|
|
296
304
|
};
|
|
297
305
|
const deploymentJobNumber = await pRetry__default["default"](fetchDeploymentJobNumber, {
|
|
298
306
|
onFailedAttempt: error => {
|
|
299
|
-
|
|
307
|
+
var _context15;
|
|
308
|
+
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
309
|
},
|
|
301
310
|
retries: 10
|
|
302
311
|
});
|
|
@@ -304,63 +313,65 @@ async function waitForDeploymentJobNumber(_ref10, _ref11) {
|
|
|
304
313
|
}
|
|
305
314
|
|
|
306
315
|
async function approve(cliFlags, config, circleCiApis) {
|
|
307
|
-
var
|
|
316
|
+
var _config$CircleCI$pagi, _config$CircleCI$pagi2, _config$CircleCI$pagi3, _config$CircleCI$pagi4, _context2, _context3, _context5, _confirmationPrompt;
|
|
308
317
|
let approvalJob;
|
|
309
318
|
let deploymentJob;
|
|
310
319
|
if (cliFlags.deployment) {
|
|
311
|
-
|
|
320
|
+
var _config$deployments, _context;
|
|
321
|
+
const requestedDeployment = (_config$deployments = config.deployments) === null || _config$deployments === void 0 ? void 0 : _config$deployments[cliFlags.deployment];
|
|
312
322
|
if (!requestedDeployment) {
|
|
313
|
-
throw new Error(
|
|
323
|
+
throw new Error("\u26A0\uFE0F Deployment ".concat(cliFlags.deployment, " not found in configuration. Make sure it exists."));
|
|
314
324
|
}
|
|
315
325
|
approvalJob = requestedDeployment.jobs.approval;
|
|
316
326
|
deploymentJob = requestedDeployment.jobs.deployment;
|
|
317
|
-
console.log(
|
|
327
|
+
console.log(_concatInstanceProperty__default["default"](_context = "\u2139\uFE0F Approving requested deployment ".concat(cliFlags.deployment, " with approval job ")).call(_context, approvalJob, "."));
|
|
318
328
|
} else {
|
|
319
329
|
approvalJob = cliFlags.approvalJob;
|
|
320
330
|
deploymentJob = cliFlags.deploymentJob;
|
|
321
|
-
console.log(
|
|
331
|
+
console.log("\u2139\uFE0F Approving with approval job ".concat(approvalJob, "."));
|
|
322
332
|
}
|
|
323
333
|
const deploymentPipeline = cliFlags.yes ? await paginateToDeploymentPipeline({
|
|
324
334
|
circleCiApis,
|
|
325
335
|
buildRevision: cliFlags.buildRevision,
|
|
326
336
|
branch: cliFlags.branch,
|
|
327
337
|
debug: cliFlags.debug,
|
|
328
|
-
maxPages: config.CircleCI.pagination
|
|
338
|
+
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
339
|
}) : await waitForDeploymentPipelinePrompt({
|
|
330
340
|
branch: cliFlags.branch,
|
|
331
341
|
circleCiApis,
|
|
332
|
-
pagesForPipelineSelection: config.CircleCI.pagination
|
|
342
|
+
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
343
|
debug: cliFlags.debug
|
|
334
344
|
});
|
|
335
345
|
if (!deploymentPipeline) {
|
|
336
|
-
throw new Error(
|
|
346
|
+
throw new Error("\u26A0\uFE0F No workflow called ".concat(config.CircleCI.deploymentWorkflowName, " found in any pipeline for deployment."));
|
|
337
347
|
}
|
|
338
|
-
console.log(
|
|
348
|
+
console.log("\u2139\uFE0F Found pipeline for deployment with revision ".concat(deploymentPipeline.vcs.revision, "."));
|
|
339
349
|
const workflowsRequest = circleCiApis.workflows({
|
|
340
350
|
pipelineId: deploymentPipeline.id
|
|
341
351
|
});
|
|
342
352
|
const workflows = await workflowsRequest.execute({
|
|
343
353
|
debug: cliFlags.debug
|
|
344
354
|
});
|
|
345
|
-
const buildAndDeployWorkflow = _findInstanceProperty__default["default"](
|
|
355
|
+
const buildAndDeployWorkflow = _findInstanceProperty__default["default"](_context2 = workflows.items).call(_context2, workflow => workflow.name === config.CircleCI.deploymentWorkflowName);
|
|
346
356
|
if (!buildAndDeployWorkflow) {
|
|
347
|
-
throw new Error(
|
|
357
|
+
throw new Error("\u26A0\uFE0F No workflow called ".concat(config.CircleCI.deploymentWorkflowName, " found for deployment."));
|
|
348
358
|
}
|
|
349
359
|
const workflowId = buildAndDeployWorkflow.id;
|
|
350
|
-
console.log(
|
|
360
|
+
console.log("\u2139\uFE0F Found workflow to build and deploy with id ".concat(workflowId, "."));
|
|
351
361
|
const jobsRequest = circleCiApis.jobs({
|
|
352
362
|
workflowId
|
|
353
363
|
});
|
|
354
364
|
const jobs = await jobsRequest.execute({
|
|
355
365
|
debug: cliFlags.debug
|
|
356
366
|
});
|
|
357
|
-
console.log(
|
|
358
|
-
const applicationApprovalJob = _findInstanceProperty__default["default"](
|
|
359
|
-
const applicationApprovalJobId = applicationApprovalJob
|
|
367
|
+
console.log("\u2139\uFE0F Found jobs for workflow.");
|
|
368
|
+
const applicationApprovalJob = _findInstanceProperty__default["default"](_context3 = jobs.items).call(_context3, job => job.name === approvalJob);
|
|
369
|
+
const applicationApprovalJobId = applicationApprovalJob === null || applicationApprovalJob === void 0 ? void 0 : applicationApprovalJob.id;
|
|
360
370
|
if (!applicationApprovalJobId) {
|
|
361
|
-
|
|
371
|
+
var _context4;
|
|
372
|
+
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
373
|
}
|
|
363
|
-
console.log(
|
|
374
|
+
console.log(_concatInstanceProperty__default["default"](_context5 = "\u2139\uFE0F Found deployment approval job named ".concat(approvalJob, " with id ")).call(_context5, applicationApprovalJobId, "."));
|
|
364
375
|
let confirmationPrompt;
|
|
365
376
|
if (!cliFlags.yes) {
|
|
366
377
|
confirmationPrompt = await waitForConfirmationPrompt({
|
|
@@ -368,11 +379,11 @@ async function approve(cliFlags, config, circleCiApis) {
|
|
|
368
379
|
revision: deploymentPipeline.vcs.revision
|
|
369
380
|
});
|
|
370
381
|
}
|
|
371
|
-
if (cliFlags.yes || confirmationPrompt
|
|
382
|
+
if (cliFlags.yes || (_confirmationPrompt = confirmationPrompt) !== null && _confirmationPrompt !== void 0 && _confirmationPrompt.confirmed) {
|
|
372
383
|
if (cliFlags.dryRun) {
|
|
373
|
-
console.log(
|
|
384
|
+
console.log("\uD83D\uDE4A Not approving deployment job due to dry run.");
|
|
374
385
|
} else {
|
|
375
|
-
console.log(
|
|
386
|
+
console.log("\u2139\uFE0F Approving deployment job.");
|
|
376
387
|
}
|
|
377
388
|
const approvalRequest = circleCiApis.approve({
|
|
378
389
|
workflowId,
|
|
@@ -383,10 +394,11 @@ async function approve(cliFlags, config, circleCiApis) {
|
|
|
383
394
|
skip: cliFlags.dryRun
|
|
384
395
|
});
|
|
385
396
|
if (cliFlags.yes) {
|
|
386
|
-
console.log(
|
|
397
|
+
console.log("\u2139\uFE0F Skipping determining deployment job approved by ".concat(approvalJob, " due to '--yes' flag. Please check CircleCI manually."));
|
|
387
398
|
} else if (cliFlags.dryRun) {
|
|
388
|
-
console.log(
|
|
399
|
+
console.log("\u270C\uFE0F Dry running hence could not determine deployment job approved by ".concat(approvalJob, "."));
|
|
389
400
|
} else if (deploymentJob) {
|
|
401
|
+
var _context6, _context7;
|
|
390
402
|
const deploymentJobNumber = await waitForDeploymentJobNumber({
|
|
391
403
|
workflowId,
|
|
392
404
|
deploymentJob,
|
|
@@ -396,22 +408,23 @@ async function approve(cliFlags, config, circleCiApis) {
|
|
|
396
408
|
dryRun: cliFlags.dryRun,
|
|
397
409
|
yes: cliFlags.yes
|
|
398
410
|
});
|
|
399
|
-
console.log(
|
|
411
|
+
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
412
|
projectName: config.CircleCI.projectName,
|
|
401
413
|
pipelineNumber: deploymentPipeline.number,
|
|
402
414
|
workflowId,
|
|
403
415
|
jobNumber: deploymentJobNumber
|
|
404
|
-
})
|
|
416
|
+
})));
|
|
405
417
|
} else {
|
|
406
|
-
console.log(
|
|
418
|
+
console.log("\u2139\uFE0F Skipping determining deployment job as no '--deployment-job' name to wait for was passed. Please check CircleCI manually.");
|
|
407
419
|
}
|
|
408
420
|
} else {
|
|
409
|
-
console.log(
|
|
421
|
+
console.log("\u2139\uFE0F Not approving deployment job. Confirm the prompt or use '--yes' option.");
|
|
410
422
|
}
|
|
411
423
|
}
|
|
412
424
|
|
|
413
425
|
async function processCircleCiResponse(response) {
|
|
414
426
|
if (!response.ok) {
|
|
427
|
+
var _context, _context2;
|
|
415
428
|
/**
|
|
416
429
|
* NOTE:
|
|
417
430
|
* Trying to handle known but undocumented responses of the CircleCI API.
|
|
@@ -431,13 +444,13 @@ async function processCircleCiResponse(response) {
|
|
|
431
444
|
message = _JSON$parse.message;
|
|
432
445
|
if (message.match(/job already approved/i)) {
|
|
433
446
|
console.log('ℹ️ Deployment job is already approved.');
|
|
434
|
-
|
|
447
|
+
// TODO: can we return instead of force exiting?
|
|
448
|
+
node_process.exit(0);
|
|
435
449
|
}
|
|
436
450
|
} catch {
|
|
437
451
|
// Ignore JSON parsing errors
|
|
438
452
|
}
|
|
439
|
-
throw new Error(
|
|
440
|
-
Status text is ${response.statusText} and text is ${error}.`);
|
|
453
|
+
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
454
|
}
|
|
442
455
|
return response.json();
|
|
443
456
|
}
|
|
@@ -445,10 +458,11 @@ function createCircleCiClient(_ref) {
|
|
|
445
458
|
let projectName = _ref.projectName,
|
|
446
459
|
apiBaseUrl = _ref.apiBaseUrl;
|
|
447
460
|
async function execute(api) {
|
|
461
|
+
var _context3;
|
|
448
462
|
let _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
449
463
|
skip = _ref2.skip,
|
|
450
464
|
debug = _ref2.debug;
|
|
451
|
-
let url =
|
|
465
|
+
let url = _concatInstanceProperty__default["default"](_context3 = "".concat(apiBaseUrl)).call(_context3, api.url);
|
|
452
466
|
if (api.params && api.method === 'GET') {
|
|
453
467
|
const urlSearchParams = new _URLSearchParams__default["default"]();
|
|
454
468
|
for (const _ref3 of _Object$entries__default["default"](api.params)) {
|
|
@@ -459,18 +473,18 @@ function createCircleCiClient(_ref) {
|
|
|
459
473
|
urlSearchParams.append(key, value);
|
|
460
474
|
}
|
|
461
475
|
}
|
|
462
|
-
url +=
|
|
476
|
+
url += "?".concat(urlSearchParams.toString());
|
|
463
477
|
}
|
|
464
478
|
if (skip) {
|
|
465
479
|
if (debug) {
|
|
466
|
-
console.log(
|
|
480
|
+
console.log("\uD83C\uDFED Skipping CircleCI call API at: ".concat(url, "."));
|
|
467
481
|
}
|
|
468
482
|
|
|
469
483
|
// @ts-expect-error
|
|
470
484
|
return _Promise__default["default"].resolve();
|
|
471
485
|
}
|
|
472
486
|
if (debug) {
|
|
473
|
-
console.log(
|
|
487
|
+
console.log("\uD83C\uDFED Calling CircleCI API at: ".concat(url, "."));
|
|
474
488
|
}
|
|
475
489
|
try {
|
|
476
490
|
const response = await fetch(url, {
|
|
@@ -481,7 +495,7 @@ function createCircleCiClient(_ref) {
|
|
|
481
495
|
const processedCircleCiResponse = await processCircleCiResponse(response);
|
|
482
496
|
return processedCircleCiResponse;
|
|
483
497
|
} catch (error) {
|
|
484
|
-
console.log(
|
|
498
|
+
console.log("\u26A0\uFE0F Calling CircleCI API at: ".concat(url, " failed."));
|
|
485
499
|
throw error;
|
|
486
500
|
}
|
|
487
501
|
}
|
|
@@ -490,12 +504,12 @@ function createCircleCiClient(_ref) {
|
|
|
490
504
|
let _ref5 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
491
505
|
pageToken = _ref5.pageToken,
|
|
492
506
|
_ref5$projectSlug = _ref5.projectSlug,
|
|
493
|
-
projectSlug = _ref5$projectSlug === void 0 ?
|
|
507
|
+
projectSlug = _ref5$projectSlug === void 0 ? "gh/commercetools/".concat(projectName) : _ref5$projectSlug,
|
|
494
508
|
_ref5$branch = _ref5.branch,
|
|
495
509
|
branch = _ref5$branch === void 0 ? 'main' : _ref5$branch;
|
|
496
510
|
return {
|
|
497
511
|
execute: options => execute({
|
|
498
|
-
url:
|
|
512
|
+
url: "/project/".concat(projectSlug, "/pipeline"),
|
|
499
513
|
headers: {
|
|
500
514
|
'Content-Type': 'application/json',
|
|
501
515
|
// The CLI throws if this is not present on environment
|
|
@@ -513,7 +527,7 @@ function createCircleCiClient(_ref) {
|
|
|
513
527
|
let pipelineId = _ref6.pipelineId;
|
|
514
528
|
return {
|
|
515
529
|
execute: options => execute({
|
|
516
|
-
url:
|
|
530
|
+
url: "/pipeline/".concat(pipelineId, "/workflow"),
|
|
517
531
|
headers: {
|
|
518
532
|
'Content-Type': 'application/json',
|
|
519
533
|
// The CLI throws if this is not present on environment
|
|
@@ -527,7 +541,7 @@ function createCircleCiClient(_ref) {
|
|
|
527
541
|
let workflowId = _ref7.workflowId;
|
|
528
542
|
return {
|
|
529
543
|
execute: options => execute({
|
|
530
|
-
url:
|
|
544
|
+
url: "/workflow/".concat(workflowId, "/job"),
|
|
531
545
|
headers: {
|
|
532
546
|
'Content-Type': 'application/json',
|
|
533
547
|
// The CLI throws if this is not present on environment
|
|
@@ -541,15 +555,18 @@ function createCircleCiClient(_ref) {
|
|
|
541
555
|
let workflowId = _ref8.workflowId,
|
|
542
556
|
approvalRequestId = _ref8.approvalRequestId;
|
|
543
557
|
return {
|
|
544
|
-
execute: options =>
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
558
|
+
execute: options => {
|
|
559
|
+
var _context4;
|
|
560
|
+
return execute({
|
|
561
|
+
url: _concatInstanceProperty__default["default"](_context4 = "/workflow/".concat(workflowId, "/approve/")).call(_context4, approvalRequestId, " "),
|
|
562
|
+
headers: {
|
|
563
|
+
'Content-Type': 'application/json',
|
|
564
|
+
// The CLI throws if this is not present on environment
|
|
565
|
+
'Circle-Token': process.env.CIRCLE_TOKEN
|
|
566
|
+
},
|
|
567
|
+
method: 'POST'
|
|
568
|
+
}, options);
|
|
569
|
+
}
|
|
553
570
|
};
|
|
554
571
|
}
|
|
555
572
|
};
|
|
@@ -577,13 +594,13 @@ async function run() {
|
|
|
577
594
|
|
|
578
595
|
// Command: Approve
|
|
579
596
|
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(
|
|
597
|
+
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
598
|
default: 'main'
|
|
582
599
|
}).option('--yes', '(optional) Skip all confirmation prompts. Useful in Continuous integration (CI) to automatically answer confirmation questions.', {
|
|
583
600
|
default: false
|
|
584
601
|
}).action(async options => {
|
|
585
602
|
if (options.dryRun) {
|
|
586
|
-
console.log(
|
|
603
|
+
console.log("\uD83D\uDE4A Do not worry. This is a dry run!");
|
|
587
604
|
}
|
|
588
605
|
throwIfRequiredEnvironmentVariableIsUnset(['CIRCLE_TOKEN']);
|
|
589
606
|
await approve(options, config, circleCiApis);
|