@commercetools-frontend/deployment-cli 0.0.4 → 0.0.5

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.
@@ -26,37 +26,35 @@ function _loadConfig() {
26
26
  _loadConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
27
27
  var deploymentConfigExplorer, defaultConfig, cosmiconfigResult, mergedConfig;
28
28
  return _regeneratorRuntime.wrap(function _callee$(_context7) {
29
- while (1) {
30
- switch (_context7.prev = _context7.next) {
31
- case 0:
32
- deploymentConfigExplorer = cosmiconfig('deployment');
33
- defaultConfig = {
34
- CircleCI: {
35
- apiBaseUrl: 'https://circleci.com/api/v2',
36
- deploymentWorkflowName: 'test_build_and_deploy',
37
- pagination: {
38
- maxPages: 42,
39
- pagesForPipelineSelection: 5
40
- }
41
- },
42
- MerchantCenter: {}
43
- };
44
- _context7.prev = 2;
45
- _context7.next = 5;
46
- return deploymentConfigExplorer.search();
47
- case 5:
48
- cosmiconfigResult = _context7.sent;
49
- mergedConfig = merge(defaultConfig, cosmiconfigResult === null || cosmiconfigResult === void 0 ? void 0 : cosmiconfigResult.config);
50
- return _context7.abrupt("return", mergedConfig);
51
- case 10:
52
- _context7.prev = 10;
53
- _context7.t0 = _context7["catch"](2);
54
- console.warn(_context7.t0);
55
- throw new Error('Failed loading a deployment configuration. Create a cosmiconfig for `deployment` for example `deployment.config.cjs`.');
56
- case 14:
57
- case "end":
58
- return _context7.stop();
59
- }
29
+ while (1) switch (_context7.prev = _context7.next) {
30
+ case 0:
31
+ deploymentConfigExplorer = cosmiconfig('deployment');
32
+ defaultConfig = {
33
+ CircleCI: {
34
+ apiBaseUrl: 'https://circleci.com/api/v2',
35
+ deploymentWorkflowName: 'test_build_and_deploy',
36
+ pagination: {
37
+ maxPages: 42,
38
+ pagesForPipelineSelection: 5
39
+ }
40
+ },
41
+ MerchantCenter: {}
42
+ };
43
+ _context7.prev = 2;
44
+ _context7.next = 5;
45
+ return deploymentConfigExplorer.search();
46
+ case 5:
47
+ cosmiconfigResult = _context7.sent;
48
+ mergedConfig = merge(defaultConfig, cosmiconfigResult === null || cosmiconfigResult === void 0 ? void 0 : cosmiconfigResult.config);
49
+ return _context7.abrupt("return", mergedConfig);
50
+ case 10:
51
+ _context7.prev = 10;
52
+ _context7.t0 = _context7["catch"](2);
53
+ console.warn(_context7.t0);
54
+ throw new Error('Failed loading a deployment configuration. Create a cosmiconfig for `deployment` for example `deployment.config.cjs`.');
55
+ case 14:
56
+ case "end":
57
+ return _context7.stop();
60
58
  }
61
59
  }, _callee, null, [[2, 10]]);
62
60
  }));
@@ -126,54 +124,52 @@ function _paginateToDeploymentPipeline() {
126
124
  _paginateToDeploymentPipeline = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref5) {
127
125
  var circleCiApis, buildRevision, branch, debug, maxPages, deploymentPipeline, nextPageToken, i, _context8, _context9, pipelineRequest, pipelines, nonScheduledPipelines, _context10, _context11;
128
126
  return _regeneratorRuntime.wrap(function _callee2$(_context13) {
129
- while (1) {
130
- switch (_context13.prev = _context13.next) {
131
- case 0:
132
- circleCiApis = _ref5.circleCiApis, buildRevision = _ref5.buildRevision, branch = _ref5.branch, debug = _ref5.debug, maxPages = _ref5.maxPages;
133
- i = 0;
134
- case 2:
135
- if (!(i < maxPages)) {
136
- _context13.next = 16;
137
- break;
138
- }
139
- // eslint-disable-next-line no-await-in-loop
140
- pipelineRequest = circleCiApis.pipelines({
141
- pageToken: nextPageToken,
142
- branch: branch
143
- });
144
- _context13.next = 6;
145
- return pipelineRequest.execute({
146
- debug: debug
127
+ while (1) switch (_context13.prev = _context13.next) {
128
+ case 0:
129
+ circleCiApis = _ref5.circleCiApis, buildRevision = _ref5.buildRevision, branch = _ref5.branch, debug = _ref5.debug, maxPages = _ref5.maxPages;
130
+ i = 0;
131
+ case 2:
132
+ if (!(i < maxPages)) {
133
+ _context13.next = 16;
134
+ break;
135
+ }
136
+ // eslint-disable-next-line no-await-in-loop
137
+ pipelineRequest = circleCiApis.pipelines({
138
+ pageToken: nextPageToken,
139
+ branch: branch
140
+ });
141
+ _context13.next = 6;
142
+ return pipelineRequest.execute({
143
+ debug: debug
144
+ });
145
+ case 6:
146
+ pipelines = _context13.sent;
147
+ nextPageToken = pipelines.next_page_token;
148
+ nonScheduledPipelines = _filterInstanceProperty(_context8 = _filterInstanceProperty(_context9 = pipelines.items).call(_context9, isNonScheduledPipeline)).call(_context8, isNonErroredPipeline);
149
+ if (buildRevision) {
150
+ console.log(_concatInstanceProperty(_context10 = _concatInstanceProperty(_context11 = "\uD83D\uDD04 Trying to find pipeline with revision ".concat(buildRevision, ". Attempt ")).call(_context11, i + 1, " out of ")).call(_context10, maxPages, "."));
151
+ deploymentPipeline = _findInstanceProperty(nonScheduledPipelines).call(nonScheduledPipelines, function (pipeline) {
152
+ var _context12;
153
+ return _startsWithInstanceProperty(_context12 = pipeline.vcs.revision).call(_context12, buildRevision);
147
154
  });
148
- case 6:
149
- pipelines = _context13.sent;
150
- nextPageToken = pipelines.next_page_token;
151
- nonScheduledPipelines = _filterInstanceProperty(_context8 = _filterInstanceProperty(_context9 = pipelines.items).call(_context9, isNonScheduledPipeline)).call(_context8, isNonErroredPipeline);
152
- if (buildRevision) {
153
- console.log(_concatInstanceProperty(_context10 = _concatInstanceProperty(_context11 = "\uD83D\uDD04 Trying to find pipeline with revision ".concat(buildRevision, ". Attempt ")).call(_context11, i + 1, " out of ")).call(_context10, maxPages, "."));
154
- deploymentPipeline = _findInstanceProperty(nonScheduledPipelines).call(nonScheduledPipelines, function (pipeline) {
155
- var _context12;
156
- return _startsWithInstanceProperty(_context12 = pipeline.vcs.revision).call(_context12, buildRevision);
157
- });
158
- } else {
159
- deploymentPipeline = nonScheduledPipelines[0];
160
- }
161
- if (!deploymentPipeline) {
162
- _context13.next = 13;
163
- break;
164
- }
165
- console.log("\u2139\uFE0F Using pipeline for deployment with revision ".concat(deploymentPipeline.vcs.revision, "."));
166
- return _context13.abrupt("break", 16);
167
- case 13:
168
- i++;
169
- _context13.next = 2;
155
+ } else {
156
+ deploymentPipeline = nonScheduledPipelines[0];
157
+ }
158
+ if (!deploymentPipeline) {
159
+ _context13.next = 13;
170
160
  break;
171
- case 16:
172
- return _context13.abrupt("return", deploymentPipeline);
173
- case 17:
174
- case "end":
175
- return _context13.stop();
176
- }
161
+ }
162
+ console.log("\u2139\uFE0F Using pipeline for deployment with revision ".concat(deploymentPipeline.vcs.revision, "."));
163
+ return _context13.abrupt("break", 16);
164
+ case 13:
165
+ i++;
166
+ _context13.next = 2;
167
+ break;
168
+ case 16:
169
+ return _context13.abrupt("return", deploymentPipeline);
170
+ case 17:
171
+ case "end":
172
+ return _context13.stop();
177
173
  }
178
174
  }, _callee2);
179
175
  }));
@@ -186,40 +182,38 @@ function _collectDeploymentPipelines() {
186
182
  _collectDeploymentPipelines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref6) {
187
183
  var circleCiApis, branch, pagesForPipelineSelection, debug, deploymentPipelines, nextPageToken, i, _context14, _context15, pipelinesRequest, pipelines, nonScheduledPipelines;
188
184
  return _regeneratorRuntime.wrap(function _callee3$(_context16) {
189
- while (1) {
190
- switch (_context16.prev = _context16.next) {
191
- case 0:
192
- circleCiApis = _ref6.circleCiApis, branch = _ref6.branch, pagesForPipelineSelection = _ref6.pagesForPipelineSelection, debug = _ref6.debug;
193
- deploymentPipelines = [];
194
- i = 0;
195
- case 3:
196
- if (!(i < pagesForPipelineSelection)) {
197
- _context16.next = 13;
198
- break;
199
- }
200
- // eslint-disable-next-line no-await-in-loop
201
- pipelinesRequest = circleCiApis.pipelines({
202
- pageToken: nextPageToken,
203
- branch: branch
204
- });
205
- _context16.next = 7;
206
- return pipelinesRequest.execute({
207
- debug: debug
208
- });
209
- case 7:
210
- pipelines = _context16.sent;
211
- nonScheduledPipelines = _filterInstanceProperty(_context14 = _filterInstanceProperty(_context15 = pipelines.items).call(_context15, isNonScheduledPipeline)).call(_context14, isNonErroredPipeline);
212
- deploymentPipelines = _concatInstanceProperty(deploymentPipelines).call(deploymentPipelines, nonScheduledPipelines);
213
- case 10:
214
- i++;
215
- _context16.next = 3;
185
+ while (1) switch (_context16.prev = _context16.next) {
186
+ case 0:
187
+ circleCiApis = _ref6.circleCiApis, branch = _ref6.branch, pagesForPipelineSelection = _ref6.pagesForPipelineSelection, debug = _ref6.debug;
188
+ deploymentPipelines = [];
189
+ i = 0;
190
+ case 3:
191
+ if (!(i < pagesForPipelineSelection)) {
192
+ _context16.next = 13;
216
193
  break;
217
- case 13:
218
- return _context16.abrupt("return", deploymentPipelines);
219
- case 14:
220
- case "end":
221
- return _context16.stop();
222
- }
194
+ }
195
+ // eslint-disable-next-line no-await-in-loop
196
+ pipelinesRequest = circleCiApis.pipelines({
197
+ pageToken: nextPageToken,
198
+ branch: branch
199
+ });
200
+ _context16.next = 7;
201
+ return pipelinesRequest.execute({
202
+ debug: debug
203
+ });
204
+ case 7:
205
+ pipelines = _context16.sent;
206
+ nonScheduledPipelines = _filterInstanceProperty(_context14 = _filterInstanceProperty(_context15 = pipelines.items).call(_context15, isNonScheduledPipeline)).call(_context14, isNonErroredPipeline);
207
+ deploymentPipelines = _concatInstanceProperty(deploymentPipelines).call(deploymentPipelines, nonScheduledPipelines);
208
+ case 10:
209
+ i++;
210
+ _context16.next = 3;
211
+ break;
212
+ case 13:
213
+ return _context16.abrupt("return", deploymentPipelines);
214
+ case 14:
215
+ case "end":
216
+ return _context16.stop();
223
217
  }
224
218
  }, _callee3);
225
219
  }));
@@ -232,40 +226,38 @@ function _waitForDeploymentPipelinePrompt() {
232
226
  _waitForDeploymentPipelinePrompt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref7) {
233
227
  var circleCiApis, branch, pagesForPipelineSelection, debug, deploymentPipelines, deploymentPipelinePrompt, revision;
234
228
  return _regeneratorRuntime.wrap(function _callee4$(_context17) {
235
- while (1) {
236
- switch (_context17.prev = _context17.next) {
237
- case 0:
238
- circleCiApis = _ref7.circleCiApis, branch = _ref7.branch, pagesForPipelineSelection = _ref7.pagesForPipelineSelection, debug = _ref7.debug;
239
- _context17.next = 3;
240
- return collectDeploymentPipelines({
241
- branch: branch,
242
- pagesForPipelineSelection: pagesForPipelineSelection,
243
- circleCiApis: circleCiApis,
244
- debug: debug
245
- });
246
- case 3:
247
- deploymentPipelines = _context17.sent;
248
- _context17.next = 6;
249
- return prompts(
250
- // @ts-expect-error prompts is not typed
251
- promptOptions.deploymentPipelineSelect({
252
- deploymentPipelines: deploymentPipelines
253
- }));
254
- case 6:
255
- deploymentPipelinePrompt = _context17.sent;
256
- revision = deploymentPipelinePrompt.deploymentPipeline.vcs.revision;
257
- if (revision) {
258
- _context17.next = 11;
259
- break;
260
- }
261
- console.log('☝️ Please select a revision or specify it as a CLI argument via `--build-revision`.');
262
- throw new Error('No revision specified.');
263
- case 11:
264
- return _context17.abrupt("return", deploymentPipelinePrompt.deploymentPipeline);
265
- case 12:
266
- case "end":
267
- return _context17.stop();
268
- }
229
+ while (1) switch (_context17.prev = _context17.next) {
230
+ case 0:
231
+ circleCiApis = _ref7.circleCiApis, branch = _ref7.branch, pagesForPipelineSelection = _ref7.pagesForPipelineSelection, debug = _ref7.debug;
232
+ _context17.next = 3;
233
+ return collectDeploymentPipelines({
234
+ branch: branch,
235
+ pagesForPipelineSelection: pagesForPipelineSelection,
236
+ circleCiApis: circleCiApis,
237
+ debug: debug
238
+ });
239
+ case 3:
240
+ deploymentPipelines = _context17.sent;
241
+ _context17.next = 6;
242
+ return prompts(
243
+ // @ts-expect-error prompts is not typed
244
+ promptOptions.deploymentPipelineSelect({
245
+ deploymentPipelines: deploymentPipelines
246
+ }));
247
+ case 6:
248
+ deploymentPipelinePrompt = _context17.sent;
249
+ revision = deploymentPipelinePrompt.deploymentPipeline.vcs.revision;
250
+ if (revision) {
251
+ _context17.next = 11;
252
+ break;
253
+ }
254
+ console.log('☝️ Please select a revision or specify it as a CLI argument via `--build-revision`.');
255
+ throw new Error('No revision specified.');
256
+ case 11:
257
+ return _context17.abrupt("return", deploymentPipelinePrompt.deploymentPipeline);
258
+ case 12:
259
+ case "end":
260
+ return _context17.stop();
269
261
  }
270
262
  }, _callee4);
271
263
  }));
@@ -278,20 +270,18 @@ function _waitForConfirmationPrompt() {
278
270
  _waitForConfirmationPrompt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(_ref8) {
279
271
  var approvalJob, revision;
280
272
  return _regeneratorRuntime.wrap(function _callee5$(_context18) {
281
- while (1) {
282
- switch (_context18.prev = _context18.next) {
283
- case 0:
284
- approvalJob = _ref8.approvalJob, revision = _ref8.revision;
285
- return _context18.abrupt("return", prompts(
286
- // @ts-expect-error prompts is not typed
287
- promptOptions.deploymentConfirmation({
288
- approvalJob: approvalJob,
289
- revision: revision
290
- })));
291
- case 2:
292
- case "end":
293
- return _context18.stop();
294
- }
273
+ while (1) switch (_context18.prev = _context18.next) {
274
+ case 0:
275
+ approvalJob = _ref8.approvalJob, revision = _ref8.revision;
276
+ return _context18.abrupt("return", prompts(
277
+ // @ts-expect-error prompts is not typed
278
+ promptOptions.deploymentConfirmation({
279
+ approvalJob: approvalJob,
280
+ revision: revision
281
+ })));
282
+ case 2:
283
+ case "end":
284
+ return _context18.stop();
295
285
  }
296
286
  }, _callee5);
297
287
  }));
@@ -318,64 +308,60 @@ function _waitForDeploymentJobNumber() {
318
308
  _waitForDeploymentJobNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(_ref10, _ref11) {
319
309
  var workflowId, deploymentJob, circleCiApis, debug, fetchDeploymentJobNumber, deploymentJobNumber;
320
310
  return _regeneratorRuntime.wrap(function _callee7$(_context22) {
321
- while (1) {
322
- switch (_context22.prev = _context22.next) {
323
- case 0:
324
- workflowId = _ref10.workflowId, deploymentJob = _ref10.deploymentJob, circleCiApis = _ref10.circleCiApis;
325
- debug = _ref11.debug;
326
- fetchDeploymentJobNumber = /*#__PURE__*/function () {
327
- var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
328
- var _context19;
329
- var jobsRequest, jobs, applicationDeploymentJob;
330
- return _regeneratorRuntime.wrap(function _callee6$(_context20) {
331
- while (1) {
332
- switch (_context20.prev = _context20.next) {
333
- case 0:
334
- jobsRequest = circleCiApis.jobs({
335
- workflowId: workflowId
336
- });
337
- _context20.next = 3;
338
- return jobsRequest.execute({
339
- debug: debug
340
- });
341
- case 3:
342
- jobs = _context20.sent;
343
- applicationDeploymentJob = _findInstanceProperty(_context19 = jobs.items).call(_context19, function (job) {
344
- return job.name === deploymentJob;
345
- });
346
- if (!(!applicationDeploymentJob || applicationDeploymentJob.status === 'blocked')) {
347
- _context20.next = 7;
348
- break;
349
- }
350
- throw new Error('Deployment job not yet running. Retrying.');
351
- case 7:
352
- return _context20.abrupt("return", applicationDeploymentJob.job_number);
353
- case 8:
354
- case "end":
355
- return _context20.stop();
311
+ while (1) switch (_context22.prev = _context22.next) {
312
+ case 0:
313
+ workflowId = _ref10.workflowId, deploymentJob = _ref10.deploymentJob, circleCiApis = _ref10.circleCiApis;
314
+ debug = _ref11.debug;
315
+ fetchDeploymentJobNumber = /*#__PURE__*/function () {
316
+ var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
317
+ var _context19;
318
+ var jobsRequest, jobs, applicationDeploymentJob;
319
+ return _regeneratorRuntime.wrap(function _callee6$(_context20) {
320
+ while (1) switch (_context20.prev = _context20.next) {
321
+ case 0:
322
+ jobsRequest = circleCiApis.jobs({
323
+ workflowId: workflowId
324
+ });
325
+ _context20.next = 3;
326
+ return jobsRequest.execute({
327
+ debug: debug
328
+ });
329
+ case 3:
330
+ jobs = _context20.sent;
331
+ applicationDeploymentJob = _findInstanceProperty(_context19 = jobs.items).call(_context19, function (job) {
332
+ return job.name === deploymentJob;
333
+ });
334
+ if (!(!applicationDeploymentJob || applicationDeploymentJob.status === 'blocked')) {
335
+ _context20.next = 7;
336
+ break;
356
337
  }
357
- }
358
- }, _callee6);
359
- }));
360
- return function fetchDeploymentJobNumber() {
361
- return _ref12.apply(this, arguments);
362
- };
363
- }();
364
- _context22.next = 5;
365
- return pRetry(fetchDeploymentJobNumber, {
366
- onFailedAttempt: function onFailedAttempt(error) {
367
- var _context21;
368
- console.log(_concatInstanceProperty(_context21 = "\uD83D\uDD04 Trying to find deployment job. Attempt ".concat(error.attemptNumber, " with ")).call(_context21, error.retriesLeft, " retries left."));
369
- },
370
- retries: 10
371
- });
372
- case 5:
373
- deploymentJobNumber = _context22.sent;
374
- return _context22.abrupt("return", deploymentJobNumber);
375
- case 7:
376
- case "end":
377
- return _context22.stop();
378
- }
338
+ throw new Error('Deployment job not yet running. Retrying.');
339
+ case 7:
340
+ return _context20.abrupt("return", applicationDeploymentJob.job_number);
341
+ case 8:
342
+ case "end":
343
+ return _context20.stop();
344
+ }
345
+ }, _callee6);
346
+ }));
347
+ return function fetchDeploymentJobNumber() {
348
+ return _ref12.apply(this, arguments);
349
+ };
350
+ }();
351
+ _context22.next = 5;
352
+ return pRetry(fetchDeploymentJobNumber, {
353
+ onFailedAttempt: function onFailedAttempt(error) {
354
+ var _context21;
355
+ console.log(_concatInstanceProperty(_context21 = "\uD83D\uDD04 Trying to find deployment job. Attempt ".concat(error.attemptNumber, " with ")).call(_context21, error.retriesLeft, " retries left."));
356
+ },
357
+ retries: 10
358
+ });
359
+ case 5:
360
+ deploymentJobNumber = _context22.sent;
361
+ return _context22.abrupt("return", deploymentJobNumber);
362
+ case 7:
363
+ case "end":
364
+ return _context22.stop();
379
365
  }
380
366
  }, _callee7);
381
367
  }));
@@ -390,188 +376,186 @@ function _approve() {
390
376
  var _config$CircleCI$pagi, _config$CircleCI$pagi2, _config$CircleCI$pagi3, _config$CircleCI$pagi4, _context2, _context3, _context5, _confirmationPrompt;
391
377
  var approvalJob, deploymentJob, _config$deployments, _context, requestedDeployment, deploymentPipeline, workflowsRequest, workflows, buildAndDeployWorkflow, workflowId, jobsRequest, jobs, applicationApprovalJob, applicationApprovalJobId, _context4, confirmationPrompt, approvalRequest, _context6, _context7, deploymentJobNumber;
392
378
  return _regeneratorRuntime.wrap(function _callee$(_context8) {
393
- while (1) {
394
- switch (_context8.prev = _context8.next) {
395
- case 0:
396
- if (!cliFlags.deployment) {
397
- _context8.next = 9;
398
- break;
399
- }
400
- requestedDeployment = (_config$deployments = config.deployments) === null || _config$deployments === void 0 ? void 0 : _config$deployments[cliFlags.deployment];
401
- if (requestedDeployment) {
402
- _context8.next = 4;
403
- break;
404
- }
405
- throw new Error("\u26A0\uFE0F Deployment ".concat(cliFlags.deployment, " not found in configuration. Make sure it exists."));
406
- case 4:
407
- approvalJob = requestedDeployment.jobs.approval;
408
- deploymentJob = requestedDeployment.jobs.deployment;
409
- console.log(_concatInstanceProperty(_context = "\u2139\uFE0F Approving requested deployment ".concat(cliFlags.deployment, " with approval job ")).call(_context, approvalJob, "."));
410
- _context8.next = 12;
379
+ while (1) switch (_context8.prev = _context8.next) {
380
+ case 0:
381
+ if (!cliFlags.deployment) {
382
+ _context8.next = 9;
411
383
  break;
412
- case 9:
413
- approvalJob = cliFlags.approvalJob;
414
- deploymentJob = cliFlags.deploymentJob;
415
- console.log("\u2139\uFE0F Approving with approval job ".concat(approvalJob, "."));
416
- case 12:
417
- if (!cliFlags.yes) {
418
- _context8.next = 18;
419
- break;
420
- }
421
- _context8.next = 15;
422
- return paginateToDeploymentPipeline({
423
- circleCiApis: circleCiApis,
424
- buildRevision: cliFlags.buildRevision,
425
- branch: cliFlags.branch,
426
- debug: cliFlags.debug,
427
- 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
428
- });
429
- case 15:
430
- _context8.t0 = _context8.sent;
431
- _context8.next = 21;
384
+ }
385
+ requestedDeployment = (_config$deployments = config.deployments) === null || _config$deployments === void 0 ? void 0 : _config$deployments[cliFlags.deployment];
386
+ if (requestedDeployment) {
387
+ _context8.next = 4;
432
388
  break;
433
- case 18:
434
- _context8.next = 20;
435
- return waitForDeploymentPipelinePrompt({
436
- branch: cliFlags.branch,
437
- circleCiApis: circleCiApis,
438
- 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,
439
- debug: cliFlags.debug
440
- });
441
- case 20:
442
- _context8.t0 = _context8.sent;
443
- case 21:
444
- deploymentPipeline = _context8.t0;
445
- if (deploymentPipeline) {
446
- _context8.next = 24;
447
- break;
448
- }
449
- throw new Error("\u26A0\uFE0F No workflow called ".concat(config.CircleCI.deploymentWorkflowName, " found in any pipeline for deployment."));
450
- case 24:
451
- console.log("\u2139\uFE0F Found pipeline for deployment with revision ".concat(deploymentPipeline.vcs.revision, "."));
452
- workflowsRequest = circleCiApis.workflows({
453
- pipelineId: deploymentPipeline.id
454
- });
455
- _context8.next = 28;
456
- return workflowsRequest.execute({
457
- debug: cliFlags.debug
458
- });
459
- case 28:
460
- workflows = _context8.sent;
461
- buildAndDeployWorkflow = _findInstanceProperty(_context2 = workflows.items).call(_context2, function (workflow) {
462
- return workflow.name === config.CircleCI.deploymentWorkflowName;
463
- });
464
- if (buildAndDeployWorkflow) {
465
- _context8.next = 32;
466
- break;
467
- }
468
- throw new Error("\u26A0\uFE0F No workflow called ".concat(config.CircleCI.deploymentWorkflowName, " found for deployment."));
469
- case 32:
470
- workflowId = buildAndDeployWorkflow.id;
471
- console.log("\u2139\uFE0F Found workflow to build and deploy with id ".concat(workflowId, "."));
472
- jobsRequest = circleCiApis.jobs({
473
- workflowId: workflowId
474
- });
475
- _context8.next = 37;
476
- return jobsRequest.execute({
477
- debug: cliFlags.debug
478
- });
479
- case 37:
480
- jobs = _context8.sent;
481
- console.log("\u2139\uFE0F Found jobs for workflow.");
482
- applicationApprovalJob = _findInstanceProperty(_context3 = jobs.items).call(_context3, function (job) {
483
- return job.name === approvalJob;
484
- });
485
- applicationApprovalJobId = applicationApprovalJob === null || applicationApprovalJob === void 0 ? void 0 : applicationApprovalJob.id;
486
- if (applicationApprovalJobId) {
487
- _context8.next = 43;
488
- break;
489
- }
490
- 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."));
491
- case 43:
492
- console.log(_concatInstanceProperty(_context5 = "\u2139\uFE0F Found deployment approval job named ".concat(approvalJob, " with id ")).call(_context5, applicationApprovalJobId, "."));
493
- if (cliFlags.yes) {
494
- _context8.next = 48;
495
- break;
496
- }
497
- _context8.next = 47;
498
- return waitForConfirmationPrompt({
499
- approvalJob: approvalJob,
500
- revision: deploymentPipeline.vcs.revision
501
- });
502
- case 47:
503
- confirmationPrompt = _context8.sent;
504
- case 48:
505
- if (!(cliFlags.yes || (_confirmationPrompt = confirmationPrompt) !== null && _confirmationPrompt !== void 0 && _confirmationPrompt.confirmed)) {
506
- _context8.next = 71;
507
- break;
508
- }
509
- if (cliFlags.dryRun) {
510
- console.log("\uD83D\uDE4A Not approving deployment job due to dry run.");
511
- } else {
512
- console.log("\u2139\uFE0F Approving deployment job.");
513
- }
514
- approvalRequest = circleCiApis.approve({
515
- workflowId: workflowId,
516
- approvalRequestId: applicationApprovalJobId
517
- });
518
- _context8.next = 53;
519
- return approvalRequest.execute({
520
- debug: cliFlags.debug,
521
- skip: cliFlags.dryRun
522
- });
523
- case 53:
524
- if (!cliFlags.yes) {
525
- _context8.next = 57;
526
- break;
527
- }
528
- console.log("\u2139\uFE0F Skipping determining deployment job approved by ".concat(approvalJob, " due to '--yes' flag. Please check CircleCI manually."));
529
- _context8.next = 69;
389
+ }
390
+ throw new Error("\u26A0\uFE0F Deployment ".concat(cliFlags.deployment, " not found in configuration. Make sure it exists."));
391
+ case 4:
392
+ approvalJob = requestedDeployment.jobs.approval;
393
+ deploymentJob = requestedDeployment.jobs.deployment;
394
+ console.log(_concatInstanceProperty(_context = "\u2139\uFE0F Approving requested deployment ".concat(cliFlags.deployment, " with approval job ")).call(_context, approvalJob, "."));
395
+ _context8.next = 12;
396
+ break;
397
+ case 9:
398
+ approvalJob = cliFlags.approvalJob;
399
+ deploymentJob = cliFlags.deploymentJob;
400
+ console.log("\u2139\uFE0F Approving with approval job ".concat(approvalJob, "."));
401
+ case 12:
402
+ if (!cliFlags.yes) {
403
+ _context8.next = 18;
530
404
  break;
531
- case 57:
532
- if (!cliFlags.dryRun) {
533
- _context8.next = 61;
534
- break;
535
- }
536
- console.log("\u270C\uFE0F Dry running hence could not determine deployment job approved by ".concat(approvalJob, "."));
537
- _context8.next = 69;
405
+ }
406
+ _context8.next = 15;
407
+ return paginateToDeploymentPipeline({
408
+ circleCiApis: circleCiApis,
409
+ buildRevision: cliFlags.buildRevision,
410
+ branch: cliFlags.branch,
411
+ debug: cliFlags.debug,
412
+ 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
413
+ });
414
+ case 15:
415
+ _context8.t0 = _context8.sent;
416
+ _context8.next = 21;
417
+ break;
418
+ case 18:
419
+ _context8.next = 20;
420
+ return waitForDeploymentPipelinePrompt({
421
+ branch: cliFlags.branch,
422
+ circleCiApis: circleCiApis,
423
+ 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,
424
+ debug: cliFlags.debug
425
+ });
426
+ case 20:
427
+ _context8.t0 = _context8.sent;
428
+ case 21:
429
+ deploymentPipeline = _context8.t0;
430
+ if (deploymentPipeline) {
431
+ _context8.next = 24;
538
432
  break;
539
- case 61:
540
- if (!deploymentJob) {
541
- _context8.next = 68;
542
- break;
543
- }
544
- _context8.next = 64;
545
- return waitForDeploymentJobNumber({
546
- workflowId: workflowId,
547
- deploymentJob: deploymentJob,
548
- circleCiApis: circleCiApis
549
- }, {
550
- debug: cliFlags.debug,
551
- dryRun: cliFlags.dryRun,
552
- yes: cliFlags.yes
553
- });
554
- case 64:
555
- deploymentJobNumber = _context8.sent;
556
- console.log(_concatInstanceProperty(_context6 = _concatInstanceProperty(_context7 = "\uD83D\uDE4C The deployment via ".concat(approvalJob, " at revision ")).call(_context7, deploymentPipeline.vcs.revision, " is running at: ")).call(_context6, getJobUrl({
557
- projectName: config.CircleCI.projectName,
558
- pipelineNumber: deploymentPipeline.number,
559
- workflowId: workflowId,
560
- jobNumber: deploymentJobNumber
561
- })));
562
- _context8.next = 69;
433
+ }
434
+ throw new Error("\u26A0\uFE0F No workflow called ".concat(config.CircleCI.deploymentWorkflowName, " found in any pipeline for deployment."));
435
+ case 24:
436
+ console.log("\u2139\uFE0F Found pipeline for deployment with revision ".concat(deploymentPipeline.vcs.revision, "."));
437
+ workflowsRequest = circleCiApis.workflows({
438
+ pipelineId: deploymentPipeline.id
439
+ });
440
+ _context8.next = 28;
441
+ return workflowsRequest.execute({
442
+ debug: cliFlags.debug
443
+ });
444
+ case 28:
445
+ workflows = _context8.sent;
446
+ buildAndDeployWorkflow = _findInstanceProperty(_context2 = workflows.items).call(_context2, function (workflow) {
447
+ return workflow.name === config.CircleCI.deploymentWorkflowName;
448
+ });
449
+ if (buildAndDeployWorkflow) {
450
+ _context8.next = 32;
563
451
  break;
564
- case 68:
565
- console.log("\u2139\uFE0F Skipping determining deployment job as no '--deployment-job' name to wait for was passed. Please check CircleCI manually.");
566
- case 69:
567
- _context8.next = 72;
452
+ }
453
+ throw new Error("\u26A0\uFE0F No workflow called ".concat(config.CircleCI.deploymentWorkflowName, " found for deployment."));
454
+ case 32:
455
+ workflowId = buildAndDeployWorkflow.id;
456
+ console.log("\u2139\uFE0F Found workflow to build and deploy with id ".concat(workflowId, "."));
457
+ jobsRequest = circleCiApis.jobs({
458
+ workflowId: workflowId
459
+ });
460
+ _context8.next = 37;
461
+ return jobsRequest.execute({
462
+ debug: cliFlags.debug
463
+ });
464
+ case 37:
465
+ jobs = _context8.sent;
466
+ console.log("\u2139\uFE0F Found jobs for workflow.");
467
+ applicationApprovalJob = _findInstanceProperty(_context3 = jobs.items).call(_context3, function (job) {
468
+ return job.name === approvalJob;
469
+ });
470
+ applicationApprovalJobId = applicationApprovalJob === null || applicationApprovalJob === void 0 ? void 0 : applicationApprovalJob.id;
471
+ if (applicationApprovalJobId) {
472
+ _context8.next = 43;
568
473
  break;
569
- case 71:
570
- console.log("\u2139\uFE0F Not approving deployment job. Confirm the prompt or use '--yes' option.");
571
- case 72:
572
- case "end":
573
- return _context8.stop();
574
- }
474
+ }
475
+ 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."));
476
+ case 43:
477
+ console.log(_concatInstanceProperty(_context5 = "\u2139\uFE0F Found deployment approval job named ".concat(approvalJob, " with id ")).call(_context5, applicationApprovalJobId, "."));
478
+ if (cliFlags.yes) {
479
+ _context8.next = 48;
480
+ break;
481
+ }
482
+ _context8.next = 47;
483
+ return waitForConfirmationPrompt({
484
+ approvalJob: approvalJob,
485
+ revision: deploymentPipeline.vcs.revision
486
+ });
487
+ case 47:
488
+ confirmationPrompt = _context8.sent;
489
+ case 48:
490
+ if (!(cliFlags.yes || (_confirmationPrompt = confirmationPrompt) !== null && _confirmationPrompt !== void 0 && _confirmationPrompt.confirmed)) {
491
+ _context8.next = 71;
492
+ break;
493
+ }
494
+ if (cliFlags.dryRun) {
495
+ console.log("\uD83D\uDE4A Not approving deployment job due to dry run.");
496
+ } else {
497
+ console.log("\u2139\uFE0F Approving deployment job.");
498
+ }
499
+ approvalRequest = circleCiApis.approve({
500
+ workflowId: workflowId,
501
+ approvalRequestId: applicationApprovalJobId
502
+ });
503
+ _context8.next = 53;
504
+ return approvalRequest.execute({
505
+ debug: cliFlags.debug,
506
+ skip: cliFlags.dryRun
507
+ });
508
+ case 53:
509
+ if (!cliFlags.yes) {
510
+ _context8.next = 57;
511
+ break;
512
+ }
513
+ console.log("\u2139\uFE0F Skipping determining deployment job approved by ".concat(approvalJob, " due to '--yes' flag. Please check CircleCI manually."));
514
+ _context8.next = 69;
515
+ break;
516
+ case 57:
517
+ if (!cliFlags.dryRun) {
518
+ _context8.next = 61;
519
+ break;
520
+ }
521
+ console.log("\u270C\uFE0F Dry running hence could not determine deployment job approved by ".concat(approvalJob, "."));
522
+ _context8.next = 69;
523
+ break;
524
+ case 61:
525
+ if (!deploymentJob) {
526
+ _context8.next = 68;
527
+ break;
528
+ }
529
+ _context8.next = 64;
530
+ return waitForDeploymentJobNumber({
531
+ workflowId: workflowId,
532
+ deploymentJob: deploymentJob,
533
+ circleCiApis: circleCiApis
534
+ }, {
535
+ debug: cliFlags.debug,
536
+ dryRun: cliFlags.dryRun,
537
+ yes: cliFlags.yes
538
+ });
539
+ case 64:
540
+ deploymentJobNumber = _context8.sent;
541
+ console.log(_concatInstanceProperty(_context6 = _concatInstanceProperty(_context7 = "\uD83D\uDE4C The deployment via ".concat(approvalJob, " at revision ")).call(_context7, deploymentPipeline.vcs.revision, " is running at: ")).call(_context6, getJobUrl({
542
+ projectName: config.CircleCI.projectName,
543
+ pipelineNumber: deploymentPipeline.number,
544
+ workflowId: workflowId,
545
+ jobNumber: deploymentJobNumber
546
+ })));
547
+ _context8.next = 69;
548
+ break;
549
+ case 68:
550
+ console.log("\u2139\uFE0F Skipping determining deployment job as no '--deployment-job' name to wait for was passed. Please check CircleCI manually.");
551
+ case 69:
552
+ _context8.next = 72;
553
+ break;
554
+ case 71:
555
+ console.log("\u2139\uFE0F Not approving deployment job. Confirm the prompt or use '--yes' option.");
556
+ case 72:
557
+ case "end":
558
+ return _context8.stop();
575
559
  }
576
560
  }, _callee);
577
561
  }));
@@ -585,39 +569,37 @@ function _processCircleCiResponse() {
585
569
  _processCircleCiResponse = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(response) {
586
570
  var _context4, _context5, errorJson, errorText;
587
571
  return _regeneratorRuntime.wrap(function _callee2$(_context6) {
588
- while (1) {
589
- switch (_context6.prev = _context6.next) {
590
- case 0:
591
- if (response.ok) {
592
- _context6.next = 14;
593
- break;
594
- }
595
- _context6.prev = 1;
596
- _context6.next = 4;
597
- return response.json();
598
- case 4:
599
- errorJson = _context6.sent;
600
- if (errorJson.message.match(/job already approved/i)) {
601
- console.log('ℹ️ Deployment job is already approved.');
602
- process.exit(0);
603
- }
604
- _context6.next = 10;
572
+ while (1) switch (_context6.prev = _context6.next) {
573
+ case 0:
574
+ if (response.ok) {
575
+ _context6.next = 14;
605
576
  break;
606
- case 8:
607
- _context6.prev = 8;
608
- _context6.t0 = _context6["catch"](1);
609
- case 10:
610
- _context6.next = 12;
611
- return response.text();
612
- case 12:
613
- errorText = _context6.sent;
614
- throw new Error(_concatInstanceProperty(_context4 = _concatInstanceProperty(_context5 = "".concat(response.status, ": Network response was not ok.\n\n Status text is ")).call(_context5, response.statusText, " and text is ")).call(_context4, errorText, "."));
615
- case 14:
616
- return _context6.abrupt("return", response.json());
617
- case 15:
618
- case "end":
619
- return _context6.stop();
620
- }
577
+ }
578
+ _context6.prev = 1;
579
+ _context6.next = 4;
580
+ return response.json();
581
+ case 4:
582
+ errorJson = _context6.sent;
583
+ if (errorJson.message.match(/job already approved/i)) {
584
+ console.log('ℹ️ Deployment job is already approved.');
585
+ process.exit(0);
586
+ }
587
+ _context6.next = 10;
588
+ break;
589
+ case 8:
590
+ _context6.prev = 8;
591
+ _context6.t0 = _context6["catch"](1);
592
+ case 10:
593
+ _context6.next = 12;
594
+ return response.text();
595
+ case 12:
596
+ errorText = _context6.sent;
597
+ throw new Error(_concatInstanceProperty(_context4 = _concatInstanceProperty(_context5 = "".concat(response.status, ": Network response was not ok.\n\n Status text is ")).call(_context5, response.statusText, " and text is ")).call(_context4, errorText, "."));
598
+ case 14:
599
+ return _context6.abrupt("return", response.json());
600
+ case 15:
601
+ case "end":
602
+ return _context6.stop();
621
603
  }
622
604
  }, _callee2, null, [[1, 8]]);
623
605
  }));
@@ -639,7 +621,7 @@ function createCircleCiClient(_ref) {
639
621
  urlSearchParams,
640
622
  _i,
641
623
  _Object$entries,
642
- _ref9,
624
+ _ref7,
643
625
  _ref8,
644
626
  key,
645
627
  value,
@@ -647,61 +629,59 @@ function createCircleCiClient(_ref) {
647
629
  processedCircleCiResponse,
648
630
  _args = arguments;
649
631
  return _regeneratorRuntime.wrap(function _callee$(_context3) {
650
- while (1) {
651
- switch (_context3.prev = _context3.next) {
652
- case 0:
653
- _ref6 = _args.length > 1 && _args[1] !== undefined ? _args[1] : {}, skip = _ref6.skip, debug = _ref6.debug;
654
- url = _concatInstanceProperty(_context2 = "".concat(apiBaseUrl)).call(_context2, api.url);
655
- if (api.params && api.method === 'GET') {
656
- urlSearchParams = new _URLSearchParams();
657
- for (_i = 0, _Object$entries = _Object$entries2(api.params); _i < _Object$entries.length; _i++) {
658
- _ref9 = _Object$entries[_i];
659
- _ref8 = _slicedToArray(_ref9, 2);
660
- key = _ref8[0];
661
- value = _ref8[1];
662
- if (value !== null && value !== undefined) {
663
- urlSearchParams.append(key, value);
664
- }
632
+ while (1) switch (_context3.prev = _context3.next) {
633
+ case 0:
634
+ _ref6 = _args.length > 1 && _args[1] !== undefined ? _args[1] : {}, skip = _ref6.skip, debug = _ref6.debug;
635
+ url = _concatInstanceProperty(_context2 = "".concat(apiBaseUrl)).call(_context2, api.url);
636
+ if (api.params && api.method === 'GET') {
637
+ urlSearchParams = new _URLSearchParams();
638
+ for (_i = 0, _Object$entries = _Object$entries2(api.params); _i < _Object$entries.length; _i++) {
639
+ _ref7 = _Object$entries[_i];
640
+ _ref8 = _slicedToArray(_ref7, 2);
641
+ key = _ref8[0];
642
+ value = _ref8[1];
643
+ if (value !== null && value !== undefined) {
644
+ urlSearchParams.append(key, value);
665
645
  }
666
- url += "?".concat(urlSearchParams.toString());
667
- }
668
- if (!skip) {
669
- _context3.next = 6;
670
- break;
671
- }
672
- if (debug) {
673
- console.log("\uD83C\uDFED Skipping CircleCI call API at: ".concat(url, "."));
674
646
  }
647
+ url += "?".concat(urlSearchParams.toString());
648
+ }
649
+ if (!skip) {
650
+ _context3.next = 6;
651
+ break;
652
+ }
653
+ if (debug) {
654
+ console.log("\uD83C\uDFED Skipping CircleCI call API at: ".concat(url, "."));
655
+ }
675
656
 
676
- // @ts-expect-error
677
- return _context3.abrupt("return", _Promise.resolve());
678
- case 6:
679
- if (debug) {
680
- console.log("\uD83C\uDFED Calling CircleCI API at: ".concat(url, "."));
681
- }
682
- _context3.prev = 7;
683
- _context3.next = 10;
684
- return fetch(url, {
685
- headers: api.headers,
686
- method: api.method,
687
- body: api.method === 'POST' ? _JSON$stringify(api.params) : undefined
688
- });
689
- case 10:
690
- response = _context3.sent;
691
- _context3.next = 13;
692
- return processCircleCiResponse(response);
693
- case 13:
694
- processedCircleCiResponse = _context3.sent;
695
- return _context3.abrupt("return", processedCircleCiResponse);
696
- case 17:
697
- _context3.prev = 17;
698
- _context3.t0 = _context3["catch"](7);
699
- console.log("\u26A0\uFE0F Calling CircleCI API at: ".concat(url, " failed."));
700
- throw _context3.t0;
701
- case 21:
702
- case "end":
703
- return _context3.stop();
704
- }
657
+ // @ts-expect-error
658
+ return _context3.abrupt("return", _Promise.resolve());
659
+ case 6:
660
+ if (debug) {
661
+ console.log("\uD83C\uDFED Calling CircleCI API at: ".concat(url, "."));
662
+ }
663
+ _context3.prev = 7;
664
+ _context3.next = 10;
665
+ return fetch(url, {
666
+ headers: api.headers,
667
+ method: api.method,
668
+ body: api.method === 'POST' ? _JSON$stringify(api.params) : undefined
669
+ });
670
+ case 10:
671
+ response = _context3.sent;
672
+ _context3.next = 13;
673
+ return processCircleCiResponse(response);
674
+ case 13:
675
+ processedCircleCiResponse = _context3.sent;
676
+ return _context3.abrupt("return", processedCircleCiResponse);
677
+ case 17:
678
+ _context3.prev = 17;
679
+ _context3.t0 = _context3["catch"](7);
680
+ console.log("\u26A0\uFE0F Calling CircleCI API at: ".concat(url, " failed."));
681
+ throw _context3.t0;
682
+ case 21:
683
+ case "end":
684
+ return _context3.stop();
705
685
  }
706
686
  }, _callee, null, [[7, 17]]);
707
687
  }));
@@ -793,72 +773,70 @@ function _run() {
793
773
  _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
794
774
  var config, circleCiApis, _context, cliFlags, cliCommands, cliCommand;
795
775
  return _regeneratorRuntime.wrap(function _callee$(_context2) {
796
- while (1) {
797
- switch (_context2.prev = _context2.next) {
798
- case 0:
799
- _context2.next = 2;
800
- return loadConfig();
801
- case 2:
802
- config = _context2.sent;
803
- throwIfConfigurationLacksRequiredValues(config);
804
- circleCiApis = createCircleCiClient({
805
- projectName: config.CircleCI.projectName,
806
- apiBaseUrl: config.CircleCI.apiBaseUrl
807
- });
808
- _context2.prev = 5;
809
- cliFlags = mri(_sliceInstanceProperty(_context = process.argv).call(_context, 2), {
810
- alias: {
811
- help: ['h']
812
- },
813
- boolean: ['dry-run', 'debug', 'yes'],
814
- default: {
815
- branch: 'main'
816
- }
817
- });
818
- cliCommands = cliFlags._;
819
- if (cliCommands.length === 0 ||
820
- // @ts-expect-error mri is not typed for the help command.
821
- cliCommands.help && cliCommands.length === 0) {
822
- console.log("\nUsage: deployment-cli [command] [flags]\n\nDisplays help information.\n\nCommand:\n approve 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/).\n\nOptions:\n --approval-job The name of the approval job to approve a deployment with.\n --deployment-job (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.\n --deployment (optional) The name of a deployment configured in the configuration file.\n --build-revision <git-sha> (optional) The git commit SHA that needs to be deployed. If not specified, the last successful pipeline is used.\n --branch (optional) The git branch to deploy from. If not specified, defaults to 'main'.\n --yes (optional) Skip all confirmation prompts. Useful in Continuous integration (CI) to automatically answer confirmation questions.\n\nGeneral options:\n --dry-run (optional) Simulate a deployment.\n --debug (optional) Print additional debug information.\n");
823
- process.exit(0);
824
- }
825
- cliCommand = cliCommands[0];
826
- if (cliFlags['dry-run']) {
827
- console.log("\n \uD83D\uDE4A Do not worry. This is a dry run!\n ");
776
+ while (1) switch (_context2.prev = _context2.next) {
777
+ case 0:
778
+ _context2.next = 2;
779
+ return loadConfig();
780
+ case 2:
781
+ config = _context2.sent;
782
+ throwIfConfigurationLacksRequiredValues(config);
783
+ circleCiApis = createCircleCiClient({
784
+ projectName: config.CircleCI.projectName,
785
+ apiBaseUrl: config.CircleCI.apiBaseUrl
786
+ });
787
+ _context2.prev = 5;
788
+ cliFlags = mri(_sliceInstanceProperty(_context = process.argv).call(_context, 2), {
789
+ alias: {
790
+ help: ['h']
791
+ },
792
+ boolean: ['dry-run', 'debug', 'yes'],
793
+ default: {
794
+ branch: 'main'
828
795
  }
829
- console.log("\uD83C\uDFC3 Running ".concat(cliCommand, " command"));
830
- _context2.t0 = cliCommand;
831
- _context2.next = _context2.t0 === 'approve' ? 15 : 19;
832
- break;
833
- case 15:
834
- throwIfRequiredEnvironmentVariableIsUnset(['CIRCLE_TOKEN']);
835
- _context2.next = 18;
836
- return approve({
837
- deployment: cliFlags.deployment,
838
- branch: cliFlags.branch,
839
- approvalJob: cliFlags['approval-job'],
840
- deploymentJob: cliFlags['deployment-job'],
841
- buildRevision: cliFlags['build-revision'],
842
- yes: cliFlags.yes,
843
- debug: cliFlags.debug,
844
- dryRun: cliFlags['dry-run']
845
- }, config, circleCiApis);
846
- case 18:
796
+ });
797
+ cliCommands = cliFlags._;
798
+ if (cliCommands.length === 0 ||
799
+ // @ts-expect-error mri is not typed for the help command.
800
+ cliCommands.help && cliCommands.length === 0) {
801
+ console.log("\nUsage: deployment-cli [command] [flags]\n\nDisplays help information.\n\nCommand:\n approve 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/).\n\nOptions:\n --approval-job The name of the approval job to approve a deployment with.\n --deployment-job (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.\n --deployment (optional) The name of a deployment configured in the configuration file.\n --build-revision <git-sha> (optional) The git commit SHA that needs to be deployed. If not specified, the last successful pipeline is used.\n --branch (optional) The git branch to deploy from. If not specified, defaults to 'main'.\n --yes (optional) Skip all confirmation prompts. Useful in Continuous integration (CI) to automatically answer confirmation questions.\n\nGeneral options:\n --dry-run (optional) Simulate a deployment.\n --debug (optional) Print additional debug information.\n");
847
802
  process.exit(0);
848
- case 19:
849
- throw new Error("\uD83D\uDC80 Unknown command \"".concat(cliCommand, "\"."));
850
- case 20:
851
- _context2.next = 26;
852
- break;
853
- case 22:
854
- _context2.prev = 22;
855
- _context2.t1 = _context2["catch"](5);
856
- console.error(_context2.t1);
857
- process.exit(1);
858
- case 26:
859
- case "end":
860
- return _context2.stop();
861
- }
803
+ }
804
+ cliCommand = cliCommands[0];
805
+ if (cliFlags['dry-run']) {
806
+ console.log("\n \uD83D\uDE4A Do not worry. This is a dry run!\n ");
807
+ }
808
+ console.log("\uD83C\uDFC3 Running ".concat(cliCommand, " command"));
809
+ _context2.t0 = cliCommand;
810
+ _context2.next = _context2.t0 === 'approve' ? 15 : 19;
811
+ break;
812
+ case 15:
813
+ throwIfRequiredEnvironmentVariableIsUnset(['CIRCLE_TOKEN']);
814
+ _context2.next = 18;
815
+ return approve({
816
+ deployment: cliFlags.deployment,
817
+ branch: cliFlags.branch,
818
+ approvalJob: cliFlags['approval-job'],
819
+ deploymentJob: cliFlags['deployment-job'],
820
+ buildRevision: cliFlags['build-revision'],
821
+ yes: cliFlags.yes,
822
+ debug: cliFlags.debug,
823
+ dryRun: cliFlags['dry-run']
824
+ }, config, circleCiApis);
825
+ case 18:
826
+ process.exit(0);
827
+ case 19:
828
+ throw new Error("\uD83D\uDC80 Unknown command \"".concat(cliCommand, "\"."));
829
+ case 20:
830
+ _context2.next = 26;
831
+ break;
832
+ case 22:
833
+ _context2.prev = 22;
834
+ _context2.t1 = _context2["catch"](5);
835
+ console.error(_context2.t1);
836
+ process.exit(1);
837
+ case 26:
838
+ case "end":
839
+ return _context2.stop();
862
840
  }
863
841
  }, _callee, null, [[5, 22]]);
864
842
  }));