@commercetools-frontend/deployment-cli 0.2.4 → 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
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { cac } from 'cac';
|
|
2
|
-
import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
|
|
3
2
|
import _findInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/find';
|
|
4
3
|
import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/for-each';
|
|
5
4
|
import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
|
|
6
5
|
import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
|
|
7
6
|
import _startsWithInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/starts-with';
|
|
7
|
+
import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
|
|
8
8
|
import { cosmiconfig } from 'cosmiconfig';
|
|
9
9
|
import merge from 'lodash/merge';
|
|
10
10
|
import prompts from 'prompts';
|
|
@@ -14,11 +14,10 @@ import _URLSearchParams from '@babel/runtime-corejs3/core-js-stable/url-search-p
|
|
|
14
14
|
import _Object$entries from '@babel/runtime-corejs3/core-js-stable/object/entries';
|
|
15
15
|
import _Promise from '@babel/runtime-corejs3/core-js-stable/promise';
|
|
16
16
|
import _JSON$stringify from '@babel/runtime-corejs3/core-js-stable/json/stringify';
|
|
17
|
-
import fetch from 'node-fetch';
|
|
18
17
|
|
|
19
18
|
var pkgJson = {
|
|
20
19
|
name: "@commercetools-frontend/deployment-cli",
|
|
21
|
-
version: "0.
|
|
20
|
+
version: "1.0.0",
|
|
22
21
|
description: "CLI to manage Custom Applications deployments in Google Storage.",
|
|
23
22
|
keywords: [
|
|
24
23
|
"commercetools",
|
|
@@ -44,23 +43,21 @@ var pkgJson = {
|
|
|
44
43
|
"@babel/runtime": "^7.21.0",
|
|
45
44
|
"@babel/runtime-corejs3": "^7.21.0",
|
|
46
45
|
cac: "^6.7.14",
|
|
47
|
-
cosmiconfig: "
|
|
46
|
+
cosmiconfig: "9.0.0",
|
|
48
47
|
lodash: "4.17.21",
|
|
49
|
-
"node-fetch": "2.7.0",
|
|
50
48
|
"p-retry": "4.6.2",
|
|
51
49
|
prompts: "2.4.2"
|
|
52
50
|
},
|
|
53
51
|
devDependencies: {
|
|
54
52
|
"@tsconfig/node20": "20.1.2",
|
|
55
53
|
"@types/lodash": "^4.14.198",
|
|
56
|
-
"@types/node": "20.
|
|
57
|
-
"@types/
|
|
58
|
-
"@types/prompts": "2.4.5",
|
|
54
|
+
"@types/node": "20.11.5",
|
|
55
|
+
"@types/prompts": "2.4.9",
|
|
59
56
|
msw: "1.3.2",
|
|
60
57
|
typescript: "5.2.2"
|
|
61
58
|
},
|
|
62
59
|
engines: {
|
|
63
|
-
node: ">=
|
|
60
|
+
node: ">=18",
|
|
64
61
|
npm: ">=6"
|
|
65
62
|
},
|
|
66
63
|
publishConfig: {
|
|
@@ -75,7 +72,9 @@ var pkgJson = {
|
|
|
75
72
|
};
|
|
76
73
|
|
|
77
74
|
async function loadConfig() {
|
|
78
|
-
const deploymentConfigExplorer = cosmiconfig('deployment'
|
|
75
|
+
const deploymentConfigExplorer = cosmiconfig('deployment', {
|
|
76
|
+
searchStrategy: 'project'
|
|
77
|
+
});
|
|
79
78
|
const defaultConfig = {
|
|
80
79
|
CircleCI: {
|
|
81
80
|
apiBaseUrl: 'https://circleci.com/api/v2',
|
|
@@ -89,7 +88,7 @@ async function loadConfig() {
|
|
|
89
88
|
};
|
|
90
89
|
try {
|
|
91
90
|
const cosmiconfigResult = await deploymentConfigExplorer.search();
|
|
92
|
-
const mergedConfig = merge(defaultConfig, cosmiconfigResult
|
|
91
|
+
const mergedConfig = merge(defaultConfig, cosmiconfigResult?.config);
|
|
93
92
|
return mergedConfig;
|
|
94
93
|
} catch (e) {
|
|
95
94
|
console.warn(e);
|
|
@@ -98,13 +97,13 @@ async function loadConfig() {
|
|
|
98
97
|
}
|
|
99
98
|
function throwIfConfigurationLacksRequiredValues(parsedConfiguration) {
|
|
100
99
|
if (!parsedConfiguration.CircleCI.projectName) {
|
|
101
|
-
throw new Error(
|
|
100
|
+
throw new Error(`Missing 'projectName' in 'CircleCI' on configuration. Make sure it exists!`);
|
|
102
101
|
}
|
|
103
102
|
}
|
|
104
103
|
function throwIfRequiredEnvironmentVariableIsUnset(requiredEnvironmentVariables) {
|
|
105
104
|
_forEachInstanceProperty(requiredEnvironmentVariables).call(requiredEnvironmentVariables, nameOfRequiredEnvironmentVariable => {
|
|
106
105
|
const valueOfRequiredEnvironmentVariable = process.env[nameOfRequiredEnvironmentVariable];
|
|
107
|
-
if (!valueOfRequiredEnvironmentVariable) throw new Error(
|
|
106
|
+
if (!valueOfRequiredEnvironmentVariable) throw new Error(`Missing '${nameOfRequiredEnvironmentVariable}' environment variable`);
|
|
108
107
|
});
|
|
109
108
|
}
|
|
110
109
|
const promptOptions = {
|
|
@@ -130,23 +129,19 @@ const promptOptions = {
|
|
|
130
129
|
type: 'select',
|
|
131
130
|
name: 'deploymentPipeline',
|
|
132
131
|
message: 'Select the revision you would like to deploy',
|
|
133
|
-
choices: _mapInstanceProperty(deploymentPipelines).call(deploymentPipelines, deploymentPipeline => {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
value: deploymentPipeline
|
|
138
|
-
};
|
|
139
|
-
})
|
|
132
|
+
choices: _mapInstanceProperty(deploymentPipelines).call(deploymentPipelines, deploymentPipeline => ({
|
|
133
|
+
title: `${deploymentPipeline.vcs.revision.substring(0, 7)} - ${deploymentPipeline.vcs.commit.subject} <${deploymentPipeline.trigger.actor.login}>`,
|
|
134
|
+
value: deploymentPipeline
|
|
135
|
+
}))
|
|
140
136
|
};
|
|
141
137
|
},
|
|
142
138
|
deploymentConfirmation: _ref4 => {
|
|
143
|
-
var _context3;
|
|
144
139
|
let approvalJob = _ref4.approvalJob,
|
|
145
140
|
revision = _ref4.revision;
|
|
146
141
|
return {
|
|
147
142
|
type: 'toggle',
|
|
148
143
|
name: 'confirmed',
|
|
149
|
-
message:
|
|
144
|
+
message: `Are you sure you want to deploy by approving ${approvalJob} at ${revision}?`,
|
|
150
145
|
initial: false,
|
|
151
146
|
active: 'Yes',
|
|
152
147
|
inactive: 'No'
|
|
@@ -163,7 +158,7 @@ async function paginateToDeploymentPipeline(_ref5) {
|
|
|
163
158
|
let nextPageToken;
|
|
164
159
|
// eslint-disable-next-line no-plusplus
|
|
165
160
|
for (let i = 0; i < maxPages; i++) {
|
|
166
|
-
var
|
|
161
|
+
var _context, _context2;
|
|
167
162
|
// eslint-disable-next-line no-await-in-loop
|
|
168
163
|
|
|
169
164
|
const pipelineRequest = circleCiApis.pipelines({
|
|
@@ -174,19 +169,18 @@ async function paginateToDeploymentPipeline(_ref5) {
|
|
|
174
169
|
debug
|
|
175
170
|
});
|
|
176
171
|
nextPageToken = pipelines.next_page_token;
|
|
177
|
-
const nonScheduledPipelines = _filterInstanceProperty(
|
|
172
|
+
const nonScheduledPipelines = _filterInstanceProperty(_context = _filterInstanceProperty(_context2 = pipelines.items).call(_context2, isNonScheduledPipeline)).call(_context, isNonErroredPipeline);
|
|
178
173
|
if (buildRevision) {
|
|
179
|
-
|
|
180
|
-
console.log(_concatInstanceProperty(_context6 = _concatInstanceProperty(_context7 = "\uD83D\uDD04 Trying to find pipeline with revision ".concat(buildRevision, ". Attempt ")).call(_context7, i + 1, " out of ")).call(_context6, maxPages, "."));
|
|
174
|
+
console.log(`🔄 Trying to find pipeline with revision ${buildRevision}. Attempt ${i + 1} out of ${maxPages}.`);
|
|
181
175
|
deploymentPipeline = _findInstanceProperty(nonScheduledPipelines).call(nonScheduledPipelines, pipeline => {
|
|
182
|
-
var
|
|
183
|
-
return _startsWithInstanceProperty(
|
|
176
|
+
var _context3;
|
|
177
|
+
return _startsWithInstanceProperty(_context3 = pipeline.vcs.revision).call(_context3, buildRevision);
|
|
184
178
|
});
|
|
185
179
|
} else {
|
|
186
180
|
deploymentPipeline = nonScheduledPipelines[0];
|
|
187
181
|
}
|
|
188
182
|
if (deploymentPipeline) {
|
|
189
|
-
console.log(
|
|
183
|
+
console.log(`ℹ️ Using pipeline for deployment with revision ${deploymentPipeline.vcs.revision}.`);
|
|
190
184
|
break;
|
|
191
185
|
}
|
|
192
186
|
}
|
|
@@ -201,7 +195,7 @@ async function collectDeploymentPipelines(_ref6) {
|
|
|
201
195
|
let nextPageToken;
|
|
202
196
|
// eslint-disable-next-line no-plusplus
|
|
203
197
|
for (let i = 0; i < pagesForPipelineSelection; i++) {
|
|
204
|
-
var
|
|
198
|
+
var _context4, _context5;
|
|
205
199
|
// eslint-disable-next-line no-await-in-loop
|
|
206
200
|
const pipelinesRequest = circleCiApis.pipelines({
|
|
207
201
|
pageToken: nextPageToken,
|
|
@@ -210,7 +204,7 @@ async function collectDeploymentPipelines(_ref6) {
|
|
|
210
204
|
const pipelines = await pipelinesRequest.execute({
|
|
211
205
|
debug
|
|
212
206
|
});
|
|
213
|
-
const nonScheduledPipelines = _filterInstanceProperty(
|
|
207
|
+
const nonScheduledPipelines = _filterInstanceProperty(_context4 = _filterInstanceProperty(_context5 = pipelines.items).call(_context5, isNonScheduledPipeline)).call(_context4, isNonErroredPipeline);
|
|
214
208
|
deploymentPipelines = _concatInstanceProperty(deploymentPipelines).call(deploymentPipelines, nonScheduledPipelines);
|
|
215
209
|
}
|
|
216
210
|
return deploymentPipelines;
|
|
@@ -249,12 +243,11 @@ async function waitForConfirmationPrompt(_ref8) {
|
|
|
249
243
|
}));
|
|
250
244
|
}
|
|
251
245
|
function getJobUrl(_ref9) {
|
|
252
|
-
var _context11, _context12, _context13;
|
|
253
246
|
let pipelineNumber = _ref9.pipelineNumber,
|
|
254
247
|
workflowId = _ref9.workflowId,
|
|
255
248
|
jobNumber = _ref9.jobNumber,
|
|
256
249
|
projectName = _ref9.projectName;
|
|
257
|
-
return
|
|
250
|
+
return `https://app.circleci.com/pipelines/github/commercetools/${projectName}/${pipelineNumber}/workflows/${workflowId}/jobs/${jobNumber}`;
|
|
258
251
|
}
|
|
259
252
|
function isNonScheduledPipeline(pipeline) {
|
|
260
253
|
return pipeline.trigger.type !== 'schedule' && pipeline.trigger.type !== 'scheduled_pipeline';
|
|
@@ -268,14 +261,14 @@ async function waitForDeploymentJobNumber(_ref10, _ref11) {
|
|
|
268
261
|
circleCiApis = _ref10.circleCiApis;
|
|
269
262
|
let debug = _ref11.debug;
|
|
270
263
|
const fetchDeploymentJobNumber = async () => {
|
|
271
|
-
var
|
|
264
|
+
var _context6;
|
|
272
265
|
const jobsRequest = circleCiApis.jobs({
|
|
273
266
|
workflowId
|
|
274
267
|
});
|
|
275
268
|
const jobs = await jobsRequest.execute({
|
|
276
269
|
debug
|
|
277
270
|
});
|
|
278
|
-
const applicationDeploymentJob = _findInstanceProperty(
|
|
271
|
+
const applicationDeploymentJob = _findInstanceProperty(_context6 = jobs.items).call(_context6, job => job.name === deploymentJob);
|
|
279
272
|
if (!applicationDeploymentJob || applicationDeploymentJob.status === 'blocked') {
|
|
280
273
|
throw new Error('Deployment job not yet running. Retrying.');
|
|
281
274
|
}
|
|
@@ -283,8 +276,7 @@ async function waitForDeploymentJobNumber(_ref10, _ref11) {
|
|
|
283
276
|
};
|
|
284
277
|
const deploymentJobNumber = await pRetry(fetchDeploymentJobNumber, {
|
|
285
278
|
onFailedAttempt: error => {
|
|
286
|
-
|
|
287
|
-
console.log(_concatInstanceProperty(_context15 = "\uD83D\uDD04 Trying to find deployment job. Attempt ".concat(error.attemptNumber, " with ")).call(_context15, error.retriesLeft, " retries left."));
|
|
279
|
+
console.log(`🔄 Trying to find deployment job. Attempt ${error.attemptNumber} with ${error.retriesLeft} retries left.`);
|
|
288
280
|
},
|
|
289
281
|
retries: 10
|
|
290
282
|
});
|
|
@@ -292,65 +284,63 @@ async function waitForDeploymentJobNumber(_ref10, _ref11) {
|
|
|
292
284
|
}
|
|
293
285
|
|
|
294
286
|
async function approve(cliFlags, config, circleCiApis) {
|
|
295
|
-
var
|
|
287
|
+
var _context, _context2;
|
|
296
288
|
let approvalJob;
|
|
297
289
|
let deploymentJob;
|
|
298
290
|
if (cliFlags.deployment) {
|
|
299
|
-
|
|
300
|
-
const requestedDeployment = (_config$deployments = config.deployments) === null || _config$deployments === void 0 ? void 0 : _config$deployments[cliFlags.deployment];
|
|
291
|
+
const requestedDeployment = config.deployments?.[cliFlags.deployment];
|
|
301
292
|
if (!requestedDeployment) {
|
|
302
|
-
throw new Error(
|
|
293
|
+
throw new Error(`⚠️ Deployment ${cliFlags.deployment} not found in configuration. Make sure it exists.`);
|
|
303
294
|
}
|
|
304
295
|
approvalJob = requestedDeployment.jobs.approval;
|
|
305
296
|
deploymentJob = requestedDeployment.jobs.deployment;
|
|
306
|
-
console.log(
|
|
297
|
+
console.log(`ℹ️ Approving requested deployment ${cliFlags.deployment} with approval job ${approvalJob}.`);
|
|
307
298
|
} else {
|
|
308
299
|
approvalJob = cliFlags.approvalJob;
|
|
309
300
|
deploymentJob = cliFlags.deploymentJob;
|
|
310
|
-
console.log(
|
|
301
|
+
console.log(`ℹ️ Approving with approval job ${approvalJob}.`);
|
|
311
302
|
}
|
|
312
303
|
const deploymentPipeline = cliFlags.yes ? await paginateToDeploymentPipeline({
|
|
313
304
|
circleCiApis,
|
|
314
305
|
buildRevision: cliFlags.buildRevision,
|
|
315
306
|
branch: cliFlags.branch,
|
|
316
307
|
debug: cliFlags.debug,
|
|
317
|
-
maxPages:
|
|
308
|
+
maxPages: config.CircleCI.pagination?.maxPages ?? 1
|
|
318
309
|
}) : await waitForDeploymentPipelinePrompt({
|
|
319
310
|
branch: cliFlags.branch,
|
|
320
311
|
circleCiApis,
|
|
321
|
-
pagesForPipelineSelection:
|
|
312
|
+
pagesForPipelineSelection: config.CircleCI.pagination?.pagesForPipelineSelection ?? 1,
|
|
322
313
|
debug: cliFlags.debug
|
|
323
314
|
});
|
|
324
315
|
if (!deploymentPipeline) {
|
|
325
|
-
throw new Error(
|
|
316
|
+
throw new Error(`⚠️ No workflow called ${config.CircleCI.deploymentWorkflowName} found in any pipeline for deployment.`);
|
|
326
317
|
}
|
|
327
|
-
console.log(
|
|
318
|
+
console.log(`ℹ️ Found pipeline for deployment with revision ${deploymentPipeline.vcs.revision}.`);
|
|
328
319
|
const workflowsRequest = circleCiApis.workflows({
|
|
329
320
|
pipelineId: deploymentPipeline.id
|
|
330
321
|
});
|
|
331
322
|
const workflows = await workflowsRequest.execute({
|
|
332
323
|
debug: cliFlags.debug
|
|
333
324
|
});
|
|
334
|
-
const buildAndDeployWorkflow = _findInstanceProperty(
|
|
325
|
+
const buildAndDeployWorkflow = _findInstanceProperty(_context = workflows.items).call(_context, workflow => workflow.name === config.CircleCI.deploymentWorkflowName);
|
|
335
326
|
if (!buildAndDeployWorkflow) {
|
|
336
|
-
throw new Error(
|
|
327
|
+
throw new Error(`⚠️ No workflow called ${config.CircleCI.deploymentWorkflowName} found for deployment.`);
|
|
337
328
|
}
|
|
338
329
|
const workflowId = buildAndDeployWorkflow.id;
|
|
339
|
-
console.log(
|
|
330
|
+
console.log(`ℹ️ Found workflow to build and deploy with id ${workflowId}.`);
|
|
340
331
|
const jobsRequest = circleCiApis.jobs({
|
|
341
332
|
workflowId
|
|
342
333
|
});
|
|
343
334
|
const jobs = await jobsRequest.execute({
|
|
344
335
|
debug: cliFlags.debug
|
|
345
336
|
});
|
|
346
|
-
console.log(
|
|
347
|
-
const applicationApprovalJob = _findInstanceProperty(
|
|
348
|
-
const applicationApprovalJobId = applicationApprovalJob
|
|
337
|
+
console.log(`ℹ️ Found jobs for workflow.`);
|
|
338
|
+
const applicationApprovalJob = _findInstanceProperty(_context2 = jobs.items).call(_context2, job => job.name === approvalJob);
|
|
339
|
+
const applicationApprovalJobId = applicationApprovalJob?.id;
|
|
349
340
|
if (!applicationApprovalJobId) {
|
|
350
|
-
|
|
351
|
-
throw new Error(_concatInstanceProperty(_context4 = "\u270C\uFE0F Could not find deployment approval job named ".concat(approvalJob, " at revision ")).call(_context4, deploymentPipeline.vcs.revision, ". Maybe try again later."));
|
|
341
|
+
throw new Error(`✌️ Could not find deployment approval job named ${approvalJob} at revision ${deploymentPipeline.vcs.revision}. Maybe try again later.`);
|
|
352
342
|
}
|
|
353
|
-
console.log(
|
|
343
|
+
console.log(`ℹ️ Found deployment approval job named ${approvalJob} with id ${applicationApprovalJobId}.`);
|
|
354
344
|
let confirmationPrompt;
|
|
355
345
|
if (!cliFlags.yes) {
|
|
356
346
|
confirmationPrompt = await waitForConfirmationPrompt({
|
|
@@ -358,11 +348,11 @@ async function approve(cliFlags, config, circleCiApis) {
|
|
|
358
348
|
revision: deploymentPipeline.vcs.revision
|
|
359
349
|
});
|
|
360
350
|
}
|
|
361
|
-
if (cliFlags.yes ||
|
|
351
|
+
if (cliFlags.yes || confirmationPrompt?.confirmed) {
|
|
362
352
|
if (cliFlags.dryRun) {
|
|
363
|
-
console.log(
|
|
353
|
+
console.log(`🙊 Not approving deployment job due to dry run.`);
|
|
364
354
|
} else {
|
|
365
|
-
console.log(
|
|
355
|
+
console.log(`ℹ️ Approving deployment job.`);
|
|
366
356
|
}
|
|
367
357
|
const approvalRequest = circleCiApis.approve({
|
|
368
358
|
workflowId,
|
|
@@ -373,11 +363,10 @@ async function approve(cliFlags, config, circleCiApis) {
|
|
|
373
363
|
skip: cliFlags.dryRun
|
|
374
364
|
});
|
|
375
365
|
if (cliFlags.yes) {
|
|
376
|
-
console.log(
|
|
366
|
+
console.log(`ℹ️ Skipping determining deployment job approved by ${approvalJob} due to '--yes' flag. Please check CircleCI manually.`);
|
|
377
367
|
} else if (cliFlags.dryRun) {
|
|
378
|
-
console.log(
|
|
368
|
+
console.log(`✌️ Dry running hence could not determine deployment job approved by ${approvalJob}.`);
|
|
379
369
|
} else if (deploymentJob) {
|
|
380
|
-
var _context6, _context7;
|
|
381
370
|
const deploymentJobNumber = await waitForDeploymentJobNumber({
|
|
382
371
|
workflowId,
|
|
383
372
|
deploymentJob,
|
|
@@ -387,23 +376,22 @@ async function approve(cliFlags, config, circleCiApis) {
|
|
|
387
376
|
dryRun: cliFlags.dryRun,
|
|
388
377
|
yes: cliFlags.yes
|
|
389
378
|
});
|
|
390
|
-
console.log(
|
|
379
|
+
console.log(`🙌 The deployment via ${approvalJob} at revision ${deploymentPipeline.vcs.revision} is running at: ${getJobUrl({
|
|
391
380
|
projectName: config.CircleCI.projectName,
|
|
392
381
|
pipelineNumber: deploymentPipeline.number,
|
|
393
382
|
workflowId,
|
|
394
383
|
jobNumber: deploymentJobNumber
|
|
395
|
-
}))
|
|
384
|
+
})}`);
|
|
396
385
|
} else {
|
|
397
|
-
console.log(
|
|
386
|
+
console.log(`ℹ️ Skipping determining deployment job as no '--deployment-job' name to wait for was passed. Please check CircleCI manually.`);
|
|
398
387
|
}
|
|
399
388
|
} else {
|
|
400
|
-
console.log(
|
|
389
|
+
console.log(`ℹ️ Not approving deployment job. Confirm the prompt or use '--yes' option.`);
|
|
401
390
|
}
|
|
402
391
|
}
|
|
403
392
|
|
|
404
393
|
async function processCircleCiResponse(response) {
|
|
405
394
|
if (!response.ok) {
|
|
406
|
-
var _context, _context2;
|
|
407
395
|
/**
|
|
408
396
|
* NOTE:
|
|
409
397
|
* Trying to handle known but undocumented responses of the CircleCI API.
|
|
@@ -428,7 +416,8 @@ async function processCircleCiResponse(response) {
|
|
|
428
416
|
} catch {
|
|
429
417
|
// Ignore JSON parsing errors
|
|
430
418
|
}
|
|
431
|
-
throw new Error(
|
|
419
|
+
throw new Error(`${response.status}: Network response was not ok.\n
|
|
420
|
+
Status text is ${response.statusText} and text is ${error}.`);
|
|
432
421
|
}
|
|
433
422
|
return response.json();
|
|
434
423
|
}
|
|
@@ -436,11 +425,10 @@ function createCircleCiClient(_ref) {
|
|
|
436
425
|
let projectName = _ref.projectName,
|
|
437
426
|
apiBaseUrl = _ref.apiBaseUrl;
|
|
438
427
|
async function execute(api) {
|
|
439
|
-
var _context3;
|
|
440
428
|
let _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
441
429
|
skip = _ref2.skip,
|
|
442
430
|
debug = _ref2.debug;
|
|
443
|
-
let url =
|
|
431
|
+
let url = `${apiBaseUrl}${api.url}`;
|
|
444
432
|
if (api.params && api.method === 'GET') {
|
|
445
433
|
const urlSearchParams = new _URLSearchParams();
|
|
446
434
|
for (const _ref3 of _Object$entries(api.params)) {
|
|
@@ -451,18 +439,18 @@ function createCircleCiClient(_ref) {
|
|
|
451
439
|
urlSearchParams.append(key, value);
|
|
452
440
|
}
|
|
453
441
|
}
|
|
454
|
-
url +=
|
|
442
|
+
url += `?${urlSearchParams.toString()}`;
|
|
455
443
|
}
|
|
456
444
|
if (skip) {
|
|
457
445
|
if (debug) {
|
|
458
|
-
console.log(
|
|
446
|
+
console.log(`🏭 Skipping CircleCI call API at: ${url}.`);
|
|
459
447
|
}
|
|
460
448
|
|
|
461
449
|
// @ts-expect-error
|
|
462
450
|
return _Promise.resolve();
|
|
463
451
|
}
|
|
464
452
|
if (debug) {
|
|
465
|
-
console.log(
|
|
453
|
+
console.log(`🏭 Calling CircleCI API at: ${url}.`);
|
|
466
454
|
}
|
|
467
455
|
try {
|
|
468
456
|
const response = await fetch(url, {
|
|
@@ -473,7 +461,7 @@ function createCircleCiClient(_ref) {
|
|
|
473
461
|
const processedCircleCiResponse = await processCircleCiResponse(response);
|
|
474
462
|
return processedCircleCiResponse;
|
|
475
463
|
} catch (error) {
|
|
476
|
-
console.log(
|
|
464
|
+
console.log(`⚠️ Calling CircleCI API at: ${url} failed.`);
|
|
477
465
|
throw error;
|
|
478
466
|
}
|
|
479
467
|
}
|
|
@@ -482,12 +470,12 @@ function createCircleCiClient(_ref) {
|
|
|
482
470
|
let _ref5 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
483
471
|
pageToken = _ref5.pageToken,
|
|
484
472
|
_ref5$projectSlug = _ref5.projectSlug,
|
|
485
|
-
projectSlug = _ref5$projectSlug === void 0 ?
|
|
473
|
+
projectSlug = _ref5$projectSlug === void 0 ? `gh/commercetools/${projectName}` : _ref5$projectSlug,
|
|
486
474
|
_ref5$branch = _ref5.branch,
|
|
487
475
|
branch = _ref5$branch === void 0 ? 'main' : _ref5$branch;
|
|
488
476
|
return {
|
|
489
477
|
execute: options => execute({
|
|
490
|
-
url:
|
|
478
|
+
url: `/project/${projectSlug}/pipeline`,
|
|
491
479
|
headers: {
|
|
492
480
|
'Content-Type': 'application/json',
|
|
493
481
|
// The CLI throws if this is not present on environment
|
|
@@ -505,7 +493,7 @@ function createCircleCiClient(_ref) {
|
|
|
505
493
|
let pipelineId = _ref6.pipelineId;
|
|
506
494
|
return {
|
|
507
495
|
execute: options => execute({
|
|
508
|
-
url:
|
|
496
|
+
url: `/pipeline/${pipelineId}/workflow`,
|
|
509
497
|
headers: {
|
|
510
498
|
'Content-Type': 'application/json',
|
|
511
499
|
// The CLI throws if this is not present on environment
|
|
@@ -519,7 +507,7 @@ function createCircleCiClient(_ref) {
|
|
|
519
507
|
let workflowId = _ref7.workflowId;
|
|
520
508
|
return {
|
|
521
509
|
execute: options => execute({
|
|
522
|
-
url:
|
|
510
|
+
url: `/workflow/${workflowId}/job`,
|
|
523
511
|
headers: {
|
|
524
512
|
'Content-Type': 'application/json',
|
|
525
513
|
// The CLI throws if this is not present on environment
|
|
@@ -533,18 +521,15 @@ function createCircleCiClient(_ref) {
|
|
|
533
521
|
let workflowId = _ref8.workflowId,
|
|
534
522
|
approvalRequestId = _ref8.approvalRequestId;
|
|
535
523
|
return {
|
|
536
|
-
execute: options => {
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
method: 'POST'
|
|
546
|
-
}, options);
|
|
547
|
-
}
|
|
524
|
+
execute: options => execute({
|
|
525
|
+
url: `/workflow/${workflowId}/approve/${approvalRequestId} `,
|
|
526
|
+
headers: {
|
|
527
|
+
'Content-Type': 'application/json',
|
|
528
|
+
// The CLI throws if this is not present on environment
|
|
529
|
+
'Circle-Token': process.env.CIRCLE_TOKEN
|
|
530
|
+
},
|
|
531
|
+
method: 'POST'
|
|
532
|
+
}, options)
|
|
548
533
|
};
|
|
549
534
|
}
|
|
550
535
|
};
|
|
@@ -572,13 +557,13 @@ async function run() {
|
|
|
572
557
|
|
|
573
558
|
// Command: Approve
|
|
574
559
|
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/).';
|
|
575
|
-
cli.command('approve', usageApprove).usage(
|
|
560
|
+
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.', {
|
|
576
561
|
default: 'main'
|
|
577
562
|
}).option('--yes', '(optional) Skip all confirmation prompts. Useful in Continuous integration (CI) to automatically answer confirmation questions.', {
|
|
578
563
|
default: false
|
|
579
564
|
}).action(async options => {
|
|
580
565
|
if (options.dryRun) {
|
|
581
|
-
console.log(
|
|
566
|
+
console.log(`🙊 Do not worry. This is a dry run!`);
|
|
582
567
|
}
|
|
583
568
|
throwIfRequiredEnvironmentVariableIsUnset(['CIRCLE_TOKEN']);
|
|
584
569
|
await approve(options, config, circleCiApis);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from "./declarations/src/index";
|
|
2
|
-
//# sourceMappingURL=
|
|
2
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29tbWVyY2V0b29scy1mcm9udGVuZC1kZXBsb3ltZW50LWNsaS5janMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4vZGVjbGFyYXRpb25zL3NyYy9pbmRleC5kLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBIn0=
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools-frontend/deployment-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "CLI to manage Custom Applications deployments in Google Storage.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"commercetools",
|
|
@@ -23,23 +23,21 @@
|
|
|
23
23
|
"@babel/runtime": "^7.21.0",
|
|
24
24
|
"@babel/runtime-corejs3": "^7.21.0",
|
|
25
25
|
"cac": "^6.7.14",
|
|
26
|
-
"cosmiconfig": "
|
|
26
|
+
"cosmiconfig": "9.0.0",
|
|
27
27
|
"lodash": "4.17.21",
|
|
28
|
-
"node-fetch": "2.7.0",
|
|
29
28
|
"p-retry": "4.6.2",
|
|
30
29
|
"prompts": "2.4.2"
|
|
31
30
|
},
|
|
32
31
|
"devDependencies": {
|
|
33
32
|
"@tsconfig/node20": "20.1.2",
|
|
34
33
|
"@types/lodash": "^4.14.198",
|
|
35
|
-
"@types/node": "20.
|
|
36
|
-
"@types/
|
|
37
|
-
"@types/prompts": "2.4.5",
|
|
34
|
+
"@types/node": "20.11.5",
|
|
35
|
+
"@types/prompts": "2.4.9",
|
|
38
36
|
"msw": "1.3.2",
|
|
39
37
|
"typescript": "5.2.2"
|
|
40
38
|
},
|
|
41
39
|
"engines": {
|
|
42
|
-
"node": ">=
|
|
40
|
+
"node": ">=18",
|
|
43
41
|
"npm": ">=6"
|
|
44
42
|
},
|
|
45
43
|
"publishConfig": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"commercetools-frontend-deployment-cli-cli.cjs.d.ts","sourceRoot":"","sources":["../../dist/declarations/src/cli.d.ts"],"names":[],"mappings":"AAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"commercetools-frontend-deployment-cli.cjs.d.ts","sourceRoot":"","sources":["./declarations/src/index.d.ts"],"names":[],"mappings":"AAAA"}
|