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