@elaraai/e3-cloud-cli 1.1.19 → 1.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +117 -9
- package/dist/src/app-source.d.ts +40 -3
- package/dist/src/app-source.d.ts.map +1 -1
- package/dist/src/app-source.js +44 -5
- package/dist/src/app-source.js.map +1 -1
- package/dist/src/cli.js +29 -4
- package/dist/src/cli.js.map +1 -1
- package/dist/src/commands/admin.d.ts +44 -0
- package/dist/src/commands/admin.d.ts.map +1 -0
- package/dist/src/commands/admin.js +127 -0
- package/dist/src/commands/admin.js.map +1 -0
- package/dist/src/commands/app.d.ts +6 -1
- package/dist/src/commands/app.d.ts.map +1 -1
- package/dist/src/commands/app.js +508 -43
- package/dist/src/commands/app.js.map +1 -1
- package/dist/src/commands/files.d.ts +23 -3
- package/dist/src/commands/files.d.ts.map +1 -1
- package/dist/src/commands/files.js +136 -20
- package/dist/src/commands/files.js.map +1 -1
- package/dist/src/commands/release.d.ts.map +1 -1
- package/dist/src/commands/release.js +53 -19
- package/dist/src/commands/release.js.map +1 -1
- package/dist/src/files-local.d.ts +73 -3
- package/dist/src/files-local.d.ts.map +1 -1
- package/dist/src/files-local.js +239 -14
- package/dist/src/files-local.js.map +1 -1
- package/dist/src/files-push.d.ts +12 -0
- package/dist/src/files-push.d.ts.map +1 -1
- package/dist/src/files-push.js +45 -5
- package/dist/src/files-push.js.map +1 -1
- package/dist/src/package-compare.d.ts +26 -0
- package/dist/src/package-compare.d.ts.map +1 -1
- package/dist/src/package-compare.js +28 -9
- package/dist/src/package-compare.js.map +1 -1
- package/package.json +9 -9
package/dist/src/commands/app.js
CHANGED
|
@@ -9,7 +9,10 @@
|
|
|
9
9
|
* a workspace as its own deployable. `build` makes a bundle of an app's
|
|
10
10
|
* source (the app, and the package it was built against); `deploy` takes
|
|
11
11
|
* bundles, or sources, imports their package into the repository when it is
|
|
12
|
-
* not there
|
|
12
|
+
* not there (for the platform's next e3, `--for-platform`, hands it to the
|
|
13
|
+
* platform to hold for its move instead: the e3 the platform runs
|
|
14
|
+
* would refuse an import of a package the next e3 exported), uploads each
|
|
15
|
+
* app object and deploys them together, printing
|
|
13
16
|
* every problem when the deploy is refused; `list`, `versions` and `remove`
|
|
14
17
|
* read and remove what is deployed (a protected workspace, one with a
|
|
15
18
|
* staging, refuses a deploy and a removal unless an admin forces it with
|
|
@@ -29,16 +32,23 @@
|
|
|
29
32
|
* package back over it: nothing on the platform side can refuse that yet, so
|
|
30
33
|
* the CLI says it loudly and exits non-zero. So an app whose package the next
|
|
31
34
|
* e3 exports to other bytes is still staged for it on the package its
|
|
32
|
-
* workspace runs, on any release of the platform.
|
|
35
|
+
* workspace runs, on any release of the platform. A deployment that holds a
|
|
36
|
+
* build's own package for its move takes it with that package
|
|
37
|
+
* instead, where binding refuses it (a page reading through indexes, or a
|
|
38
|
+
* fit the checks refuse): the CLI's refusals then say so, and never to
|
|
39
|
+
* remove the app across the move; on one that does not, they say what they
|
|
40
|
+
* said before.
|
|
33
41
|
*/
|
|
34
42
|
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
35
43
|
import { dirname, resolve } from 'node:path';
|
|
36
44
|
import { StringType, decodeBeast2For, encodeBeast2For, equalFor, none, some } from '@elaraai/east';
|
|
37
45
|
import { objectGet, packageImport, packageList, workspaceGet, workspaceList } from '@elaraai/e3-api-client';
|
|
38
|
-
import { ApiError, adminAppList, appDeploy, appDeployWait, appGet, appList, repositoryAppList, appDeployRefusedText, appRemove, appsDeploy, appUpload, appVersions, platformVersions, } from '@elaraai/e3-cloud-client';
|
|
46
|
+
import { ApiError, adminAppList, appDeploy, appDeployWait, appGet, appList, repositoryAppList, appDeployRefusedText, appHoldPackage, appRemove, appRemoveStaged, appsDeploy, appUpload, appVersions, heldPackagesServed, platformVersions, } from '@elaraai/e3-cloud-client';
|
|
39
47
|
import { AppBundleType, AppType } from '@elaraai/e3-cloud-ui/types';
|
|
40
48
|
import { getValidToken } from '../credentials.js';
|
|
41
|
-
import {
|
|
49
|
+
import { samePackage } from '@elaraai/e3-cloud-types';
|
|
50
|
+
import { packageZipCheck, packageZipRef } from '@elaraai/e3-cloud-ui/check';
|
|
51
|
+
import { FIT_PROBLEMS, HOLDS_FOR_THE_MOVE, bindToWorkspacePackage, bindingChecks, bindingRefusalLines, boundRefusalLines, buildAppFromSource, carriesPackage, checksFor, holdsUnknownWords, movedDuringDeployLines, newerRelease, problemLines, taskPageLines } from '../app-source.js';
|
|
42
52
|
import { bindingDecision, zipObjects } from '../package-compare.js';
|
|
43
53
|
import { exitError, formatError, parseRepoUrl, parseWorkspaceUrl, printDateTime } from '../utils.js';
|
|
44
54
|
const decodeBundle = decodeBeast2For(AppBundleType);
|
|
@@ -98,6 +108,217 @@ async function workspacePackage(baseUrl, repo, workspace, token) {
|
|
|
98
108
|
}
|
|
99
109
|
/** What `--against-workspace` says of a workspace that runs no package. */
|
|
100
110
|
const RUNS_NO_PACKAGE = (workspace) => `${workspace} runs no package: deploy one first, or build without --against-workspace`;
|
|
111
|
+
/**
|
|
112
|
+
* Whether the deployment holds a build's own package for its move, for the
|
|
113
|
+
* words of a refusal: what it says of the way across the move. Only the
|
|
114
|
+
* definite sign that the hold route is absent (a 404 that is no JSON error)
|
|
115
|
+
* is "holds none"; any other error is said as it is, and no way is advised.
|
|
116
|
+
*/
|
|
117
|
+
async function platformHolds(baseUrl, repo, workspace, app, token) {
|
|
118
|
+
return heldPackagesServed(baseUrl, repo, workspace, app, { token }).catch((err) => ({ unknown: describe(err) }));
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* What a deploy for the platform's next e3 says on a deployment that holds no
|
|
122
|
+
* package for its move (a release from before the hold): a build prepared there
|
|
123
|
+
* runs on the package its workspace runs.
|
|
124
|
+
*/
|
|
125
|
+
async function holdsNoPackageWords(baseUrl, token, names, pkg, repo) {
|
|
126
|
+
const platform = await platformVersions(baseUrl, { token }).catch(() => null);
|
|
127
|
+
const release = platform !== null && platform.e3Cloud.type === 'some' ? `e3 cloud ${platform.e3Cloud.value},` : 'a release of e3 cloud';
|
|
128
|
+
return `${names} built against ${pkg}, which ${repo} doesn't hold. This deployment runs ${release} whose builds prepared for the next e3 run on the package their workspace runs: build against it (--against-workspace), or remove the app before the platform moves and deploy it after`;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* What a refused hold of a build's own package says, after the platform's
|
|
132
|
+
* words: what the person does about it. Nothing is held, and nothing deployed.
|
|
133
|
+
*/
|
|
134
|
+
function holdRefusalWords(err, names, pkg, repo, url, workspace) {
|
|
135
|
+
const said = describe(err);
|
|
136
|
+
const nothing = `Nothing is held for ${names}, and nothing is deployed`;
|
|
137
|
+
if (!(err instanceof ApiError))
|
|
138
|
+
return said;
|
|
139
|
+
switch (err.code) {
|
|
140
|
+
case 'package_version_conflict':
|
|
141
|
+
return `${said}\n${nothing}: give ${pkg.name} a new version in its source (it is ${pkg.version} now), build it again and deploy it. Only an admin may replace a zip held for the move instead, with --replace, and only while no build is prepared on it`;
|
|
142
|
+
case 'held_package_staged':
|
|
143
|
+
return `${said}\n${nothing}: give ${pkg.name} a new version in its source (it is ${pkg.version} now), build it again and deploy it; or remove each build prepared on the zip held, then hold it again with --replace (an admin's). ${REMOVE_PREPARED_WORDS(url)}`;
|
|
144
|
+
case 'held_packages_full': {
|
|
145
|
+
// The platform says what keeps each zip, and the steps that apply: the command's form, for a zip in use
|
|
146
|
+
const inUse = typeof err.details === 'string' && err.details.includes('remove-prepared');
|
|
147
|
+
return `${said}\n${nothing}${inUse ? `. ${REMOVE_PREPARED_WORDS(url)}: its zip is let go at once` : ''}`;
|
|
148
|
+
}
|
|
149
|
+
case 'bad_request':
|
|
150
|
+
return `${said}\n${nothing}: the bundle's package zip is not one e3 exports whole, or names a release e3 does not write. Build it again (e3-cloud app build, or deploy --from-source)`;
|
|
151
|
+
case 'invalid_name':
|
|
152
|
+
return `${said}\n${nothing}: give ${pkg.name} a shorter name or version in the source, build it again and deploy it`;
|
|
153
|
+
case 'workspace_protected':
|
|
154
|
+
return `${said}\n${nothing}: prepare the build on ${workspace}'s staging, and a release carries it here`;
|
|
155
|
+
default:
|
|
156
|
+
return said;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* What a refused deploy for the platform's next e3 says after the platform's
|
|
161
|
+
* words, of a build with a package of its own: what the person does about it.
|
|
162
|
+
* Nothing for any other refusal.
|
|
163
|
+
*/
|
|
164
|
+
function preparedRefusalWords(err, url, workspace, forPlatform, pkg) {
|
|
165
|
+
if (!(err instanceof ApiError))
|
|
166
|
+
return null;
|
|
167
|
+
// A version names one package: the repository holds another build of it
|
|
168
|
+
if (err.code === 'package_version_conflict')
|
|
169
|
+
return `Nothing is deployed: give ${pkg.name} a new version in its source (it is ${pkg.version} now) and deploy again; for the platform's next e3, the platform then holds that package for its move`;
|
|
170
|
+
if (forPlatform === null)
|
|
171
|
+
return null;
|
|
172
|
+
switch (err.code) {
|
|
173
|
+
case 'staged_package_differs':
|
|
174
|
+
return `Nothing is prepared. ${REMOVE_PREPARED_WORDS(url)}, leaving its live version as it is; then deploy ${workspace}'s apps again together`;
|
|
175
|
+
case 'package_e3_differs':
|
|
176
|
+
return `Nothing is prepared. Build the apps with e3 ${forPlatform}, giving the package a new version, and deploy them again with --for-platform ${forPlatform}`;
|
|
177
|
+
case 'package_unreadable':
|
|
178
|
+
return `Nothing is prepared. Build the apps again with e3 ${forPlatform}, giving the package a new version, and deploy them again with --for-platform ${forPlatform}`;
|
|
179
|
+
case 'held_package_gone':
|
|
180
|
+
return `${packageWords(pkg)} is no longer held, and this deploy's build is taken back (as the platform says above): deploy again, which holds it again`;
|
|
181
|
+
case 'held_package_gone_prepared':
|
|
182
|
+
return `The build may be left prepared on ${packageWords(pkg)}, which is no longer held, and the platform's move refuses it so: deploy again, which holds it again and repairs that`;
|
|
183
|
+
case 'package_files_differ':
|
|
184
|
+
return `Nothing is prepared. The move deploys the package with no client to send files: fit ${workspace}'s Files declarations to it, or build against a package that takes them as ${workspace}'s does`;
|
|
185
|
+
default:
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* How a prepared build is removed, and who may: on a workspace with a
|
|
191
|
+
* staging (protected), on its staging, which a release carries over; an
|
|
192
|
+
* admin alone forces it on the protected workspace.
|
|
193
|
+
*/
|
|
194
|
+
const REMOVE_PREPARED_WORDS = (url) => `Remove a prepared build no longer needed with e3-cloud app remove-prepared ${url} <workspace> <app> (owners and admins; on a workspace with a staging, remove it on the staging and release, or an admin forces it with --force)`;
|
|
195
|
+
/** What the CLI says after a refusal that follows a hold: the zip stays held, and how it goes. */
|
|
196
|
+
const STAYS_HELD = (pkg) => `${packageWords(pkg)} stays held for the platform's move: the hold that next needs room lets it go by itself once no prepared build names it`;
|
|
197
|
+
/**
|
|
198
|
+
* A package zip as e3 exports it whole, here: its ref, and every object of it
|
|
199
|
+
* hashed to its name, the package object among them, as the platform's hold
|
|
200
|
+
* checks it. Exits in words, holding and sending nothing, for one that does
|
|
201
|
+
* not read or verify.
|
|
202
|
+
*/
|
|
203
|
+
async function verifiedZip(zip, names) {
|
|
204
|
+
try {
|
|
205
|
+
const ref = packageZipRef(zip);
|
|
206
|
+
await packageZipCheck(zip, ref);
|
|
207
|
+
return ref;
|
|
208
|
+
}
|
|
209
|
+
catch (err) {
|
|
210
|
+
exitError(`The package zip ${names} ${names.includes(',') ? 'carry' : 'carries'} is not one e3 exports whole: ${formatError(err)}. Nothing is held, and nothing is deployed: build it again (e3-cloud app build, or deploy --from-source)`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* The checks of a build that brings its own package, here, against that
|
|
215
|
+
* package as its zip holds it, before anything is held: the project's, as its
|
|
216
|
+
* build ran them, for a source; this CLI's own for a bundle file. Where the
|
|
217
|
+
* platform's e3 cannot read a package of the next e3, these are the only
|
|
218
|
+
* checks before the platform's move, whose preflight checks the build again.
|
|
219
|
+
*
|
|
220
|
+
* @param bundles - The builds, each with its source (null for a bundle file)
|
|
221
|
+
* @param zip - Their package's zip
|
|
222
|
+
* @param pkg - Their package
|
|
223
|
+
* @returns Each app's problems, and the checks run
|
|
224
|
+
*/
|
|
225
|
+
async function checkedHere(bundles, zip, pkg) {
|
|
226
|
+
const checks = await checksFor(bundles.find((one) => one.source !== null)?.source ?? null);
|
|
227
|
+
const view = await checks.checks.readPackageView(await zipObjects(zip), pkg);
|
|
228
|
+
const problems = bundles
|
|
229
|
+
.map(({ bundle }) => ({ app: bundle.app.name, problems: checks.checks.checkApp(bundle.app, view, { e3Version: null }) }))
|
|
230
|
+
.filter((entry) => entry.problems.length > 0);
|
|
231
|
+
return { problems, checks };
|
|
232
|
+
}
|
|
233
|
+
/** The checks run here, in words: `the project's checks (@elaraai/e3-cloud-ui 1.1.19)`. */
|
|
234
|
+
function checksWords(checks) {
|
|
235
|
+
const release = checks.version === null ? '' : ` (@elaraai/e3-cloud-ui ${checks.version})`;
|
|
236
|
+
return checks.from === 'project' ? `the project's checks${release}` : `this CLI's checks${release}, since ${checks.fallback ?? "the project's can't be loaded"}`;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* The live apps of a workspace with no build for the next e3 prepared, after
|
|
240
|
+
* a deploy prepared some: what the platform's move waits for, since its
|
|
241
|
+
* preflight refuses while an app built with another e3 has none.
|
|
242
|
+
*/
|
|
243
|
+
function stillToPrepare(apps, next) {
|
|
244
|
+
return apps
|
|
245
|
+
.filter((app) => !sameString(app.current.builtWith, next) && !(app.staged.type === 'some' && sameString(app.staged.value.forPlatform, next)))
|
|
246
|
+
.map((app) => app.name);
|
|
247
|
+
}
|
|
248
|
+
/** Names, in words: `ops`, `ops and exec`, `ops, exec and planner`. */
|
|
249
|
+
function namesInWords(names) {
|
|
250
|
+
return names.length <= 1 ? names.join('') : `${names.slice(0, -1).join(', ')} and ${names.at(-1)}`;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* What a hold did, in words: held, kept as held already, or held in place of
|
|
254
|
+
* another zip (an admin's replace); and, when `--replace` was asked for and
|
|
255
|
+
* nothing was replaced, that it was not.
|
|
256
|
+
*/
|
|
257
|
+
function holdWords(answer, repo, workspace, next, replace) {
|
|
258
|
+
const pkg = `${answer.name}@${answer.version}`;
|
|
259
|
+
const exported = `exported with e3 ${answer.release.type === 'some' ? answer.release.value : 'of no release'}`;
|
|
260
|
+
const move = `the move imports it and deploys it to ${workspace}`;
|
|
261
|
+
const replacedNothing = replace ? ` (--replace replaced nothing: no other zip was held for ${pkg})` : '';
|
|
262
|
+
switch (answer.outcome.type) {
|
|
263
|
+
case 'held':
|
|
264
|
+
return `Holding ${pkg} (${exported}) in ${repo} for the platform's move to e3 ${next}: ${move}${replacedNothing}`;
|
|
265
|
+
case 'kept':
|
|
266
|
+
return `${pkg} (${exported}) is held in ${repo} for the platform's move to e3 ${next} already: ${move}${replacedNothing}`;
|
|
267
|
+
case 'replaced':
|
|
268
|
+
return `Holding ${pkg} (${exported}) in ${repo} for the platform's move to e3 ${next}, in place of the zip held for it before (${answer.outcome.value.slice(0, 12)}): ${move}`;
|
|
269
|
+
case 'in_repository':
|
|
270
|
+
return `${repo} holds ${pkg} already: nothing is held for the move`;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Whether builds whose package is the version their workspace runs, exported
|
|
275
|
+
* to other bytes, fit the workspace's package: the binding `--against-workspace`
|
|
276
|
+
* makes, by the project's checks (this CLI's for a bundle file).
|
|
277
|
+
*
|
|
278
|
+
* @returns The bound builds; why not, in lines (none when they fit); and
|
|
279
|
+
* what differs where no page binds it, or only in code, in the lines
|
|
280
|
+
* `--against-workspace` prints
|
|
281
|
+
*/
|
|
282
|
+
async function fitsRunning(built, sourceOf, runs, workspace, baseUrl, repo, token) {
|
|
283
|
+
const why = [];
|
|
284
|
+
const differs = [];
|
|
285
|
+
// What differs that e3 shows (a name, a type, a signature, an initial value, a file source): the owner's change, not an export's
|
|
286
|
+
const changed = [];
|
|
287
|
+
// Among them, an input's file source: bound by the workspace's Files declarations
|
|
288
|
+
let files = false;
|
|
289
|
+
const bound = [];
|
|
290
|
+
const held = `${packageWords(runs)}, which ${workspace} runs`;
|
|
291
|
+
for (const bundle of built) {
|
|
292
|
+
const source = sourceOf.get(bundle) ?? null;
|
|
293
|
+
const checks = await checksFor(source);
|
|
294
|
+
const decision = await bindingDecision(bundle.app, { hash: bundle.app.package.hash, read: await zipObjects(bundle.package) }, { hash: runs.hash, read: (hash) => objectGet(baseUrl, repo, hash, { token }) }, runs, held, checks.checks);
|
|
295
|
+
const name = bundle.app.name;
|
|
296
|
+
if (decision.indexed.length > 0)
|
|
297
|
+
why.push(` ${name}: ${decision.indexed.map((read) => `page ${read.page} reads ${read.records.join(', ')} through indexes, whose programs it carries from its own source`).join('; ')}`);
|
|
298
|
+
if (decision.unknown.length > 0)
|
|
299
|
+
why.push(` ${name}: ${decision.unknown.map((entry) => `page ${entry.page} calls ${entry.calls.join(', ')}, binds this CLI doesn't know`).join('; ')}`);
|
|
300
|
+
if (decision.problems.length > 0)
|
|
301
|
+
why.push(` ${name}:`, ...problemLines(decision.problems, { app: name, package: packageWords(runs) }).map((line) => ` ${line}`));
|
|
302
|
+
// What differs, as --against-workspace says it
|
|
303
|
+
if (decision.differences.length > 0)
|
|
304
|
+
differs.push(`${name}'s pages fit ${held}; these differ, where no page of ${name} binds them, or only in code:`, ...decision.differences.map((line) => ` ${line}`));
|
|
305
|
+
// Its kind as the comparison found it, never read back from its words
|
|
306
|
+
for (const difference of decision.kinds) {
|
|
307
|
+
if (difference.kind === 'code')
|
|
308
|
+
continue;
|
|
309
|
+
if (difference.kind === 'files')
|
|
310
|
+
files = true;
|
|
311
|
+
if (!changed.includes(difference.line))
|
|
312
|
+
changed.push(difference.line);
|
|
313
|
+
}
|
|
314
|
+
differs.push(...taskPageLines(name, packageWords(runs), decision.taskPages));
|
|
315
|
+
const one = bindToWorkspacePackage(bundle, runs, workspace);
|
|
316
|
+
if (source !== null)
|
|
317
|
+
sourceOf.set(one, source);
|
|
318
|
+
bound.push(one);
|
|
319
|
+
}
|
|
320
|
+
return { bound, why, differs, changed, files };
|
|
321
|
+
}
|
|
101
322
|
/**
|
|
102
323
|
* A workspace's URL, as `app build --against-workspace` takes it: refused
|
|
103
324
|
* with anything past the workspace's name.
|
|
@@ -138,23 +359,30 @@ async function boundAgainst(source, bundle, running, workspace, baseUrl, repo, t
|
|
|
138
359
|
// An app with an indexed read is never bound: its pages carry the record's
|
|
139
360
|
// index programs from its own source, which the platform's checks don't read
|
|
140
361
|
if (decision.indexed.length > 0) {
|
|
362
|
+
const holds = await platformHolds(baseUrl, repo, workspace, name, token);
|
|
141
363
|
exitError([
|
|
142
364
|
`${name} can't be built against ${held}: ${decision.indexed.length === 1 ? 'a page of it reads' : 'pages of it read'} records through indexes`,
|
|
143
365
|
...decision.indexed.map((read) => ` page ${read.page}: ${read.records.join(', ')}`),
|
|
144
|
-
|
|
366
|
+
holds === true
|
|
367
|
+
? `Such a page carries the record's index programs from its own source, which can't be shown to be the workspace's. Deploy ${name} with a package of its own instead, without --against-workspace, giving ${running.name} a new version in its source: ${HOLDS_FOR_THE_MOVE}`
|
|
368
|
+
: holds === false
|
|
369
|
+
? `Such a page carries the record's index programs from its own source, which can't be shown to be the workspace's. Stage it with a package of its own once the platform takes one; until then, remove ${name} before the platform moves and deploy it after`
|
|
370
|
+
: `Such a page carries the record's index programs from its own source, which can't be shown to be the workspace's. ${holdsUnknownWords(holds)}`,
|
|
145
371
|
].join('\n'));
|
|
146
372
|
}
|
|
147
373
|
// A bind this CLI doesn't know may carry programs as the indexed read does: refused, failing closed
|
|
148
374
|
if (decision.unknown.length > 0) {
|
|
375
|
+
const holds = await platformHolds(baseUrl, repo, workspace, name, token);
|
|
149
376
|
exitError([
|
|
150
377
|
`${name} can't be built against ${held}: ${decision.unknown.length === 1 ? 'a page of it calls' : 'pages of it call'} binds this e3-cloud CLI doesn't know`,
|
|
151
378
|
...decision.unknown.map((entry) => ` page ${entry.page}: ${entry.calls.join(', ')}`),
|
|
152
|
-
`This release of the e3-cloud CLI doesn't know such a bind of the workspace, so it can't show that what the page carries from its own source is the workspace's. Deploy ${name} as built, with the package its source exports (without --against-workspace), where the repository holds no other of that version
|
|
379
|
+
`This release of the e3-cloud CLI doesn't know such a bind of the workspace, so it can't show that what the page carries from its own source is the workspace's. Deploy ${name} as built, with the package its source exports (without --against-workspace), where the repository holds no other of that version${holds === true ? `; ${HOLDS_FOR_THE_MOVE}` : holds === false ? `; or remove ${name} before the platform moves and deploy it after` : `. ${holdsUnknownWords(holds)}`}`,
|
|
153
380
|
].join('\n'));
|
|
154
381
|
}
|
|
155
382
|
// What its pages bind, held to the held package by the platform's own checks, in their words
|
|
156
383
|
if (decision.problems.length > 0) {
|
|
157
|
-
|
|
384
|
+
const holds = decision.problems.some((problem) => FIT_PROBLEMS.has(problem.type)) ? await platformHolds(baseUrl, repo, workspace, name, token) : false;
|
|
385
|
+
exitError(bindingRefusalLines(name, packageWords(running), `which ${workspace} runs`, decision.problems, checks, holds).join('\n'));
|
|
158
386
|
}
|
|
159
387
|
if (decision.differences.length > 0) {
|
|
160
388
|
console.log([`${name}'s pages fit ${held}; these differ, where no page of ${name} binds them, or only in code:`, ...decision.differences.map((line) => ` ${line}`)].join('\n'));
|
|
@@ -164,29 +392,55 @@ async function boundAgainst(source, bundle, running, workspace, baseUrl, repo, t
|
|
|
164
392
|
console.log(line);
|
|
165
393
|
return bound;
|
|
166
394
|
}
|
|
167
|
-
/**
|
|
168
|
-
|
|
395
|
+
/**
|
|
396
|
+
* What a deploy did, in words. A build for the next e3 prepared with a package
|
|
397
|
+
* of its own, other than the one its workspace runs, says what the
|
|
398
|
+
* platform's move does: it deploys that package, and the workspace then needs
|
|
399
|
+
* a run.
|
|
400
|
+
*
|
|
401
|
+
* @param response - The deploy's answer
|
|
402
|
+
* @param workspace - The workspace
|
|
403
|
+
* @param pkg - The package the apps were built against
|
|
404
|
+
* @param running - The package the workspace runs, read once for a deploy for
|
|
405
|
+
* the next e3; null for any other deploy, or a workspace that runs none
|
|
406
|
+
*/
|
|
407
|
+
function deployedWords(response, workspace, pkg, running) {
|
|
408
|
+
const own = running !== null && !samePackage(running, pkg);
|
|
169
409
|
switch (response.type) {
|
|
170
410
|
case 'refused':
|
|
171
411
|
return '';
|
|
172
412
|
case 'checked': {
|
|
173
413
|
const apps = response.value.apps.join(', ');
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
414
|
+
const them = response.value.apps.length === 1 ? 'it' : 'them';
|
|
415
|
+
const what = response.value.deploy.type === 'ui_only' ? `a deploy would change only ${response.value.apps.length === 1 ? 'the app' : 'the apps'}: ${workspace} runs ${packageWords(pkg)}`
|
|
416
|
+
: response.value.deploy.type === 'for_platform'
|
|
417
|
+
? own
|
|
418
|
+
? `a deploy would prepare ${them} for e3 ${response.value.deploy.value} with ${packageWords(pkg)}, which the platform's move deploys`
|
|
419
|
+
: `a deploy would prepare a build of ${them} for e3 ${response.value.deploy.value}`
|
|
420
|
+
: `a deploy would deploy ${packageWords(pkg)} first`;
|
|
177
421
|
return `${apps} ${response.value.apps.length === 1 ? 'fits' : 'fit'} ${workspace}: ${what}`;
|
|
178
422
|
}
|
|
179
423
|
case 'live':
|
|
180
|
-
return response.value.map((app) => `${app.name} v${app.current.number} is live on ${workspace} (UI only: ${workspace} runs ${pkg})`).join('\n');
|
|
424
|
+
return response.value.map((app) => `${app.name} v${app.current.number} is live on ${workspace} (UI only: ${workspace} runs ${packageWords(pkg)})`).join('\n');
|
|
181
425
|
case 'deploying':
|
|
182
|
-
return `Deploying ${pkg} to ${workspace}, keeping the inputs people set · ${response.value.apps.join(', ')} ${response.value.apps.length === 1 ? 'goes' : 'go'} live as the deploy completes (job ${response.value.job})`;
|
|
426
|
+
return `Deploying ${packageWords(pkg)} to ${workspace}, keeping the inputs people set · ${response.value.apps.join(', ')} ${response.value.apps.length === 1 ? 'goes' : 'go'} live as the deploy completes (job ${response.value.job})`;
|
|
183
427
|
case 'staged':
|
|
184
|
-
return response.value.map((app) =>
|
|
428
|
+
return response.value.map((app) => {
|
|
429
|
+
const next = app.staged.type === 'some' ? app.staged.value.forPlatform : '?';
|
|
430
|
+
if (own && app.staged.type === 'some' && !samePackage(app.staged.value.package, running)) {
|
|
431
|
+
const brings = packageWords(app.staged.value.package);
|
|
432
|
+
return `A build of ${app.name} for e3 ${next} is prepared on ${workspace}, with ${brings}: the platform's move deploys ${brings} to ${workspace}, and to each workspace a release carries the build to, keeping the inputs people set and migrating records. Each then needs a run, which nothing starts: the deploy keeps only the outputs of tasks it leaves unchanged, and the next e3's export usually changes every task. v${app.current.number} stays live on ${packageWords(running)} until then`;
|
|
433
|
+
}
|
|
434
|
+
return `A build of ${app.name} for e3 ${next} is prepared on ${workspace}: it goes live when the platform moves; v${app.current.number} stays live until then`;
|
|
435
|
+
}).join('\n');
|
|
185
436
|
}
|
|
186
437
|
}
|
|
187
438
|
/** An app's row in a listing. */
|
|
188
439
|
function appRow(app) {
|
|
189
|
-
|
|
440
|
+
// A build prepared with a package of its own names it: the package the platform's move deploys
|
|
441
|
+
const staged = app.staged.type === 'none' ? ''
|
|
442
|
+
: samePackage(app.staged.value.package, app.current.package) ? ` · build for ${app.staged.value.forPlatform} prepared`
|
|
443
|
+
: ` · build for ${app.staged.value.forPlatform} prepared, with ${packageWords(app.staged.value.package)}`;
|
|
190
444
|
return [
|
|
191
445
|
app.workspace.padEnd(16),
|
|
192
446
|
app.name.padEnd(16),
|
|
@@ -227,7 +481,7 @@ export const appCommand = {
|
|
|
227
481
|
// the bundle is written already, so a deployment that doesn't answer leaves the hint without it
|
|
228
482
|
const platform = await platformVersions(against.baseUrl, { token: token }).catch(() => null);
|
|
229
483
|
const staging = platform !== null && newerRelease(bundle.app.builtWith, platform.e3) ? ` --for-platform ${bundle.app.builtWith}` : '';
|
|
230
|
-
const why = staging === '' ? '' : ` (the deployment runs e3 ${platform.e3}: the app is
|
|
484
|
+
const why = staging === '' ? '' : ` (the deployment runs e3 ${platform.e3}: the app is prepared for its move to ${bundle.app.builtWith})`;
|
|
231
485
|
console.log(`Its pages were checked against ${packageWords(pkg)} by the platform's checks, here; e3-cloud app deploy ${against.baseUrl}/repos/${against.repo} ${against.workspace} ${output}${staging} --dry-run checks them by the deployment's own${why}`);
|
|
232
486
|
}
|
|
233
487
|
}
|
|
@@ -235,7 +489,7 @@ export const appCommand = {
|
|
|
235
489
|
exitError(describe(err));
|
|
236
490
|
}
|
|
237
491
|
},
|
|
238
|
-
/** e3-cloud app deploy <repoUrl> <workspace> [bundles...] [--from-source <source...>] [--against-workspace] [--dry-run] [--for-platform <version>] [--force] */
|
|
492
|
+
/** e3-cloud app deploy <repoUrl> <workspace> [bundles...] [--from-source <source...>] [--against-workspace] [--dry-run] [--for-platform <version>] [--force] [--replace] */
|
|
239
493
|
async deploy(url, workspace, bundles, options) {
|
|
240
494
|
try {
|
|
241
495
|
const force = options.force === true;
|
|
@@ -249,7 +503,9 @@ export const appCommand = {
|
|
|
249
503
|
exitError('--against-workspace builds sources: give them with --from-source, or build the bundle with e3-cloud app build --against-workspace');
|
|
250
504
|
const { baseUrl, repo } = parseRepoUrl(url);
|
|
251
505
|
const token = await getValidToken(baseUrl);
|
|
252
|
-
|
|
506
|
+
let built = [...bundles.map(readBundle)];
|
|
507
|
+
// Each build's source, for the checks run here; none for a bundle file
|
|
508
|
+
const sourceOf = new Map();
|
|
253
509
|
// The package the workspace runs, read before any build: what sources are built against
|
|
254
510
|
const running = against ? await workspacePackage(baseUrl, repo, workspace, token) : null;
|
|
255
511
|
if (against && running === null)
|
|
@@ -257,53 +513,218 @@ export const appCommand = {
|
|
|
257
513
|
// Each source, built; against the package the workspace runs, bound to it
|
|
258
514
|
for (const source of sources) {
|
|
259
515
|
const bundle = await buildAppFromSource(source);
|
|
260
|
-
|
|
516
|
+
const one = against ? await boundAgainst(source, bundle, running, workspace, baseUrl, repo, token) : bundle;
|
|
517
|
+
sourceOf.set(one, source);
|
|
518
|
+
built.push(one);
|
|
261
519
|
}
|
|
262
|
-
|
|
263
|
-
const other = built.find((b) => !
|
|
520
|
+
let pkg = built[0].app.package;
|
|
521
|
+
const other = built.find((b) => !samePackage(b.app.package, pkg));
|
|
264
522
|
if (other !== undefined) {
|
|
265
523
|
// Two of one name and version are told apart by their hashes
|
|
266
524
|
const alike = sameString(other.app.package.name, pkg.name) && sameString(other.app.package.version, pkg.version);
|
|
267
525
|
const words = (p) => (alike ? packageWithHash(p) : packageWords(p));
|
|
268
526
|
exitError(`Apps deployed together are built against one package: ${built[0].app.name} against ${words(pkg)}, ${other.app.name} against ${words(other.app.package)}`);
|
|
269
527
|
}
|
|
528
|
+
const names = built.map((bundle) => bundle.app.name);
|
|
529
|
+
const one = names.length === 1;
|
|
530
|
+
const namesWere = `${names.join(', ')} ${one ? 'was' : 'were'}`;
|
|
531
|
+
const dryRun = options.dryRun === true;
|
|
532
|
+
// The platform's e3 against the build's, read before anything is sent: a
|
|
533
|
+
// build of a newer e3 is prepared for the platform's move by itself, as
|
|
534
|
+
// if --for-platform named its e3, which stays accepted and means the same
|
|
535
|
+
let forPlatform = options.forPlatform;
|
|
536
|
+
// The platform's e3 not read: said, and never a newer build imported unseen (below)
|
|
537
|
+
let platformUnread = null;
|
|
538
|
+
if (forPlatform === undefined) {
|
|
539
|
+
const platform = await platformVersions(baseUrl, { token }).catch((err) => {
|
|
540
|
+
// A deployment from before the route (a 404) runs an e3 no build is newer than here: as before
|
|
541
|
+
if (!(err instanceof ApiError && (err.code === 'not_found' || err.code === 'http_404')))
|
|
542
|
+
platformUnread = describe(err);
|
|
543
|
+
return null;
|
|
544
|
+
});
|
|
545
|
+
const withs = [...new Set(built.map((bundle) => bundle.app.builtWith))];
|
|
546
|
+
if (platform !== null && withs.some((w) => newerRelease(w, platform.e3))) {
|
|
547
|
+
if (withs.length > 1)
|
|
548
|
+
exitError(`${names.join(', ')} are built with e3 ${withs.join(' and ')}: build them with one, the platform's next`);
|
|
549
|
+
forPlatform = withs[0];
|
|
550
|
+
console.log(`This platform runs e3 ${platform.e3}, and ${names.join(', ')} ${one ? 'is' : 'are'} built with e3 ${forPlatform}: preparing ${one ? 'it' : 'them'} for the platform's move to e3 ${forPlatform} on ${workspace}. ${one ? 'It goes' : 'They go'} live when the platform moves; until then ${workspace}'s live ${one ? 'version stays' : 'versions stay'}`);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
// Choosing the package of a build for the next e3: the one the workspace
|
|
554
|
+
// runs; the same version exported to other bytes, when the apps fit the
|
|
555
|
+
// workspace's (the binding --against-workspace makes); else their own,
|
|
556
|
+
// held for the move, which needs a version no other build of holds
|
|
557
|
+
if (forPlatform !== undefined && built.some(carriesPackage)) {
|
|
558
|
+
const runs = await workspacePackage(baseUrl, repo, workspace, token);
|
|
559
|
+
if (runs !== null && !sameString(runs.hash, pkg.hash) && sameString(runs.name, pkg.name) && sameString(runs.version, pkg.version)) {
|
|
560
|
+
const fit = await fitsRunning(built, sourceOf, runs, workspace, baseUrl, repo, token);
|
|
561
|
+
if (fit.why.length > 0) {
|
|
562
|
+
exitError([
|
|
563
|
+
`${names.join(', ')} ${one ? 'is' : 'are'} built against ${packageWords(pkg)}, which ${workspace} runs exported to other bytes (${pkg.hash.slice(0, 12)}, not ${runs.hash.slice(0, 12)}), and ${one ? "doesn't" : "don't"} fit ${workspace}'s:`,
|
|
564
|
+
...fit.why,
|
|
565
|
+
`A version names one package: give ${pkg.name} a new version in its source (it is ${pkg.version} now) and deploy again. Nothing is sent; the platform then holds that package for its move, and the move deploys it`,
|
|
566
|
+
].join('\n'));
|
|
567
|
+
}
|
|
568
|
+
// A difference e3 shows is the owner's change to the package, never
|
|
569
|
+
// an export's: refused before anything is sent, with the one step
|
|
570
|
+
if (fit.changed.length > 0) {
|
|
571
|
+
exitError([
|
|
572
|
+
`${names.join(', ')} ${one ? 'is' : 'are'} built against ${packageWords(pkg)}, and its package differs from ${packageWords(runs)}, which ${workspace} runs, where e3 shows it: a change to the package, not the next e3's export of it:`,
|
|
573
|
+
...fit.changed.map((line) => ` ${line}`),
|
|
574
|
+
`A version names one package: give ${pkg.name} a new version in its source (it is ${pkg.version} now) and deploy again. Nothing is sent; the platform then holds that package for its move, and the move deploys it with ${one ? 'the app' : 'the apps'}`,
|
|
575
|
+
// An input's file source differs: the new version is then held to the workspace's Files declarations too
|
|
576
|
+
...(fit.files ? [`An input taken from another file is bound by ${workspace}'s Files declarations, which must fit the new version as well: until they do, its deploy is refused package_files_differ, which says how to fit them`] : []),
|
|
577
|
+
].join('\n'));
|
|
578
|
+
}
|
|
579
|
+
built = fit.bound;
|
|
580
|
+
pkg = runs;
|
|
581
|
+
// First, before what differs: a change of code made here is not deployed by this
|
|
582
|
+
console.log(`This prepares ${namesInWords(names)} on the package ${workspace} runs, ${packageWords(runs)}, not on the package built here: a change you made to the package's code is not deployed. To send it with ${one ? 'the app' : 'the apps'}, give ${pkg.name} a new version in its source and deploy again`);
|
|
583
|
+
console.log(`${names.join(', ')}'s package, exported with e3 ${forPlatform}, differs from ${packageWords(runs)}, which ${workspace} runs, in code alone, which an export by the next e3 also changes; ${one ? 'it fits' : 'they fit'} ${packageWords(runs)}, so ${one ? 'its build is' : 'their builds are'} prepared on it, and the move deploys no package to ${workspace}`);
|
|
584
|
+
for (const line of fit.differs)
|
|
585
|
+
console.log(line);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
270
588
|
// A bundle carrying no package runs on exactly the package the workspace runs.
|
|
271
589
|
// Read again now, after the builds, so a workspace that moved meanwhile
|
|
272
|
-
// refuses it; one that moves in the seconds after is said, below
|
|
590
|
+
// refuses it; one that moves in the seconds after is said, below. As the
|
|
591
|
+
// platform decides it: a build for the next e3 by name, version and hash
|
|
592
|
+
// (a move to another version of one content shares the hash, and is
|
|
593
|
+
// still another package, which the platform refuses package_differs); a
|
|
594
|
+
// live one by its content, which the platform deploys UI only
|
|
273
595
|
const bareNow = built.filter((b) => !carriesPackage(b));
|
|
274
596
|
const now = bareNow.length === 0 ? null : await workspacePackage(baseUrl, repo, workspace, token);
|
|
597
|
+
const runsIt = (p) => now !== null && (forPlatform === undefined ? sameString(now.hash, p.hash) : samePackage(now, p));
|
|
275
598
|
for (const bundle of bareNow) {
|
|
276
|
-
if (
|
|
599
|
+
if (!runsIt(bundle.app.package)) {
|
|
277
600
|
exitError(`${bundle.app.name} was built against ${packageWithHash(bundle.app.package)} and carries no package, and ${workspace} runs ${now === null ? 'no package' : packageWithHash(now)}: build it again with --against-workspace, against the package ${workspace} runs now`);
|
|
278
601
|
}
|
|
279
602
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
const
|
|
283
|
-
if (!
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
603
|
+
const listed = await packageList(baseUrl, repo, { token });
|
|
604
|
+
const inRepository = listed.some((p) => sameString(p.name, pkg.name) && sameString(p.version, pkg.version));
|
|
605
|
+
const carrier = built.find(carriesPackage);
|
|
606
|
+
if (!inRepository && carrier === undefined) {
|
|
607
|
+
exitError(`${built[0].app.name} was built against ${packageWords(pkg)} as a repository held it when it was built, and ${repo} holds no ${packageWords(pkg)}: build it from source with --against-workspace here`);
|
|
608
|
+
}
|
|
609
|
+
// A package the repository lacks, checked here first: its zip verified as e3
|
|
610
|
+
// exports one, and the apps against it, by the project's checks
|
|
611
|
+
let fitsHere = null;
|
|
612
|
+
if (!inRepository) {
|
|
613
|
+
await verifiedZip(carrier.package, names.join(', '));
|
|
614
|
+
const here = await checkedHere(built.map((bundle) => ({ bundle, source: sourceOf.get(bundle) ?? null })), carrier.package, pkg);
|
|
615
|
+
if (here.problems.length > 0) {
|
|
616
|
+
exitError([
|
|
617
|
+
`${here.problems.map((entry) => entry.app).join(', ')} ${here.problems.length === 1 ? "doesn't" : "don't"} fit ${packageWords(pkg)}, which ${here.problems.length === 1 ? 'it brings' : 'they bring'}, by ${checksWords(here.checks)}, here: nothing is held, and nothing is deployed`,
|
|
618
|
+
...here.problems.flatMap((entry) => problemLines(entry.problems, { app: entry.app, package: packageWords(pkg) })),
|
|
619
|
+
].join('\n'));
|
|
620
|
+
}
|
|
621
|
+
fitsHere = `Checked here, by ${checksWords(here.checks)}: the zip of ${packageWords(pkg)} is whole, and ${names.join(', ')} ${one ? 'fits' : 'fit'} it`;
|
|
622
|
+
}
|
|
623
|
+
// A dry run keeps nothing: a package the repository lacks is neither
|
|
624
|
+
// imported nor held, and the platform drops the build it is sent to check. Not for the next e3, the platform's checks need it
|
|
625
|
+
// imported, so nothing is sent, and the checks run here answer; for the
|
|
626
|
+
// next e3, the platform checks against a zip held already, and the
|
|
627
|
+
// checks here answer when none is
|
|
628
|
+
const them = one ? 'it' : 'them';
|
|
629
|
+
// A package the repository lacks, with the platform's e3 unknown: the
|
|
630
|
+
// build may be of a newer e3, whose package the platform refuses to import
|
|
631
|
+
// The platform's e3 unknown: whether the build is to be prepared or deployed live is not known either,
|
|
632
|
+
// and a newer build sent as a live one meets words to build it again with the older e3: stop, either way
|
|
633
|
+
if (forPlatform === undefined && platformUnread !== null) {
|
|
634
|
+
exitError(`The platform's e3 could not be read (${platformUnread}), so whether ${names.join(', ')} ${one ? 'is' : 'are'} built with a newer e3 than it runs is not known${inRepository ? '' : ', and the platform refuses to import a package a newer e3 exported'}. Nothing is ${inRepository ? '' : 'imported or '}deployed: run again, or name the e3 the build is for with --for-platform ${built[0].app.builtWith} to prepare ${them} for the platform's move to it`);
|
|
635
|
+
}
|
|
636
|
+
if (dryRun && !inRepository && forPlatform === undefined) {
|
|
637
|
+
console.log(`${fitsHere}. A dry run writes nothing, and ${packageWords(pkg)} is not in ${repo}: the platform's own checks were not made, since they need the package imported. A deploy without --dry-run imports ${packageWords(pkg)}, then the platform checks ${them} against it`);
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
// What can be known before a hold is checked before it, so nothing is
|
|
641
|
+
// held for a deploy the platform would refuse
|
|
642
|
+
if (!inRepository && forPlatform !== undefined) {
|
|
643
|
+
const zipRef = packageZipRef(carrier.package);
|
|
644
|
+
if (zipRef.release !== forPlatform) {
|
|
645
|
+
exitError(`${packageWords(pkg)} was exported ${zipRef.release === null ? 'by an e3 its zip does not name' : `with e3 ${zipRef.release}`}, and ${names.join(', ')} ${one ? 'is' : 'are'} prepared for e3 ${forPlatform}, whose move imports only a zip that e3 exported. Nothing is held: build with e3 ${forPlatform}, giving ${pkg.name} a new version, and deploy again`);
|
|
646
|
+
}
|
|
647
|
+
const apps = await appList(baseUrl, repo, workspace, { token });
|
|
648
|
+
const missing = names.filter((name) => !apps.some((app) => sameString(app.name, name)));
|
|
649
|
+
if (missing.length > 0) {
|
|
650
|
+
exitError(`${namesInWords(missing)} ${missing.length === 1 ? 'has' : 'have'} no live version on ${workspace}, and a build for the next e3 is prepared beside a live version. Nothing is held: deploy ${missing.length === 1 ? 'it' : 'them'} once the platform runs e3 ${forPlatform}`);
|
|
651
|
+
}
|
|
652
|
+
const elsewhere = apps.filter((app) => !names.includes(app.name) && app.staged.type === 'some' && sameString(app.staged.value.forPlatform, forPlatform) && !samePackage(app.staged.value.package, pkg));
|
|
653
|
+
if (elsewhere.length > 0) {
|
|
654
|
+
const on = elsewhere[0].staged.type === 'some' ? elsewhere[0].staged.value.package : pkg;
|
|
655
|
+
const prepared = elsewhere.filter((app) => app.staged.type === 'some' && samePackage(app.staged.value.package, on)).map((app) => app.name);
|
|
656
|
+
exitError(`${workspace}'s builds for e3 ${forPlatform} are prepared on one package: ${namesInWords(prepared)} ${prepared.length === 1 ? 'is' : 'are'} prepared on ${packageWords(on)}, and ${names.join(', ')} ${one ? 'is' : 'are'} built against ${packageWords(pkg)}. Nothing is held. Prepare ${workspace}'s apps on one package together, in one deploy; or ${REMOVE_PREPARED_WORDS(url).replace(/^Remove/, 'remove')}`);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
// The package, imported when the repository does not hold its version; for
|
|
660
|
+
// the next e3, on a deployment that holds packages for its move
|
|
661
|
+
let heldNow = false;
|
|
662
|
+
if (!inRepository) {
|
|
663
|
+
if (forPlatform === undefined) {
|
|
664
|
+
console.log(`Importing ${packageWords(pkg)} into ${repo}…`);
|
|
665
|
+
await packageImport(baseUrl, repo, carrier.package, { token });
|
|
666
|
+
}
|
|
667
|
+
else {
|
|
668
|
+
// A deployment from before the hold holds none, said only on its definite sign
|
|
669
|
+
if (!await heldPackagesServed(baseUrl, repo, workspace, names[0], { token })) {
|
|
670
|
+
exitError(await holdsNoPackageWords(baseUrl, token, namesWere, packageWords(pkg), repo));
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
// Held for the platform's move, which imports it and deploys it; a dry run holds nothing
|
|
675
|
+
if (!inRepository && forPlatform !== undefined && !dryRun) {
|
|
676
|
+
let answer;
|
|
677
|
+
try {
|
|
678
|
+
answer = await appHoldPackage(baseUrl, repo, workspace, names[0], carrier.package, { token }, { force, replace: options.replace === true });
|
|
679
|
+
}
|
|
680
|
+
catch (err) {
|
|
681
|
+
exitError(holdRefusalWords(err, names.join(', '), pkg, repo, url, workspace));
|
|
287
682
|
}
|
|
288
|
-
|
|
289
|
-
|
|
683
|
+
heldNow = answer.held;
|
|
684
|
+
console.log(holdWords(answer, repo, workspace, forPlatform, options.replace === true));
|
|
290
685
|
}
|
|
686
|
+
if (options.replace === true && (inRepository || forPlatform === undefined)) {
|
|
687
|
+
console.log(`--replace replaces a zip held for the platform's move, and this deploy holds none (${inRepository ? `${repo} holds ${packageWords(pkg)}` : 'it is for no next e3'}): nothing is replaced`);
|
|
688
|
+
}
|
|
689
|
+
/** A refusal after a hold: the zip stays held, said, unless the refusal is that it is gone */
|
|
690
|
+
const refuse = (lines, gone = false) => exitError(heldNow && !gone ? `${lines}\n${STAYS_HELD(pkg)}` : lines);
|
|
691
|
+
// The package the workspace runs, for the words of a build for the next e3: read once
|
|
692
|
+
const workspaceRuns = forPlatform === undefined ? null : bareNow.length > 0 ? now : await workspacePackage(baseUrl, repo, workspace, token);
|
|
291
693
|
// Each app object, uploaded; then one deploy of them all
|
|
292
694
|
const items = [];
|
|
293
695
|
for (const bundle of built)
|
|
294
696
|
items.push({ name: bundle.app.name, source: await appUpload(baseUrl, repo, workspace, bundle.app.name, encodeApp(bundle.app), { token }) });
|
|
295
|
-
const
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
697
|
+
const preparing = forPlatform === undefined ? none : some(forPlatform);
|
|
698
|
+
let response;
|
|
699
|
+
try {
|
|
700
|
+
response = items.length === 1
|
|
701
|
+
? await appDeploy(baseUrl, repo, workspace, items[0].name, { source: items[0].source, forPlatform: preparing, dryRun, force }, { token })
|
|
702
|
+
: await appsDeploy(baseUrl, repo, workspace, { apps: items, forPlatform: preparing, dryRun, force }, { token });
|
|
703
|
+
}
|
|
704
|
+
catch (err) {
|
|
705
|
+
// A dry run for the next e3 holds nothing: one with a package not held
|
|
706
|
+
// yet is answered by the checks run here, and says what a deploy would do
|
|
707
|
+
if (dryRun && !inRepository && fitsHere !== null && err instanceof ApiError && err.code === 'package_missing') {
|
|
708
|
+
console.log(`${fitsHere}. A dry run keeps nothing, and ${packageWords(pkg)} is neither in ${repo} nor held for the platform's move: the platform's own checks were not made, since they need the package held. A deploy without --dry-run holds ${packageWords(pkg)} for the move and prepares ${them} on ${workspace} for e3 ${forPlatform}, once the platform's checks pass`);
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
const then = preparedRefusalWords(err, url, workspace, forPlatform ?? null, pkg);
|
|
712
|
+
// A zip let go since its hold (another build on it removed meanwhile): not held, so never "stays held"
|
|
713
|
+
const gone = err instanceof ApiError && (err.code === 'package_missing' || err.code === 'held_package_gone' || err.code === 'held_package_gone_prepared');
|
|
714
|
+
return refuse(then === null ? describe(err) : `${describe(err)}\n${then}`, gone);
|
|
715
|
+
}
|
|
300
716
|
// The apps refused: those deployed, and any other of the workspace the package would break
|
|
301
717
|
if (response.type === 'refused') {
|
|
302
|
-
|
|
718
|
+
const lines = [appDeployRefusedText(response.value, packageWords(pkg))];
|
|
303
719
|
// An app built against the package its workspace runs: what its problems mean for it
|
|
304
720
|
const bound = new Set(built.filter((bundle) => !carriesPackage(bundle)).map((bundle) => bundle.app.name));
|
|
305
|
-
|
|
306
|
-
|
|
721
|
+
// How such an app crosses the platform's move, where the package doesn't fit it
|
|
722
|
+
const unfit = response.value.some((entry) => bound.has(entry.app) && entry.problems.some((problem) => FIT_PROBLEMS.has(problem.type)));
|
|
723
|
+
const holds = unfit ? await platformHolds(baseUrl, repo, workspace, [...bound][0], token) : false;
|
|
724
|
+
lines.push(...boundRefusalLines(response.value, bound, packageWords(pkg), `which ${workspace} runs`, forPlatform ?? null, holds));
|
|
725
|
+
if (heldNow)
|
|
726
|
+
lines.push(STAYS_HELD(pkg));
|
|
727
|
+
console.error(lines.join('\n'));
|
|
307
728
|
process.exit(1);
|
|
308
729
|
}
|
|
309
730
|
// A bundle carrying no package, answered with a deploy of its package: the
|
|
@@ -316,7 +737,24 @@ export const appCommand = {
|
|
|
316
737
|
console.error(movedDuringDeployLines(url, workspace, packageWithHash(now), known, response.value.job, bareNow.map((bundle) => bundle.app.name)).join('\n'));
|
|
317
738
|
process.exit(1);
|
|
318
739
|
}
|
|
319
|
-
console.log(deployedWords(response, workspace,
|
|
740
|
+
console.log(deployedWords(response, workspace, pkg, workspaceRuns));
|
|
741
|
+
if (response.type === 'staged' && fitsHere !== null) {
|
|
742
|
+
// The platform may not read a package of a newer e3 than it runs: then the build is checked at the move alone
|
|
743
|
+
const platform = await platformVersions(baseUrl, { token }).catch(() => null);
|
|
744
|
+
if (platform !== null && newerRelease(forPlatform, platform.e3)) {
|
|
745
|
+
console.log(`This platform runs e3 ${platform.e3} and may not read a package of e3 ${forPlatform}: where it cannot, the build is checked at the platform's move, before it deploys. ${fitsHere}`);
|
|
746
|
+
}
|
|
747
|
+
else {
|
|
748
|
+
console.log(fitsHere);
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
// Prepared: the workspace's live apps the move still waits for a build of
|
|
752
|
+
if (response.type === 'staged') {
|
|
753
|
+
const left = stillToPrepare(await appList(baseUrl, repo, workspace, { token }), forPlatform);
|
|
754
|
+
console.log(left.length === 0
|
|
755
|
+
? `Every app of ${workspace} has a build for e3 ${forPlatform} prepared, or is built with it`
|
|
756
|
+
: `${workspace}'s apps with no build for e3 ${forPlatform} prepared yet: ${left.join(', ')}. The platform's move to it waits for a build of each, prepared as these are`);
|
|
757
|
+
}
|
|
320
758
|
// With its package: the deploy job, waited for, then the apps as it left them
|
|
321
759
|
if (response.type === 'deploying') {
|
|
322
760
|
let said = '';
|
|
@@ -400,7 +838,7 @@ export const appCommand = {
|
|
|
400
838
|
// Those a platform deploy to another e3 needs a bundle for, and those it has
|
|
401
839
|
const rebuild = apps.filter((app) => app.current.builtWith !== platform
|
|
402
840
|
&& !(app.staged.type === 'some' && app.staged.value.forPlatform === platform));
|
|
403
|
-
console.log(`\nThe platform runs e3 ${platform}: ${rebuild.length === 0 ? 'every app is built with it, or has a
|
|
841
|
+
console.log(`\nThe platform runs e3 ${platform}: ${rebuild.length === 0 ? 'every app is built with it, or has a build prepared for it' : `${rebuild.length} ${rebuild.length === 1 ? 'app needs' : 'apps need'} a build of it prepared`}.`);
|
|
404
842
|
}
|
|
405
843
|
catch (err) {
|
|
406
844
|
exitError(describe(err));
|
|
@@ -431,6 +869,33 @@ export const appCommand = {
|
|
|
431
869
|
exitError(describe(err));
|
|
432
870
|
}
|
|
433
871
|
},
|
|
872
|
+
/** e3-cloud app remove-prepared <repoUrl> <workspace> <app> [--force] */
|
|
873
|
+
async removePrepared(url, workspace, name, options = {}) {
|
|
874
|
+
try {
|
|
875
|
+
const force = options.force === true;
|
|
876
|
+
if (force)
|
|
877
|
+
console.warn(FORCE_WARNING(workspace, 'removal'));
|
|
878
|
+
const { baseUrl, repo } = parseRepoUrl(url);
|
|
879
|
+
const token = await getValidToken(baseUrl);
|
|
880
|
+
const before = await appGet(baseUrl, repo, workspace, name, { token });
|
|
881
|
+
let removed;
|
|
882
|
+
try {
|
|
883
|
+
removed = await appRemoveStaged(baseUrl, repo, workspace, name, { token }, { force });
|
|
884
|
+
}
|
|
885
|
+
catch (err) {
|
|
886
|
+
// A protected workspace's prepared builds change by a release from its staging
|
|
887
|
+
if (err instanceof ApiError && err.code === 'workspace_protected') {
|
|
888
|
+
exitError(`${describe(err)}\nRemove ${name}'s prepared build on ${workspace}'s staging (e3-cloud app remove-prepared ${url} <staging> ${name}), then release the staging to ${workspace}, which clears it here; an admin alone forces it here with --force`);
|
|
889
|
+
}
|
|
890
|
+
throw err;
|
|
891
|
+
}
|
|
892
|
+
const was = before.staged.type === 'some' ? ` for e3 ${before.staged.value.forPlatform}, with ${packageWords(before.staged.value.package)},` : '';
|
|
893
|
+
console.log(`${removed.name}'s build${was} prepared on ${workspace} is removed: v${removed.current.number} stays live on ${packageWords(removed.current.package)}, and the platform's move waits for a build of it, prepared again`);
|
|
894
|
+
}
|
|
895
|
+
catch (err) {
|
|
896
|
+
exitError(describe(err));
|
|
897
|
+
}
|
|
898
|
+
},
|
|
434
899
|
/** e3-cloud app remove <repoUrl> <workspace> <app> */
|
|
435
900
|
async remove(url, workspace, name, options = {}) {
|
|
436
901
|
try {
|