@commercetools-frontend/deployment-cli 0.0.5 → 0.0.7
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.
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var _asyncToGenerator = require('@babel/runtime-corejs3/helpers/asyncToGenerator');
|
|
6
|
-
var _regeneratorRuntime = require('@babel/runtime-corejs3/regenerator');
|
|
7
5
|
var _sliceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/slice');
|
|
8
6
|
var mri = require('mri');
|
|
9
7
|
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
@@ -13,19 +11,18 @@ var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instan
|
|
|
13
11
|
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
|
|
14
12
|
var _startsWithInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/starts-with');
|
|
15
13
|
var cosmiconfig = require('cosmiconfig');
|
|
16
|
-
var merge = require('lodash
|
|
14
|
+
var merge = require('lodash/merge');
|
|
17
15
|
var prompts = require('prompts');
|
|
18
16
|
var pRetry = require('p-retry');
|
|
19
17
|
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
20
18
|
var _URLSearchParams = require('@babel/runtime-corejs3/core-js-stable/url-search-params');
|
|
21
|
-
var _Object$
|
|
19
|
+
var _Object$entries = require('@babel/runtime-corejs3/core-js-stable/object/entries');
|
|
22
20
|
var _Promise = require('@babel/runtime-corejs3/core-js-stable/promise');
|
|
23
21
|
var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
|
|
24
22
|
var fetch = require('node-fetch');
|
|
25
23
|
|
|
26
24
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
27
25
|
|
|
28
|
-
var _regeneratorRuntime__default = /*#__PURE__*/_interopDefault(_regeneratorRuntime);
|
|
29
26
|
var _sliceInstanceProperty__default = /*#__PURE__*/_interopDefault(_sliceInstanceProperty);
|
|
30
27
|
var mri__default = /*#__PURE__*/_interopDefault(mri);
|
|
31
28
|
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
@@ -38,51 +35,32 @@ var merge__default = /*#__PURE__*/_interopDefault(merge);
|
|
|
38
35
|
var prompts__default = /*#__PURE__*/_interopDefault(prompts);
|
|
39
36
|
var pRetry__default = /*#__PURE__*/_interopDefault(pRetry);
|
|
40
37
|
var _URLSearchParams__default = /*#__PURE__*/_interopDefault(_URLSearchParams);
|
|
41
|
-
var _Object$
|
|
38
|
+
var _Object$entries__default = /*#__PURE__*/_interopDefault(_Object$entries);
|
|
42
39
|
var _Promise__default = /*#__PURE__*/_interopDefault(_Promise);
|
|
43
40
|
var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
|
|
44
41
|
var fetch__default = /*#__PURE__*/_interopDefault(fetch);
|
|
45
42
|
|
|
46
|
-
function loadConfig() {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
deploymentConfigExplorer = cosmiconfig.cosmiconfig('deployment');
|
|
56
|
-
defaultConfig = {
|
|
57
|
-
CircleCI: {
|
|
58
|
-
apiBaseUrl: 'https://circleci.com/api/v2',
|
|
59
|
-
deploymentWorkflowName: 'test_build_and_deploy',
|
|
60
|
-
pagination: {
|
|
61
|
-
maxPages: 42,
|
|
62
|
-
pagesForPipelineSelection: 5
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
MerchantCenter: {}
|
|
66
|
-
};
|
|
67
|
-
_context7.prev = 2;
|
|
68
|
-
_context7.next = 5;
|
|
69
|
-
return deploymentConfigExplorer.search();
|
|
70
|
-
case 5:
|
|
71
|
-
cosmiconfigResult = _context7.sent;
|
|
72
|
-
mergedConfig = merge__default["default"](defaultConfig, cosmiconfigResult === null || cosmiconfigResult === void 0 ? void 0 : cosmiconfigResult.config);
|
|
73
|
-
return _context7.abrupt("return", mergedConfig);
|
|
74
|
-
case 10:
|
|
75
|
-
_context7.prev = 10;
|
|
76
|
-
_context7.t0 = _context7["catch"](2);
|
|
77
|
-
console.warn(_context7.t0);
|
|
78
|
-
throw new Error('Failed loading a deployment configuration. Create a cosmiconfig for `deployment` for example `deployment.config.cjs`.');
|
|
79
|
-
case 14:
|
|
80
|
-
case "end":
|
|
81
|
-
return _context7.stop();
|
|
43
|
+
async function loadConfig() {
|
|
44
|
+
const deploymentConfigExplorer = cosmiconfig.cosmiconfig('deployment');
|
|
45
|
+
const defaultConfig = {
|
|
46
|
+
CircleCI: {
|
|
47
|
+
apiBaseUrl: 'https://circleci.com/api/v2',
|
|
48
|
+
deploymentWorkflowName: 'test_build_and_deploy',
|
|
49
|
+
pagination: {
|
|
50
|
+
maxPages: 42,
|
|
51
|
+
pagesForPipelineSelection: 5
|
|
82
52
|
}
|
|
83
|
-
},
|
|
84
|
-
|
|
85
|
-
|
|
53
|
+
},
|
|
54
|
+
MerchantCenter: {}
|
|
55
|
+
};
|
|
56
|
+
try {
|
|
57
|
+
const cosmiconfigResult = await deploymentConfigExplorer.search();
|
|
58
|
+
const mergedConfig = merge__default["default"](defaultConfig, cosmiconfigResult === null || cosmiconfigResult === void 0 ? void 0 : cosmiconfigResult.config);
|
|
59
|
+
return mergedConfig;
|
|
60
|
+
} catch (e) {
|
|
61
|
+
console.warn(e);
|
|
62
|
+
throw new Error('Failed loading a deployment configuration. Create a cosmiconfig for `deployment` for example `deployment.config.cjs`.');
|
|
63
|
+
}
|
|
86
64
|
}
|
|
87
65
|
function throwIfConfigurationLacksRequiredValues(parsedConfiguration) {
|
|
88
66
|
if (!parsedConfiguration.CircleCI.projectName) {
|
|
@@ -90,21 +68,21 @@ function throwIfConfigurationLacksRequiredValues(parsedConfiguration) {
|
|
|
90
68
|
}
|
|
91
69
|
}
|
|
92
70
|
function throwIfRequiredEnvironmentVariableIsUnset(requiredEnvironmentVariables) {
|
|
93
|
-
_forEachInstanceProperty__default["default"](requiredEnvironmentVariables).call(requiredEnvironmentVariables,
|
|
94
|
-
|
|
71
|
+
_forEachInstanceProperty__default["default"](requiredEnvironmentVariables).call(requiredEnvironmentVariables, nameOfRequiredEnvironmentVariable => {
|
|
72
|
+
const valueOfRequiredEnvironmentVariable = process.env[nameOfRequiredEnvironmentVariable];
|
|
95
73
|
if (!valueOfRequiredEnvironmentVariable) throw new Error("Missing '".concat(nameOfRequiredEnvironmentVariable, "' environment variable"));
|
|
96
74
|
});
|
|
97
75
|
}
|
|
98
|
-
|
|
99
|
-
applicationSelect:
|
|
100
|
-
|
|
76
|
+
const promptOptions = {
|
|
77
|
+
applicationSelect: _ref => {
|
|
78
|
+
let packages = _ref.packages;
|
|
101
79
|
return {
|
|
102
80
|
type: 'select',
|
|
103
81
|
name: 'applicationName',
|
|
104
82
|
message: 'Select an application',
|
|
105
|
-
choices: _mapInstanceProperty__default["default"](packages).call(packages,
|
|
106
|
-
|
|
107
|
-
|
|
83
|
+
choices: _mapInstanceProperty__default["default"](packages).call(packages, _ref2 => {
|
|
84
|
+
let packageJson = _ref2.packageJson;
|
|
85
|
+
const applicationName = packageJson.name.replace('@commercetools-local/application-', '');
|
|
108
86
|
return {
|
|
109
87
|
title: applicationName,
|
|
110
88
|
value: applicationName
|
|
@@ -112,13 +90,13 @@ var promptOptions = {
|
|
|
112
90
|
})
|
|
113
91
|
};
|
|
114
92
|
},
|
|
115
|
-
deploymentPipelineSelect:
|
|
116
|
-
|
|
93
|
+
deploymentPipelineSelect: _ref3 => {
|
|
94
|
+
let deploymentPipelines = _ref3.deploymentPipelines;
|
|
117
95
|
return {
|
|
118
96
|
type: 'select',
|
|
119
97
|
name: 'deploymentPipeline',
|
|
120
98
|
message: 'Select the revision you would like to deploy',
|
|
121
|
-
choices: _mapInstanceProperty__default["default"](deploymentPipelines).call(deploymentPipelines,
|
|
99
|
+
choices: _mapInstanceProperty__default["default"](deploymentPipelines).call(deploymentPipelines, deploymentPipeline => {
|
|
122
100
|
var _context, _context2;
|
|
123
101
|
return {
|
|
124
102
|
title: _concatInstanceProperty__default["default"](_context = _concatInstanceProperty__default["default"](_context2 = "".concat(deploymentPipeline.vcs.revision.substring(0, 7), " - ")).call(_context2, deploymentPipeline.vcs.commit.subject, " <")).call(_context, deploymentPipeline.trigger.actor.login, ">"),
|
|
@@ -127,9 +105,9 @@ var promptOptions = {
|
|
|
127
105
|
})
|
|
128
106
|
};
|
|
129
107
|
},
|
|
130
|
-
deploymentConfirmation:
|
|
108
|
+
deploymentConfirmation: _ref4 => {
|
|
131
109
|
var _context3;
|
|
132
|
-
|
|
110
|
+
let approvalJob = _ref4.approvalJob,
|
|
133
111
|
revision = _ref4.revision;
|
|
134
112
|
return {
|
|
135
113
|
type: 'toggle',
|
|
@@ -141,183 +119,108 @@ var promptOptions = {
|
|
|
141
119
|
};
|
|
142
120
|
}
|
|
143
121
|
};
|
|
144
|
-
function paginateToDeploymentPipeline(
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
if (!deploymentPipeline) {
|
|
183
|
-
_context13.next = 13;
|
|
184
|
-
break;
|
|
185
|
-
}
|
|
186
|
-
console.log("\u2139\uFE0F Using pipeline for deployment with revision ".concat(deploymentPipeline.vcs.revision, "."));
|
|
187
|
-
return _context13.abrupt("break", 16);
|
|
188
|
-
case 13:
|
|
189
|
-
i++;
|
|
190
|
-
_context13.next = 2;
|
|
191
|
-
break;
|
|
192
|
-
case 16:
|
|
193
|
-
return _context13.abrupt("return", deploymentPipeline);
|
|
194
|
-
case 17:
|
|
195
|
-
case "end":
|
|
196
|
-
return _context13.stop();
|
|
197
|
-
}
|
|
198
|
-
}, _callee2);
|
|
199
|
-
}));
|
|
200
|
-
return _paginateToDeploymentPipeline.apply(this, arguments);
|
|
201
|
-
}
|
|
202
|
-
function collectDeploymentPipelines(_x2) {
|
|
203
|
-
return _collectDeploymentPipelines.apply(this, arguments);
|
|
204
|
-
}
|
|
205
|
-
function _collectDeploymentPipelines() {
|
|
206
|
-
_collectDeploymentPipelines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3(_ref6) {
|
|
207
|
-
var circleCiApis, branch, pagesForPipelineSelection, debug, deploymentPipelines, nextPageToken, i, _context14, _context15, pipelinesRequest, pipelines, nonScheduledPipelines;
|
|
208
|
-
return _regeneratorRuntime__default["default"].wrap(function _callee3$(_context16) {
|
|
209
|
-
while (1) switch (_context16.prev = _context16.next) {
|
|
210
|
-
case 0:
|
|
211
|
-
circleCiApis = _ref6.circleCiApis, branch = _ref6.branch, pagesForPipelineSelection = _ref6.pagesForPipelineSelection, debug = _ref6.debug;
|
|
212
|
-
deploymentPipelines = [];
|
|
213
|
-
i = 0;
|
|
214
|
-
case 3:
|
|
215
|
-
if (!(i < pagesForPipelineSelection)) {
|
|
216
|
-
_context16.next = 13;
|
|
217
|
-
break;
|
|
218
|
-
}
|
|
219
|
-
// eslint-disable-next-line no-await-in-loop
|
|
220
|
-
pipelinesRequest = circleCiApis.pipelines({
|
|
221
|
-
pageToken: nextPageToken,
|
|
222
|
-
branch: branch
|
|
223
|
-
});
|
|
224
|
-
_context16.next = 7;
|
|
225
|
-
return pipelinesRequest.execute({
|
|
226
|
-
debug: debug
|
|
227
|
-
});
|
|
228
|
-
case 7:
|
|
229
|
-
pipelines = _context16.sent;
|
|
230
|
-
nonScheduledPipelines = _filterInstanceProperty__default["default"](_context14 = _filterInstanceProperty__default["default"](_context15 = pipelines.items).call(_context15, isNonScheduledPipeline)).call(_context14, isNonErroredPipeline);
|
|
231
|
-
deploymentPipelines = _concatInstanceProperty__default["default"](deploymentPipelines).call(deploymentPipelines, nonScheduledPipelines);
|
|
232
|
-
case 10:
|
|
233
|
-
i++;
|
|
234
|
-
_context16.next = 3;
|
|
235
|
-
break;
|
|
236
|
-
case 13:
|
|
237
|
-
return _context16.abrupt("return", deploymentPipelines);
|
|
238
|
-
case 14:
|
|
239
|
-
case "end":
|
|
240
|
-
return _context16.stop();
|
|
241
|
-
}
|
|
242
|
-
}, _callee3);
|
|
243
|
-
}));
|
|
244
|
-
return _collectDeploymentPipelines.apply(this, arguments);
|
|
122
|
+
async function paginateToDeploymentPipeline(_ref5) {
|
|
123
|
+
let circleCiApis = _ref5.circleCiApis,
|
|
124
|
+
buildRevision = _ref5.buildRevision,
|
|
125
|
+
branch = _ref5.branch,
|
|
126
|
+
debug = _ref5.debug,
|
|
127
|
+
maxPages = _ref5.maxPages;
|
|
128
|
+
let deploymentPipeline;
|
|
129
|
+
let nextPageToken;
|
|
130
|
+
// eslint-disable-next-line no-plusplus
|
|
131
|
+
for (let i = 0; i < maxPages; i++) {
|
|
132
|
+
var _context4, _context5;
|
|
133
|
+
// eslint-disable-next-line no-await-in-loop
|
|
134
|
+
|
|
135
|
+
const pipelineRequest = circleCiApis.pipelines({
|
|
136
|
+
pageToken: nextPageToken,
|
|
137
|
+
branch
|
|
138
|
+
});
|
|
139
|
+
const pipelines = await pipelineRequest.execute({
|
|
140
|
+
debug
|
|
141
|
+
});
|
|
142
|
+
nextPageToken = pipelines.next_page_token;
|
|
143
|
+
const nonScheduledPipelines = _filterInstanceProperty__default["default"](_context4 = _filterInstanceProperty__default["default"](_context5 = pipelines.items).call(_context5, isNonScheduledPipeline)).call(_context4, isNonErroredPipeline);
|
|
144
|
+
if (buildRevision) {
|
|
145
|
+
var _context6, _context7;
|
|
146
|
+
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, "."));
|
|
147
|
+
deploymentPipeline = _findInstanceProperty__default["default"](nonScheduledPipelines).call(nonScheduledPipelines, pipeline => {
|
|
148
|
+
var _context8;
|
|
149
|
+
return _startsWithInstanceProperty__default["default"](_context8 = pipeline.vcs.revision).call(_context8, buildRevision);
|
|
150
|
+
});
|
|
151
|
+
} else {
|
|
152
|
+
deploymentPipeline = nonScheduledPipelines[0];
|
|
153
|
+
}
|
|
154
|
+
if (deploymentPipeline) {
|
|
155
|
+
console.log("\u2139\uFE0F Using pipeline for deployment with revision ".concat(deploymentPipeline.vcs.revision, "."));
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return deploymentPipeline;
|
|
245
160
|
}
|
|
246
|
-
function
|
|
247
|
-
|
|
161
|
+
async function collectDeploymentPipelines(_ref6) {
|
|
162
|
+
let circleCiApis = _ref6.circleCiApis,
|
|
163
|
+
branch = _ref6.branch,
|
|
164
|
+
pagesForPipelineSelection = _ref6.pagesForPipelineSelection,
|
|
165
|
+
debug = _ref6.debug;
|
|
166
|
+
let deploymentPipelines = [];
|
|
167
|
+
let nextPageToken;
|
|
168
|
+
// eslint-disable-next-line no-plusplus
|
|
169
|
+
for (let i = 0; i < pagesForPipelineSelection; i++) {
|
|
170
|
+
var _context9, _context10;
|
|
171
|
+
// eslint-disable-next-line no-await-in-loop
|
|
172
|
+
const pipelinesRequest = circleCiApis.pipelines({
|
|
173
|
+
pageToken: nextPageToken,
|
|
174
|
+
branch
|
|
175
|
+
});
|
|
176
|
+
const pipelines = await pipelinesRequest.execute({
|
|
177
|
+
debug
|
|
178
|
+
});
|
|
179
|
+
const nonScheduledPipelines = _filterInstanceProperty__default["default"](_context9 = _filterInstanceProperty__default["default"](_context10 = pipelines.items).call(_context10, isNonScheduledPipeline)).call(_context9, isNonErroredPipeline);
|
|
180
|
+
deploymentPipelines = _concatInstanceProperty__default["default"](deploymentPipelines).call(deploymentPipelines, nonScheduledPipelines);
|
|
181
|
+
}
|
|
182
|
+
return deploymentPipelines;
|
|
248
183
|
}
|
|
249
|
-
function
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
deploymentPipelines = _context17.sent;
|
|
265
|
-
_context17.next = 6;
|
|
266
|
-
return prompts__default["default"](
|
|
267
|
-
// @ts-expect-error prompts is not typed
|
|
268
|
-
promptOptions.deploymentPipelineSelect({
|
|
269
|
-
deploymentPipelines: deploymentPipelines
|
|
270
|
-
}));
|
|
271
|
-
case 6:
|
|
272
|
-
deploymentPipelinePrompt = _context17.sent;
|
|
273
|
-
revision = deploymentPipelinePrompt.deploymentPipeline.vcs.revision;
|
|
274
|
-
if (revision) {
|
|
275
|
-
_context17.next = 11;
|
|
276
|
-
break;
|
|
277
|
-
}
|
|
278
|
-
console.log('☝️ Please select a revision or specify it as a CLI argument via `--build-revision`.');
|
|
279
|
-
throw new Error('No revision specified.');
|
|
280
|
-
case 11:
|
|
281
|
-
return _context17.abrupt("return", deploymentPipelinePrompt.deploymentPipeline);
|
|
282
|
-
case 12:
|
|
283
|
-
case "end":
|
|
284
|
-
return _context17.stop();
|
|
285
|
-
}
|
|
286
|
-
}, _callee4);
|
|
184
|
+
async function waitForDeploymentPipelinePrompt(_ref7) {
|
|
185
|
+
let circleCiApis = _ref7.circleCiApis,
|
|
186
|
+
branch = _ref7.branch,
|
|
187
|
+
pagesForPipelineSelection = _ref7.pagesForPipelineSelection,
|
|
188
|
+
debug = _ref7.debug;
|
|
189
|
+
const deploymentPipelines = await collectDeploymentPipelines({
|
|
190
|
+
branch,
|
|
191
|
+
pagesForPipelineSelection,
|
|
192
|
+
circleCiApis,
|
|
193
|
+
debug
|
|
194
|
+
});
|
|
195
|
+
const deploymentPipelinePrompt = await prompts__default["default"](
|
|
196
|
+
// @ts-expect-error prompts is not typed
|
|
197
|
+
promptOptions.deploymentPipelineSelect({
|
|
198
|
+
deploymentPipelines
|
|
287
199
|
}));
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
200
|
+
const revision = deploymentPipelinePrompt.deploymentPipeline.vcs.revision;
|
|
201
|
+
if (!revision) {
|
|
202
|
+
console.log('☝️ Please select a revision or specify it as a CLI argument via `--build-revision`.');
|
|
203
|
+
throw new Error('No revision specified.');
|
|
204
|
+
}
|
|
205
|
+
return deploymentPipelinePrompt.deploymentPipeline;
|
|
292
206
|
}
|
|
293
|
-
function
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
// @ts-expect-error prompts is not typed
|
|
302
|
-
promptOptions.deploymentConfirmation({
|
|
303
|
-
approvalJob: approvalJob,
|
|
304
|
-
revision: revision
|
|
305
|
-
})));
|
|
306
|
-
case 2:
|
|
307
|
-
case "end":
|
|
308
|
-
return _context18.stop();
|
|
309
|
-
}
|
|
310
|
-
}, _callee5);
|
|
207
|
+
async function waitForConfirmationPrompt(_ref8) {
|
|
208
|
+
let approvalJob = _ref8.approvalJob,
|
|
209
|
+
revision = _ref8.revision;
|
|
210
|
+
return prompts__default["default"](
|
|
211
|
+
// @ts-expect-error prompts is not typed
|
|
212
|
+
promptOptions.deploymentConfirmation({
|
|
213
|
+
approvalJob,
|
|
214
|
+
revision
|
|
311
215
|
}));
|
|
312
|
-
return _waitForConfirmationPrompt.apply(this, arguments);
|
|
313
216
|
}
|
|
314
217
|
function getJobUrl(_ref9) {
|
|
315
|
-
var
|
|
316
|
-
|
|
218
|
+
var _context11, _context12, _context13;
|
|
219
|
+
let pipelineNumber = _ref9.pipelineNumber,
|
|
317
220
|
workflowId = _ref9.workflowId,
|
|
318
221
|
jobNumber = _ref9.jobNumber,
|
|
319
222
|
projectName = _ref9.projectName;
|
|
320
|
-
return _concatInstanceProperty__default["default"](
|
|
223
|
+
return _concatInstanceProperty__default["default"](_context11 = _concatInstanceProperty__default["default"](_context12 = _concatInstanceProperty__default["default"](_context13 = "https://app.circleci.com/pipelines/github/commercetools/".concat(projectName, "/")).call(_context13, pipelineNumber, "/workflows/")).call(_context12, workflowId, "/jobs/")).call(_context11, jobNumber);
|
|
321
224
|
}
|
|
322
225
|
function isNonScheduledPipeline(pipeline) {
|
|
323
226
|
return pipeline.trigger.type !== 'schedule' && pipeline.trigger.type !== 'scheduled_pipeline';
|
|
@@ -325,458 +228,274 @@ function isNonScheduledPipeline(pipeline) {
|
|
|
325
228
|
function isNonErroredPipeline(pipeline) {
|
|
326
229
|
return pipeline.state !== 'errored';
|
|
327
230
|
}
|
|
328
|
-
function waitForDeploymentJobNumber(
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
applicationDeploymentJob = _findInstanceProperty__default["default"](_context19 = jobs.items).call(_context19, function (job) {
|
|
356
|
-
return job.name === deploymentJob;
|
|
357
|
-
});
|
|
358
|
-
if (!(!applicationDeploymentJob || applicationDeploymentJob.status === 'blocked')) {
|
|
359
|
-
_context20.next = 7;
|
|
360
|
-
break;
|
|
361
|
-
}
|
|
362
|
-
throw new Error('Deployment job not yet running. Retrying.');
|
|
363
|
-
case 7:
|
|
364
|
-
return _context20.abrupt("return", applicationDeploymentJob.job_number);
|
|
365
|
-
case 8:
|
|
366
|
-
case "end":
|
|
367
|
-
return _context20.stop();
|
|
368
|
-
}
|
|
369
|
-
}, _callee6);
|
|
370
|
-
}));
|
|
371
|
-
return function fetchDeploymentJobNumber() {
|
|
372
|
-
return _ref12.apply(this, arguments);
|
|
373
|
-
};
|
|
374
|
-
}();
|
|
375
|
-
_context22.next = 5;
|
|
376
|
-
return pRetry__default["default"](fetchDeploymentJobNumber, {
|
|
377
|
-
onFailedAttempt: function onFailedAttempt(error) {
|
|
378
|
-
var _context21;
|
|
379
|
-
console.log(_concatInstanceProperty__default["default"](_context21 = "\uD83D\uDD04 Trying to find deployment job. Attempt ".concat(error.attemptNumber, " with ")).call(_context21, error.retriesLeft, " retries left."));
|
|
380
|
-
},
|
|
381
|
-
retries: 10
|
|
382
|
-
});
|
|
383
|
-
case 5:
|
|
384
|
-
deploymentJobNumber = _context22.sent;
|
|
385
|
-
return _context22.abrupt("return", deploymentJobNumber);
|
|
386
|
-
case 7:
|
|
387
|
-
case "end":
|
|
388
|
-
return _context22.stop();
|
|
389
|
-
}
|
|
390
|
-
}, _callee7);
|
|
391
|
-
}));
|
|
392
|
-
return _waitForDeploymentJobNumber.apply(this, arguments);
|
|
231
|
+
async function waitForDeploymentJobNumber(_ref10, _ref11) {
|
|
232
|
+
let workflowId = _ref10.workflowId,
|
|
233
|
+
deploymentJob = _ref10.deploymentJob,
|
|
234
|
+
circleCiApis = _ref10.circleCiApis;
|
|
235
|
+
let debug = _ref11.debug;
|
|
236
|
+
const fetchDeploymentJobNumber = async () => {
|
|
237
|
+
var _context14;
|
|
238
|
+
const jobsRequest = circleCiApis.jobs({
|
|
239
|
+
workflowId
|
|
240
|
+
});
|
|
241
|
+
const jobs = await jobsRequest.execute({
|
|
242
|
+
debug
|
|
243
|
+
});
|
|
244
|
+
const applicationDeploymentJob = _findInstanceProperty__default["default"](_context14 = jobs.items).call(_context14, job => job.name === deploymentJob);
|
|
245
|
+
if (!applicationDeploymentJob || applicationDeploymentJob.status === 'blocked') {
|
|
246
|
+
throw new Error('Deployment job not yet running. Retrying.');
|
|
247
|
+
}
|
|
248
|
+
return applicationDeploymentJob.job_number;
|
|
249
|
+
};
|
|
250
|
+
const deploymentJobNumber = await pRetry__default["default"](fetchDeploymentJobNumber, {
|
|
251
|
+
onFailedAttempt: error => {
|
|
252
|
+
var _context15;
|
|
253
|
+
console.log(_concatInstanceProperty__default["default"](_context15 = "\uD83D\uDD04 Trying to find deployment job. Attempt ".concat(error.attemptNumber, " with ")).call(_context15, error.retriesLeft, " retries left."));
|
|
254
|
+
},
|
|
255
|
+
retries: 10
|
|
256
|
+
});
|
|
257
|
+
return deploymentJobNumber;
|
|
393
258
|
}
|
|
394
259
|
|
|
395
|
-
function approve(
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
var _config$
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
_context8.next = 48;
|
|
504
|
-
break;
|
|
505
|
-
}
|
|
506
|
-
_context8.next = 47;
|
|
507
|
-
return waitForConfirmationPrompt({
|
|
508
|
-
approvalJob: approvalJob,
|
|
509
|
-
revision: deploymentPipeline.vcs.revision
|
|
510
|
-
});
|
|
511
|
-
case 47:
|
|
512
|
-
confirmationPrompt = _context8.sent;
|
|
513
|
-
case 48:
|
|
514
|
-
if (!(cliFlags.yes || (_confirmationPrompt = confirmationPrompt) !== null && _confirmationPrompt !== void 0 && _confirmationPrompt.confirmed)) {
|
|
515
|
-
_context8.next = 71;
|
|
516
|
-
break;
|
|
517
|
-
}
|
|
518
|
-
if (cliFlags.dryRun) {
|
|
519
|
-
console.log("\uD83D\uDE4A Not approving deployment job due to dry run.");
|
|
520
|
-
} else {
|
|
521
|
-
console.log("\u2139\uFE0F Approving deployment job.");
|
|
522
|
-
}
|
|
523
|
-
approvalRequest = circleCiApis.approve({
|
|
524
|
-
workflowId: workflowId,
|
|
525
|
-
approvalRequestId: applicationApprovalJobId
|
|
526
|
-
});
|
|
527
|
-
_context8.next = 53;
|
|
528
|
-
return approvalRequest.execute({
|
|
529
|
-
debug: cliFlags.debug,
|
|
530
|
-
skip: cliFlags.dryRun
|
|
531
|
-
});
|
|
532
|
-
case 53:
|
|
533
|
-
if (!cliFlags.yes) {
|
|
534
|
-
_context8.next = 57;
|
|
535
|
-
break;
|
|
536
|
-
}
|
|
537
|
-
console.log("\u2139\uFE0F Skipping determining deployment job approved by ".concat(approvalJob, " due to '--yes' flag. Please check CircleCI manually."));
|
|
538
|
-
_context8.next = 69;
|
|
539
|
-
break;
|
|
540
|
-
case 57:
|
|
541
|
-
if (!cliFlags.dryRun) {
|
|
542
|
-
_context8.next = 61;
|
|
543
|
-
break;
|
|
544
|
-
}
|
|
545
|
-
console.log("\u270C\uFE0F Dry running hence could not determine deployment job approved by ".concat(approvalJob, "."));
|
|
546
|
-
_context8.next = 69;
|
|
547
|
-
break;
|
|
548
|
-
case 61:
|
|
549
|
-
if (!deploymentJob) {
|
|
550
|
-
_context8.next = 68;
|
|
551
|
-
break;
|
|
552
|
-
}
|
|
553
|
-
_context8.next = 64;
|
|
554
|
-
return waitForDeploymentJobNumber({
|
|
555
|
-
workflowId: workflowId,
|
|
556
|
-
deploymentJob: deploymentJob,
|
|
557
|
-
circleCiApis: circleCiApis
|
|
558
|
-
}, {
|
|
559
|
-
debug: cliFlags.debug,
|
|
560
|
-
dryRun: cliFlags.dryRun,
|
|
561
|
-
yes: cliFlags.yes
|
|
562
|
-
});
|
|
563
|
-
case 64:
|
|
564
|
-
deploymentJobNumber = _context8.sent;
|
|
565
|
-
console.log(_concatInstanceProperty__default["default"](_context6 = _concatInstanceProperty__default["default"](_context7 = "\uD83D\uDE4C The deployment via ".concat(approvalJob, " at revision ")).call(_context7, deploymentPipeline.vcs.revision, " is running at: ")).call(_context6, getJobUrl({
|
|
566
|
-
projectName: config.CircleCI.projectName,
|
|
567
|
-
pipelineNumber: deploymentPipeline.number,
|
|
568
|
-
workflowId: workflowId,
|
|
569
|
-
jobNumber: deploymentJobNumber
|
|
570
|
-
})));
|
|
571
|
-
_context8.next = 69;
|
|
572
|
-
break;
|
|
573
|
-
case 68:
|
|
574
|
-
console.log("\u2139\uFE0F Skipping determining deployment job as no '--deployment-job' name to wait for was passed. Please check CircleCI manually.");
|
|
575
|
-
case 69:
|
|
576
|
-
_context8.next = 72;
|
|
577
|
-
break;
|
|
578
|
-
case 71:
|
|
579
|
-
console.log("\u2139\uFE0F Not approving deployment job. Confirm the prompt or use '--yes' option.");
|
|
580
|
-
case 72:
|
|
581
|
-
case "end":
|
|
582
|
-
return _context8.stop();
|
|
583
|
-
}
|
|
584
|
-
}, _callee);
|
|
585
|
-
}));
|
|
586
|
-
return _approve.apply(this, arguments);
|
|
260
|
+
async function approve(cliFlags, config, circleCiApis) {
|
|
261
|
+
var _config$CircleCI$pagi, _config$CircleCI$pagi2, _config$CircleCI$pagi3, _config$CircleCI$pagi4, _context2, _context3, _context5, _confirmationPrompt;
|
|
262
|
+
let approvalJob;
|
|
263
|
+
let deploymentJob;
|
|
264
|
+
if (cliFlags.deployment) {
|
|
265
|
+
var _config$deployments, _context;
|
|
266
|
+
const requestedDeployment = (_config$deployments = config.deployments) === null || _config$deployments === void 0 ? void 0 : _config$deployments[cliFlags.deployment];
|
|
267
|
+
if (!requestedDeployment) {
|
|
268
|
+
throw new Error("\u26A0\uFE0F Deployment ".concat(cliFlags.deployment, " not found in configuration. Make sure it exists."));
|
|
269
|
+
}
|
|
270
|
+
approvalJob = requestedDeployment.jobs.approval;
|
|
271
|
+
deploymentJob = requestedDeployment.jobs.deployment;
|
|
272
|
+
console.log(_concatInstanceProperty__default["default"](_context = "\u2139\uFE0F Approving requested deployment ".concat(cliFlags.deployment, " with approval job ")).call(_context, approvalJob, "."));
|
|
273
|
+
} else {
|
|
274
|
+
approvalJob = cliFlags.approvalJob;
|
|
275
|
+
deploymentJob = cliFlags.deploymentJob;
|
|
276
|
+
console.log("\u2139\uFE0F Approving with approval job ".concat(approvalJob, "."));
|
|
277
|
+
}
|
|
278
|
+
const deploymentPipeline = cliFlags.yes ? await paginateToDeploymentPipeline({
|
|
279
|
+
circleCiApis,
|
|
280
|
+
buildRevision: cliFlags.buildRevision,
|
|
281
|
+
branch: cliFlags.branch,
|
|
282
|
+
debug: cliFlags.debug,
|
|
283
|
+
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
|
|
284
|
+
}) : await waitForDeploymentPipelinePrompt({
|
|
285
|
+
branch: cliFlags.branch,
|
|
286
|
+
circleCiApis,
|
|
287
|
+
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,
|
|
288
|
+
debug: cliFlags.debug
|
|
289
|
+
});
|
|
290
|
+
if (!deploymentPipeline) {
|
|
291
|
+
throw new Error("\u26A0\uFE0F No workflow called ".concat(config.CircleCI.deploymentWorkflowName, " found in any pipeline for deployment."));
|
|
292
|
+
}
|
|
293
|
+
console.log("\u2139\uFE0F Found pipeline for deployment with revision ".concat(deploymentPipeline.vcs.revision, "."));
|
|
294
|
+
const workflowsRequest = circleCiApis.workflows({
|
|
295
|
+
pipelineId: deploymentPipeline.id
|
|
296
|
+
});
|
|
297
|
+
const workflows = await workflowsRequest.execute({
|
|
298
|
+
debug: cliFlags.debug
|
|
299
|
+
});
|
|
300
|
+
const buildAndDeployWorkflow = _findInstanceProperty__default["default"](_context2 = workflows.items).call(_context2, workflow => workflow.name === config.CircleCI.deploymentWorkflowName);
|
|
301
|
+
if (!buildAndDeployWorkflow) {
|
|
302
|
+
throw new Error("\u26A0\uFE0F No workflow called ".concat(config.CircleCI.deploymentWorkflowName, " found for deployment."));
|
|
303
|
+
}
|
|
304
|
+
const workflowId = buildAndDeployWorkflow.id;
|
|
305
|
+
console.log("\u2139\uFE0F Found workflow to build and deploy with id ".concat(workflowId, "."));
|
|
306
|
+
const jobsRequest = circleCiApis.jobs({
|
|
307
|
+
workflowId
|
|
308
|
+
});
|
|
309
|
+
const jobs = await jobsRequest.execute({
|
|
310
|
+
debug: cliFlags.debug
|
|
311
|
+
});
|
|
312
|
+
console.log("\u2139\uFE0F Found jobs for workflow.");
|
|
313
|
+
const applicationApprovalJob = _findInstanceProperty__default["default"](_context3 = jobs.items).call(_context3, job => job.name === approvalJob);
|
|
314
|
+
const applicationApprovalJobId = applicationApprovalJob === null || applicationApprovalJob === void 0 ? void 0 : applicationApprovalJob.id;
|
|
315
|
+
if (!applicationApprovalJobId) {
|
|
316
|
+
var _context4;
|
|
317
|
+
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."));
|
|
318
|
+
}
|
|
319
|
+
console.log(_concatInstanceProperty__default["default"](_context5 = "\u2139\uFE0F Found deployment approval job named ".concat(approvalJob, " with id ")).call(_context5, applicationApprovalJobId, "."));
|
|
320
|
+
let confirmationPrompt;
|
|
321
|
+
if (!cliFlags.yes) {
|
|
322
|
+
confirmationPrompt = await waitForConfirmationPrompt({
|
|
323
|
+
approvalJob: approvalJob,
|
|
324
|
+
revision: deploymentPipeline.vcs.revision
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
if (cliFlags.yes || (_confirmationPrompt = confirmationPrompt) !== null && _confirmationPrompt !== void 0 && _confirmationPrompt.confirmed) {
|
|
328
|
+
if (cliFlags.dryRun) {
|
|
329
|
+
console.log("\uD83D\uDE4A Not approving deployment job due to dry run.");
|
|
330
|
+
} else {
|
|
331
|
+
console.log("\u2139\uFE0F Approving deployment job.");
|
|
332
|
+
}
|
|
333
|
+
const approvalRequest = circleCiApis.approve({
|
|
334
|
+
workflowId,
|
|
335
|
+
approvalRequestId: applicationApprovalJobId
|
|
336
|
+
});
|
|
337
|
+
await approvalRequest.execute({
|
|
338
|
+
debug: cliFlags.debug,
|
|
339
|
+
skip: cliFlags.dryRun
|
|
340
|
+
});
|
|
341
|
+
if (cliFlags.yes) {
|
|
342
|
+
console.log("\u2139\uFE0F Skipping determining deployment job approved by ".concat(approvalJob, " due to '--yes' flag. Please check CircleCI manually."));
|
|
343
|
+
} else if (cliFlags.dryRun) {
|
|
344
|
+
console.log("\u270C\uFE0F Dry running hence could not determine deployment job approved by ".concat(approvalJob, "."));
|
|
345
|
+
} else if (deploymentJob) {
|
|
346
|
+
var _context6, _context7;
|
|
347
|
+
const deploymentJobNumber = await waitForDeploymentJobNumber({
|
|
348
|
+
workflowId,
|
|
349
|
+
deploymentJob,
|
|
350
|
+
circleCiApis
|
|
351
|
+
}, {
|
|
352
|
+
debug: cliFlags.debug,
|
|
353
|
+
dryRun: cliFlags.dryRun,
|
|
354
|
+
yes: cliFlags.yes
|
|
355
|
+
});
|
|
356
|
+
console.log(_concatInstanceProperty__default["default"](_context6 = _concatInstanceProperty__default["default"](_context7 = "\uD83D\uDE4C The deployment via ".concat(approvalJob, " at revision ")).call(_context7, deploymentPipeline.vcs.revision, " is running at: ")).call(_context6, getJobUrl({
|
|
357
|
+
projectName: config.CircleCI.projectName,
|
|
358
|
+
pipelineNumber: deploymentPipeline.number,
|
|
359
|
+
workflowId,
|
|
360
|
+
jobNumber: deploymentJobNumber
|
|
361
|
+
})));
|
|
362
|
+
} else {
|
|
363
|
+
console.log("\u2139\uFE0F Skipping determining deployment job as no '--deployment-job' name to wait for was passed. Please check CircleCI manually.");
|
|
364
|
+
}
|
|
365
|
+
} else {
|
|
366
|
+
console.log("\u2139\uFE0F Not approving deployment job. Confirm the prompt or use '--yes' option.");
|
|
367
|
+
}
|
|
587
368
|
}
|
|
588
369
|
|
|
589
|
-
function processCircleCiResponse(
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
return response.json();
|
|
605
|
-
case 4:
|
|
606
|
-
errorJson = _context6.sent;
|
|
607
|
-
if (errorJson.message.match(/job already approved/i)) {
|
|
608
|
-
console.log('ℹ️ Deployment job is already approved.');
|
|
609
|
-
process.exit(0);
|
|
610
|
-
}
|
|
611
|
-
_context6.next = 10;
|
|
612
|
-
break;
|
|
613
|
-
case 8:
|
|
614
|
-
_context6.prev = 8;
|
|
615
|
-
_context6.t0 = _context6["catch"](1);
|
|
616
|
-
case 10:
|
|
617
|
-
_context6.next = 12;
|
|
618
|
-
return response.text();
|
|
619
|
-
case 12:
|
|
620
|
-
errorText = _context6.sent;
|
|
621
|
-
throw new Error(_concatInstanceProperty__default["default"](_context4 = _concatInstanceProperty__default["default"](_context5 = "".concat(response.status, ": Network response was not ok.\n\n Status text is ")).call(_context5, response.statusText, " and text is ")).call(_context4, errorText, "."));
|
|
622
|
-
case 14:
|
|
623
|
-
return _context6.abrupt("return", response.json());
|
|
624
|
-
case 15:
|
|
625
|
-
case "end":
|
|
626
|
-
return _context6.stop();
|
|
370
|
+
async function processCircleCiResponse(response) {
|
|
371
|
+
if (!response.ok) {
|
|
372
|
+
var _context, _context2;
|
|
373
|
+
/**
|
|
374
|
+
* NOTE:
|
|
375
|
+
* Trying to handle known but undocumented responses of the CircleCI API.
|
|
376
|
+
*
|
|
377
|
+
* 1. Message: Already approved job
|
|
378
|
+
* Deployment was already triggered manually or by train the day before.
|
|
379
|
+
*/
|
|
380
|
+
try {
|
|
381
|
+
const errorJson = await response.json();
|
|
382
|
+
if (errorJson.message.match(/job already approved/i)) {
|
|
383
|
+
console.log('ℹ️ Deployment job is already approved.');
|
|
384
|
+
process.exit(0);
|
|
627
385
|
}
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
|
|
386
|
+
} catch (e) {
|
|
387
|
+
// ignore
|
|
388
|
+
}
|
|
389
|
+
const errorText = await response.text();
|
|
390
|
+
throw new Error(_concatInstanceProperty__default["default"](_context = _concatInstanceProperty__default["default"](_context2 = "".concat(response.status, ": Network response was not ok.\n\n Status text is ")).call(_context2, response.statusText, " and text is ")).call(_context, errorText, "."));
|
|
391
|
+
}
|
|
392
|
+
return response.json();
|
|
631
393
|
}
|
|
632
394
|
function createCircleCiClient(_ref) {
|
|
633
|
-
|
|
395
|
+
let projectName = _ref.projectName,
|
|
634
396
|
apiBaseUrl = _ref.apiBaseUrl;
|
|
635
|
-
function
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
_ref8,
|
|
650
|
-
key,
|
|
651
|
-
value,
|
|
652
|
-
response,
|
|
653
|
-
processedCircleCiResponse,
|
|
654
|
-
_args = arguments;
|
|
655
|
-
return _regeneratorRuntime__default["default"].wrap(function _callee$(_context3) {
|
|
656
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
657
|
-
case 0:
|
|
658
|
-
_ref6 = _args.length > 1 && _args[1] !== undefined ? _args[1] : {}, skip = _ref6.skip, debug = _ref6.debug;
|
|
659
|
-
url = _concatInstanceProperty__default["default"](_context2 = "".concat(apiBaseUrl)).call(_context2, api.url);
|
|
660
|
-
if (api.params && api.method === 'GET') {
|
|
661
|
-
urlSearchParams = new _URLSearchParams__default["default"]();
|
|
662
|
-
for (_i = 0, _Object$entries = _Object$entries2__default["default"](api.params); _i < _Object$entries.length; _i++) {
|
|
663
|
-
_ref7 = _Object$entries[_i];
|
|
664
|
-
_ref8 = _slicedToArray(_ref7, 2);
|
|
665
|
-
key = _ref8[0];
|
|
666
|
-
value = _ref8[1];
|
|
667
|
-
if (value !== null && value !== undefined) {
|
|
668
|
-
urlSearchParams.append(key, value);
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
url += "?".concat(urlSearchParams.toString());
|
|
672
|
-
}
|
|
673
|
-
if (!skip) {
|
|
674
|
-
_context3.next = 6;
|
|
675
|
-
break;
|
|
676
|
-
}
|
|
677
|
-
if (debug) {
|
|
678
|
-
console.log("\uD83C\uDFED Skipping CircleCI call API at: ".concat(url, "."));
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
// @ts-expect-error
|
|
682
|
-
return _context3.abrupt("return", _Promise__default["default"].resolve());
|
|
683
|
-
case 6:
|
|
684
|
-
if (debug) {
|
|
685
|
-
console.log("\uD83C\uDFED Calling CircleCI API at: ".concat(url, "."));
|
|
686
|
-
}
|
|
687
|
-
_context3.prev = 7;
|
|
688
|
-
_context3.next = 10;
|
|
689
|
-
return fetch__default["default"](url, {
|
|
690
|
-
headers: api.headers,
|
|
691
|
-
method: api.method,
|
|
692
|
-
body: api.method === 'POST' ? _JSON$stringify__default["default"](api.params) : undefined
|
|
693
|
-
});
|
|
694
|
-
case 10:
|
|
695
|
-
response = _context3.sent;
|
|
696
|
-
_context3.next = 13;
|
|
697
|
-
return processCircleCiResponse(response);
|
|
698
|
-
case 13:
|
|
699
|
-
processedCircleCiResponse = _context3.sent;
|
|
700
|
-
return _context3.abrupt("return", processedCircleCiResponse);
|
|
701
|
-
case 17:
|
|
702
|
-
_context3.prev = 17;
|
|
703
|
-
_context3.t0 = _context3["catch"](7);
|
|
704
|
-
console.log("\u26A0\uFE0F Calling CircleCI API at: ".concat(url, " failed."));
|
|
705
|
-
throw _context3.t0;
|
|
706
|
-
case 21:
|
|
707
|
-
case "end":
|
|
708
|
-
return _context3.stop();
|
|
397
|
+
async function execute(api) {
|
|
398
|
+
var _context3;
|
|
399
|
+
let _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
400
|
+
skip = _ref2.skip,
|
|
401
|
+
debug = _ref2.debug;
|
|
402
|
+
let url = _concatInstanceProperty__default["default"](_context3 = "".concat(apiBaseUrl)).call(_context3, api.url);
|
|
403
|
+
if (api.params && api.method === 'GET') {
|
|
404
|
+
const urlSearchParams = new _URLSearchParams__default["default"]();
|
|
405
|
+
for (const _ref3 of _Object$entries__default["default"](api.params)) {
|
|
406
|
+
var _ref4 = _slicedToArray(_ref3, 2);
|
|
407
|
+
const key = _ref4[0];
|
|
408
|
+
const value = _ref4[1];
|
|
409
|
+
if (value !== null && value !== undefined) {
|
|
410
|
+
urlSearchParams.append(key, value);
|
|
709
411
|
}
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
|
|
412
|
+
}
|
|
413
|
+
url += "?".concat(urlSearchParams.toString());
|
|
414
|
+
}
|
|
415
|
+
if (skip) {
|
|
416
|
+
if (debug) {
|
|
417
|
+
console.log("\uD83C\uDFED Skipping CircleCI call API at: ".concat(url, "."));
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// @ts-expect-error
|
|
421
|
+
return _Promise__default["default"].resolve();
|
|
422
|
+
}
|
|
423
|
+
if (debug) {
|
|
424
|
+
console.log("\uD83C\uDFED Calling CircleCI API at: ".concat(url, "."));
|
|
425
|
+
}
|
|
426
|
+
try {
|
|
427
|
+
const response = await fetch__default["default"](url, {
|
|
428
|
+
headers: api.headers,
|
|
429
|
+
method: api.method,
|
|
430
|
+
body: api.method === 'POST' ? _JSON$stringify__default["default"](api.params) : undefined
|
|
431
|
+
});
|
|
432
|
+
const processedCircleCiResponse = await processCircleCiResponse(response);
|
|
433
|
+
return processedCircleCiResponse;
|
|
434
|
+
} catch (error) {
|
|
435
|
+
console.log("\u26A0\uFE0F Calling CircleCI API at: ".concat(url, " failed."));
|
|
436
|
+
throw error;
|
|
437
|
+
}
|
|
713
438
|
}
|
|
714
439
|
return {
|
|
715
|
-
pipelines: function
|
|
716
|
-
|
|
717
|
-
pageToken =
|
|
718
|
-
|
|
719
|
-
projectSlug =
|
|
720
|
-
|
|
721
|
-
branch =
|
|
440
|
+
pipelines: function () {
|
|
441
|
+
let _ref5 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
442
|
+
pageToken = _ref5.pageToken,
|
|
443
|
+
_ref5$projectSlug = _ref5.projectSlug,
|
|
444
|
+
projectSlug = _ref5$projectSlug === void 0 ? "gh/commercetools/".concat(projectName) : _ref5$projectSlug,
|
|
445
|
+
_ref5$branch = _ref5.branch,
|
|
446
|
+
branch = _ref5$branch === void 0 ? 'main' : _ref5$branch;
|
|
722
447
|
return {
|
|
723
|
-
execute:
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
}, options);
|
|
737
|
-
}
|
|
448
|
+
execute: options => execute({
|
|
449
|
+
url: "/project/".concat(projectSlug, "/pipeline"),
|
|
450
|
+
headers: {
|
|
451
|
+
'Content-Type': 'application/json',
|
|
452
|
+
// The CLI throws if this is not present on environment
|
|
453
|
+
'Circle-Token': process.env.CIRCLE_TOKEN
|
|
454
|
+
},
|
|
455
|
+
method: 'GET',
|
|
456
|
+
params: {
|
|
457
|
+
branch,
|
|
458
|
+
'page-token': pageToken
|
|
459
|
+
}
|
|
460
|
+
}, options)
|
|
738
461
|
};
|
|
739
462
|
},
|
|
740
|
-
workflows:
|
|
741
|
-
|
|
463
|
+
workflows: _ref6 => {
|
|
464
|
+
let pipelineId = _ref6.pipelineId;
|
|
742
465
|
return {
|
|
743
|
-
execute:
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
}, options);
|
|
753
|
-
}
|
|
466
|
+
execute: options => execute({
|
|
467
|
+
url: "/pipeline/".concat(pipelineId, "/workflow"),
|
|
468
|
+
headers: {
|
|
469
|
+
'Content-Type': 'application/json',
|
|
470
|
+
// The CLI throws if this is not present on environment
|
|
471
|
+
'Circle-Token': process.env.CIRCLE_TOKEN
|
|
472
|
+
},
|
|
473
|
+
method: 'GET'
|
|
474
|
+
}, options)
|
|
754
475
|
};
|
|
755
476
|
},
|
|
756
|
-
jobs:
|
|
757
|
-
|
|
477
|
+
jobs: _ref7 => {
|
|
478
|
+
let workflowId = _ref7.workflowId;
|
|
758
479
|
return {
|
|
759
|
-
execute:
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
}, options);
|
|
769
|
-
}
|
|
480
|
+
execute: options => execute({
|
|
481
|
+
url: "/workflow/".concat(workflowId, "/job"),
|
|
482
|
+
headers: {
|
|
483
|
+
'Content-Type': 'application/json',
|
|
484
|
+
// The CLI throws if this is not present on environment
|
|
485
|
+
'Circle-Token': process.env.CIRCLE_TOKEN
|
|
486
|
+
},
|
|
487
|
+
method: 'GET'
|
|
488
|
+
}, options)
|
|
770
489
|
};
|
|
771
490
|
},
|
|
772
|
-
approve:
|
|
773
|
-
|
|
774
|
-
approvalRequestId =
|
|
491
|
+
approve: _ref8 => {
|
|
492
|
+
let workflowId = _ref8.workflowId,
|
|
493
|
+
approvalRequestId = _ref8.approvalRequestId;
|
|
775
494
|
return {
|
|
776
|
-
execute:
|
|
777
|
-
var
|
|
778
|
-
return
|
|
779
|
-
url: _concatInstanceProperty__default["default"](
|
|
495
|
+
execute: options => {
|
|
496
|
+
var _context4;
|
|
497
|
+
return execute({
|
|
498
|
+
url: _concatInstanceProperty__default["default"](_context4 = "/workflow/".concat(workflowId, "/approve/")).call(_context4, approvalRequestId, " "),
|
|
780
499
|
headers: {
|
|
781
500
|
'Content-Type': 'application/json',
|
|
782
501
|
// The CLI throws if this is not present on environment
|
|
@@ -790,53 +509,41 @@ function createCircleCiClient(_ref) {
|
|
|
790
509
|
};
|
|
791
510
|
}
|
|
792
511
|
|
|
793
|
-
function run() {
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
process.exit(0);
|
|
827
|
-
}
|
|
828
|
-
cliCommand = cliCommands[0];
|
|
829
|
-
if (cliFlags['dry-run']) {
|
|
830
|
-
console.log("\n \uD83D\uDE4A Do not worry. This is a dry run!\n ");
|
|
831
|
-
}
|
|
832
|
-
console.log("\uD83C\uDFC3 Running ".concat(cliCommand, " command"));
|
|
833
|
-
_context2.t0 = cliCommand;
|
|
834
|
-
_context2.next = _context2.t0 === 'approve' ? 15 : 19;
|
|
835
|
-
break;
|
|
836
|
-
case 15:
|
|
512
|
+
async function run() {
|
|
513
|
+
const config = await loadConfig();
|
|
514
|
+
throwIfConfigurationLacksRequiredValues(config);
|
|
515
|
+
const circleCiApis = createCircleCiClient({
|
|
516
|
+
projectName: config.CircleCI.projectName,
|
|
517
|
+
apiBaseUrl: config.CircleCI.apiBaseUrl
|
|
518
|
+
});
|
|
519
|
+
try {
|
|
520
|
+
var _context;
|
|
521
|
+
const cliFlags = mri__default["default"](_sliceInstanceProperty__default["default"](_context = process.argv).call(_context, 2), {
|
|
522
|
+
alias: {
|
|
523
|
+
help: ['h']
|
|
524
|
+
},
|
|
525
|
+
boolean: ['dry-run', 'debug', 'yes'],
|
|
526
|
+
default: {
|
|
527
|
+
branch: 'main'
|
|
528
|
+
}
|
|
529
|
+
});
|
|
530
|
+
const cliCommands = cliFlags._;
|
|
531
|
+
if (cliCommands.length === 0 ||
|
|
532
|
+
// @ts-expect-error mri is not typed for the help command.
|
|
533
|
+
cliCommands.help && cliCommands.length === 0) {
|
|
534
|
+
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");
|
|
535
|
+
process.exit(0);
|
|
536
|
+
}
|
|
537
|
+
const cliCommand = cliCommands[0];
|
|
538
|
+
if (cliFlags['dry-run']) {
|
|
539
|
+
console.log("\n \uD83D\uDE4A Do not worry. This is a dry run!\n ");
|
|
540
|
+
}
|
|
541
|
+
console.log("\uD83C\uDFC3 Running ".concat(cliCommand, " command"));
|
|
542
|
+
switch (cliCommand) {
|
|
543
|
+
case 'approve':
|
|
544
|
+
{
|
|
837
545
|
throwIfRequiredEnvironmentVariableIsUnset(['CIRCLE_TOKEN']);
|
|
838
|
-
|
|
839
|
-
return approve({
|
|
546
|
+
await approve({
|
|
840
547
|
deployment: cliFlags.deployment,
|
|
841
548
|
branch: cliFlags.branch,
|
|
842
549
|
approvalJob: cliFlags['approval-job'],
|
|
@@ -846,25 +553,16 @@ function _run() {
|
|
|
846
553
|
debug: cliFlags.debug,
|
|
847
554
|
dryRun: cliFlags['dry-run']
|
|
848
555
|
}, config, circleCiApis);
|
|
849
|
-
case 18:
|
|
850
556
|
process.exit(0);
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
process.exit(1);
|
|
861
|
-
case 26:
|
|
862
|
-
case "end":
|
|
863
|
-
return _context2.stop();
|
|
864
|
-
}
|
|
865
|
-
}, _callee, null, [[5, 22]]);
|
|
866
|
-
}));
|
|
867
|
-
return _run.apply(this, arguments);
|
|
557
|
+
}
|
|
558
|
+
// eslint-disable-next-line no-fallthrough
|
|
559
|
+
default:
|
|
560
|
+
throw new Error("\uD83D\uDC80 Unknown command \"".concat(cliCommand, "\"."));
|
|
561
|
+
}
|
|
562
|
+
} catch (error) {
|
|
563
|
+
console.error(error);
|
|
564
|
+
process.exit(1);
|
|
565
|
+
}
|
|
868
566
|
}
|
|
869
567
|
|
|
870
568
|
exports.run = run;
|