eas-cli 24.4.2 → 24.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +133 -133
- package/build/build/build.js +71 -17
- package/build/build/logs.d.ts +10 -0
- package/build/build/logs.js +91 -0
- package/build/commandUtils/logs/format.d.ts +10 -0
- package/build/commandUtils/logs/format.js +21 -0
- package/build/commandUtils/logs/parseLogs.d.ts +7 -0
- package/build/commandUtils/{workflow/logs → logs}/parseLogs.js +1 -21
- package/build/commandUtils/logs/state.d.ts +14 -0
- package/build/commandUtils/logs/state.js +71 -0
- package/build/commandUtils/logs/types.d.ts +19 -0
- package/build/commandUtils/logs/types.js +2 -0
- package/build/commandUtils/logs/watcher.d.ts +23 -0
- package/build/commandUtils/logs/watcher.js +80 -0
- package/build/commandUtils/workflow/{logs/fetchLogs.d.ts → fetchLogs.d.ts} +2 -2
- package/build/commandUtils/workflow/{logs/fetchLogs.js → fetchLogs.js} +1 -1
- package/build/commandUtils/workflow/logs.d.ts +8 -0
- package/build/commandUtils/workflow/logs.js +43 -0
- package/build/commandUtils/workflow/stateMachine.d.ts +4 -3
- package/build/commandUtils/workflow/stateMachine.js +4 -3
- package/build/commandUtils/workflow/types.d.ts +0 -19
- package/build/commandUtils/workflow/utils.d.ts +3 -7
- package/build/commandUtils/workflow/utils.js +12 -29
- package/build/commands/go.js +15 -16
- package/build/credentials/manager/ManageIos.js +2 -2
- package/build/credentials/manager/SetUpIosBuildCredentials.js +2 -2
- package/build/graphql/generated.d.ts +206 -17
- package/build/graphql/generated.js +22 -2
- package/build/graphql/queries/UserQuery.d.ts +2 -1
- package/build/graphql/queries/UserQuery.js +39 -23
- package/build/graphql/types/Actor.d.ts +1 -0
- package/build/graphql/types/Actor.js +34 -0
- package/build/ora.d.ts +1 -0
- package/build/ora.js +5 -1
- package/build/utils/centrifuge.js +2 -0
- package/oclif.manifest.json +1796 -1796
- package/package.json +5 -5
- package/build/commandUtils/workflow/logs/parseLogs.d.ts +0 -14
- package/build/commandUtils/workflow/logs/watcher.d.ts +0 -32
- package/build/commandUtils/workflow/logs/watcher.js +0 -162
- package/build/user/actions.d.ts +0 -3
- package/build/user/actions.js +0 -9
package/build/build/build.js
CHANGED
|
@@ -13,6 +13,7 @@ const nullthrows_1 = tslib_1.__importDefault(require("nullthrows"));
|
|
|
13
13
|
const errors_1 = require("./errors");
|
|
14
14
|
const graphql_1 = require("./graphql");
|
|
15
15
|
const local_1 = require("./local");
|
|
16
|
+
const logs_1 = require("./logs");
|
|
16
17
|
const metadata_1 = require("./metadata");
|
|
17
18
|
const printBuildInfo_1 = require("./utils/printBuildInfo");
|
|
18
19
|
const repository_1 = require("./utils/repository");
|
|
@@ -20,6 +21,7 @@ const AnalyticsManager_1 = require("../analytics/AnalyticsManager");
|
|
|
20
21
|
const common_1 = require("../analytics/common");
|
|
21
22
|
const api_1 = require("../api");
|
|
22
23
|
const plans_1 = require("../billing/plans");
|
|
24
|
+
const watcher_1 = require("../commandUtils/logs/watcher");
|
|
23
25
|
const cli_1 = require("../fingerprint/cli");
|
|
24
26
|
const generated_1 = require("../graphql/generated");
|
|
25
27
|
const BuildMutation_1 = require("../graphql/mutations/BuildMutation");
|
|
@@ -30,6 +32,7 @@ const platform_1 = require("../platform");
|
|
|
30
32
|
const maybeUploadFingerprintAsync_1 = require("../project/maybeUploadFingerprintAsync");
|
|
31
33
|
const resolveRuntimeVersionAsync_1 = require("../project/resolveRuntimeVersionAsync");
|
|
32
34
|
const uploads_1 = require("../uploads");
|
|
35
|
+
const centrifuge_1 = require("../utils/centrifuge");
|
|
33
36
|
const files_1 = require("../utils/files");
|
|
34
37
|
const json_1 = require("../utils/json");
|
|
35
38
|
const progress_1 = require("../utils/progress");
|
|
@@ -347,16 +350,45 @@ async function waitForBuildEndAsync(graphqlClient, { buildIds, accountName }, {
|
|
|
347
350
|
originalSpinnerText = 'Waiting for builds to complete. You can press Ctrl+C to exit.';
|
|
348
351
|
spinner = (0, ora_1.ora)('Waiting for builds to complete. You can press Ctrl+C to exit.').start();
|
|
349
352
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
353
|
+
let render = () => { };
|
|
354
|
+
const watcher = (0, ora_1.isSpinnerEnabled)()
|
|
355
|
+
? new watcher_1.LogsWatcher(() => (0, centrifuge_1.createRealtimeLogsClient)(graphqlClient), () => {
|
|
356
|
+
render();
|
|
357
|
+
})
|
|
358
|
+
: null;
|
|
359
|
+
try {
|
|
360
|
+
while (true) {
|
|
361
|
+
render = () => { };
|
|
362
|
+
const builds = await getBuildsSafelyAsync(graphqlClient, buildIds);
|
|
363
|
+
const logsStates = await syncBuildLogsAsync(watcher, builds);
|
|
364
|
+
const installRender = (nextRender) => {
|
|
365
|
+
render = nextRender;
|
|
366
|
+
};
|
|
367
|
+
const { refetch } = builds.length === 1
|
|
368
|
+
? await handleSingleBuildProgressAsync({ build: builds[0], accountName }, { spinner, logsStates, installRender })
|
|
369
|
+
: await handleMultipleBuildsProgressAsync({ builds }, { spinner, originalSpinnerText, logsStates, installRender });
|
|
370
|
+
if (!refetch) {
|
|
371
|
+
return builds;
|
|
372
|
+
}
|
|
373
|
+
await (0, promise_1.sleepAsync)(intervalSec * 1000);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
finally {
|
|
377
|
+
watcher?.close();
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
async function syncBuildLogsAsync(watcher, builds) {
|
|
381
|
+
if (!watcher) {
|
|
382
|
+
return new Map();
|
|
383
|
+
}
|
|
384
|
+
const existingBuilds = builds.filter(isBuildFragment);
|
|
385
|
+
const logsStates = await watcher.syncAsync(existingBuilds.map(build => (0, logs_1.logSourceForBuild)(build)));
|
|
386
|
+
for (const build of existingBuilds) {
|
|
387
|
+
if ((0, logs_1.isBuildCompleted)(build.status)) {
|
|
388
|
+
(0, nullthrows_1.default)(logsStates.get(build.id), 'syncAsync must have been called before markCompleted').markCompleted();
|
|
357
389
|
}
|
|
358
|
-
await (0, promise_1.sleepAsync)(intervalSec * 1000);
|
|
359
390
|
}
|
|
391
|
+
return logsStates;
|
|
360
392
|
}
|
|
361
393
|
async function getBuildsSafelyAsync(graphqlClient, buildIds) {
|
|
362
394
|
const promises = buildIds.map(async (buildId) => {
|
|
@@ -374,9 +406,11 @@ let queueProgressBarStarted = false;
|
|
|
374
406
|
const queueProgressBar = new cli_progress_1.default.SingleBar({ format: '|{bar}| {estimatedWaitTime}' }, cli_progress_1.default.Presets.rect);
|
|
375
407
|
let statusNewSetAt = null;
|
|
376
408
|
const NEW_STATUS_GRACE_PERIOD_MS = 15_000;
|
|
377
|
-
async function handleSingleBuildProgressAsync({ build, accountName, }, { spinner }) {
|
|
409
|
+
async function handleSingleBuildProgressAsync({ build, accountName, }, { spinner, logsStates, installRender }) {
|
|
378
410
|
if (build === null) {
|
|
379
|
-
|
|
411
|
+
(0, ora_1.updateSpinnerText)(spinner, {
|
|
412
|
+
text: 'Could not fetch the build status. Check your network connection.',
|
|
413
|
+
});
|
|
380
414
|
return { refetch: true };
|
|
381
415
|
}
|
|
382
416
|
if (queueProgressBarStarted && build?.status && build.status !== generated_1.BuildStatus.InQueue) {
|
|
@@ -399,15 +433,17 @@ async function handleSingleBuildProgressAsync({ build, accountName, }, { spinner
|
|
|
399
433
|
statusNewSetAt ??= now;
|
|
400
434
|
const newStatusDurationMs = now - statusNewSetAt;
|
|
401
435
|
if (newStatusDurationMs < NEW_STATUS_GRACE_PERIOD_MS) {
|
|
402
|
-
spinner
|
|
436
|
+
(0, ora_1.updateSpinnerText)(spinner, { text: 'Waiting for build to get enqueued…' });
|
|
403
437
|
}
|
|
404
438
|
else {
|
|
405
|
-
|
|
439
|
+
(0, ora_1.updateSpinnerText)(spinner, {
|
|
440
|
+
text: `Build concurrency limit reached for your account. Build will enter queue once a concurrency becomes available. Add additional concurrencies at ${(0, log_1.link)(formatAccountBillingUrl(accountName))}.`,
|
|
441
|
+
});
|
|
406
442
|
}
|
|
407
443
|
break;
|
|
408
444
|
}
|
|
409
445
|
case generated_1.BuildStatus.InQueue: {
|
|
410
|
-
spinner
|
|
446
|
+
(0, ora_1.updateSpinnerText)(spinner, { text: 'Build queued...' });
|
|
411
447
|
const progressBarPayload = typeof build.estimatedWaitTimeLeftSeconds === 'number'
|
|
412
448
|
? { estimatedWaitTime: formatEstimatedWaitTime(build.estimatedWaitTimeLeftSeconds) }
|
|
413
449
|
: { estimatedWaitTime: '' };
|
|
@@ -435,9 +471,17 @@ async function handleSingleBuildProgressAsync({ build, accountName, }, { spinner
|
|
|
435
471
|
case generated_1.BuildStatus.Canceled:
|
|
436
472
|
spinner.fail('Build canceled');
|
|
437
473
|
return { refetch: false };
|
|
438
|
-
case generated_1.BuildStatus.InProgress:
|
|
439
|
-
|
|
474
|
+
case generated_1.BuildStatus.InProgress: {
|
|
475
|
+
const logsState = logsStates.get(build.id);
|
|
476
|
+
const render = () => {
|
|
477
|
+
(0, ora_1.updateSpinnerText)(spinner, {
|
|
478
|
+
text: (0, logs_1.formatActiveBuildText)('Build in progress...', logsState?.getLogs() ?? new Map()),
|
|
479
|
+
});
|
|
480
|
+
};
|
|
481
|
+
installRender(render);
|
|
482
|
+
render();
|
|
440
483
|
break;
|
|
484
|
+
}
|
|
441
485
|
case generated_1.BuildStatus.Errored:
|
|
442
486
|
spinner.fail('Build failed');
|
|
443
487
|
if (build.error) {
|
|
@@ -467,7 +511,7 @@ const statusToDisplayName = {
|
|
|
467
511
|
[generated_1.BuildStatus.Errored]: 'failed',
|
|
468
512
|
};
|
|
469
513
|
const platforms = [generated_1.AppPlatform.Android, generated_1.AppPlatform.Ios];
|
|
470
|
-
async function handleMultipleBuildsProgressAsync({ builds: maybeBuilds }, { spinner, originalSpinnerText }) {
|
|
514
|
+
async function handleMultipleBuildsProgressAsync({ builds: maybeBuilds }, { spinner, originalSpinnerText, logsStates, installRender, }) {
|
|
471
515
|
const buildCount = maybeBuilds.length;
|
|
472
516
|
const builds = maybeBuilds.filter(isBuildFragment);
|
|
473
517
|
const someNew = builds.some(build => build.status === generated_1.BuildStatus.New);
|
|
@@ -494,7 +538,17 @@ async function handleMultipleBuildsProgressAsync({ builds: maybeBuilds }, { spin
|
|
|
494
538
|
const showConcurrencyWarning = someNew &&
|
|
495
539
|
statusNewSetAt !== null &&
|
|
496
540
|
Date.now() - statusNewSetAt >= NEW_STATUS_GRACE_PERIOD_MS;
|
|
497
|
-
|
|
541
|
+
const pendingBuildsText = formatPendingBuildsText(originalSpinnerText, builds, showConcurrencyWarning);
|
|
542
|
+
const inProgressBuilds = builds.filter(build => build.status === generated_1.BuildStatus.InProgress);
|
|
543
|
+
const render = () => {
|
|
544
|
+
const text = (0, logs_1.formatActiveBuildsText)(pendingBuildsText, inProgressBuilds.map(build => ({
|
|
545
|
+
build,
|
|
546
|
+
logs: logsStates.get(build.id)?.getLogs() ?? new Map(),
|
|
547
|
+
})));
|
|
548
|
+
(0, ora_1.updateSpinnerText)(spinner, { text });
|
|
549
|
+
};
|
|
550
|
+
installRender(render);
|
|
551
|
+
render();
|
|
498
552
|
return { refetch: true };
|
|
499
553
|
}
|
|
500
554
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { JobLogs } from '../commandUtils/logs/types';
|
|
2
|
+
import { LogSource } from '../commandUtils/logs/watcher';
|
|
3
|
+
import { BuildFragment, BuildStatus } from '../graphql/generated';
|
|
4
|
+
export declare function logSourceForBuild(build: BuildFragment): LogSource;
|
|
5
|
+
export declare function isBuildCompleted(status: BuildStatus): boolean;
|
|
6
|
+
export declare function formatActiveBuildText(baseText: string, logs: JobLogs): string;
|
|
7
|
+
export declare function formatActiveBuildsText(baseText: string, buildsWithLogs: {
|
|
8
|
+
build: BuildFragment;
|
|
9
|
+
logs: JobLogs;
|
|
10
|
+
}[]): string;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logSourceForBuild = logSourceForBuild;
|
|
4
|
+
exports.isBuildCompleted = isBuildCompleted;
|
|
5
|
+
exports.formatActiveBuildText = formatActiveBuildText;
|
|
6
|
+
exports.formatActiveBuildsText = formatActiveBuildsText;
|
|
7
|
+
const tslib_1 = require("tslib");
|
|
8
|
+
const eas_build_job_1 = require("@expo/eas-build-job");
|
|
9
|
+
const format_1 = require("../commandUtils/logs/format");
|
|
10
|
+
const parseLogs_1 = require("../commandUtils/logs/parseLogs");
|
|
11
|
+
const fetch_1 = tslib_1.__importDefault(require("../fetch"));
|
|
12
|
+
const generated_1 = require("../graphql/generated");
|
|
13
|
+
const log_1 = tslib_1.__importDefault(require("../log"));
|
|
14
|
+
const platform_1 = require("../platform");
|
|
15
|
+
const formatFields_1 = tslib_1.__importDefault(require("../utils/formatFields"));
|
|
16
|
+
const LOGS_FETCH_TIMEOUT_MS = 5_000;
|
|
17
|
+
const SINGLE_BUILD_MAX_LOG_LINES = 5;
|
|
18
|
+
const MULTIPLE_BUILDS_MAX_LOG_LINES = 3;
|
|
19
|
+
async function fetchAndParseLogsForBuildAsync(build) {
|
|
20
|
+
const logFileUrl = build.logFiles[0];
|
|
21
|
+
if (!logFileUrl) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
const response = await (0, fetch_1.default)(logFileUrl, { timeout: LOGS_FETCH_TIMEOUT_MS });
|
|
25
|
+
const rawLogs = await response.text();
|
|
26
|
+
if (!rawLogs) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
const { logLines, errors } = (0, parseLogs_1.parseLogLines)(rawLogs);
|
|
30
|
+
for (const error of errors) {
|
|
31
|
+
log_1.default.debug(`Failed to parse a log line: ${error.message}`);
|
|
32
|
+
}
|
|
33
|
+
return logLines;
|
|
34
|
+
}
|
|
35
|
+
function logSourceForBuild(build) {
|
|
36
|
+
return {
|
|
37
|
+
key: build.id,
|
|
38
|
+
realtimeTarget: { type: generated_1.RealtimeLogsTargetType.Build, id: build.id },
|
|
39
|
+
isInProgress: build.status === generated_1.BuildStatus.InProgress,
|
|
40
|
+
fetchRawLogLinesAsync: async () => await fetchAndParseLogsForBuildAsync(build),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function isBuildCompleted(status) {
|
|
44
|
+
switch (status) {
|
|
45
|
+
case generated_1.BuildStatus.Finished:
|
|
46
|
+
case generated_1.BuildStatus.Errored:
|
|
47
|
+
case generated_1.BuildStatus.Canceled:
|
|
48
|
+
return true;
|
|
49
|
+
case generated_1.BuildStatus.New:
|
|
50
|
+
case generated_1.BuildStatus.InQueue:
|
|
51
|
+
case generated_1.BuildStatus.InProgress:
|
|
52
|
+
case generated_1.BuildStatus.PendingCancel:
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function stepDisplayName(label) {
|
|
57
|
+
return Object.hasOwn(eas_build_job_1.buildPhaseDisplayName, label)
|
|
58
|
+
? eas_build_job_1.buildPhaseDisplayName[label]
|
|
59
|
+
: label;
|
|
60
|
+
}
|
|
61
|
+
function activeBuildFields(logs, maxLogLines, buildLabel) {
|
|
62
|
+
const steps = (0, format_1.choicesFromJobLogs)(logs);
|
|
63
|
+
if (steps.length === 0) {
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
const currentStep = steps[steps.length - 1];
|
|
67
|
+
const fields = [{ label: '', value: '' }];
|
|
68
|
+
if (buildLabel !== null) {
|
|
69
|
+
fields.push({ label: ' Build', value: buildLabel });
|
|
70
|
+
}
|
|
71
|
+
fields.push({ label: ' Current phase', value: stepDisplayName(currentStep.name) });
|
|
72
|
+
if (currentStep.logLines?.length) {
|
|
73
|
+
fields.push({ label: ' Current logs', value: '' });
|
|
74
|
+
for (const logLine of (0, format_1.stepLogTail)(currentStep, maxLogLines)) {
|
|
75
|
+
fields.push({ label: '', value: logLine });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return fields;
|
|
79
|
+
}
|
|
80
|
+
function appendFields(baseText, fields) {
|
|
81
|
+
if (fields.length === 0) {
|
|
82
|
+
return baseText;
|
|
83
|
+
}
|
|
84
|
+
return `${baseText}\n${(0, formatFields_1.default)(fields)}`;
|
|
85
|
+
}
|
|
86
|
+
function formatActiveBuildText(baseText, logs) {
|
|
87
|
+
return appendFields(baseText, activeBuildFields(logs, SINGLE_BUILD_MAX_LOG_LINES, null));
|
|
88
|
+
}
|
|
89
|
+
function formatActiveBuildsText(baseText, buildsWithLogs) {
|
|
90
|
+
return appendFields(baseText, buildsWithLogs.flatMap(({ build, logs }) => activeBuildFields(logs, MULTIPLE_BUILDS_MAX_LOG_LINES, `${platform_1.appPlatformEmojis[build.platform]} ${platform_1.appPlatformDisplayNames[build.platform]}`)));
|
|
91
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { JobLogs, LogLine } from './types';
|
|
2
|
+
import { Choice } from '../../prompts';
|
|
3
|
+
export declare function choicesFromJobLogs(logs: JobLogs): (Choice & {
|
|
4
|
+
name: string;
|
|
5
|
+
status: string;
|
|
6
|
+
logLines: LogLine[] | undefined;
|
|
7
|
+
})[];
|
|
8
|
+
export declare function stepLogTail(step: {
|
|
9
|
+
logLines?: LogLine[];
|
|
10
|
+
}, maxLogLines: number): string[];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.choicesFromJobLogs = choicesFromJobLogs;
|
|
4
|
+
exports.stepLogTail = stepLogTail;
|
|
5
|
+
function choicesFromJobLogs(logs) {
|
|
6
|
+
return Array.from(logs.values())
|
|
7
|
+
.map(({ key, label, result, logLines }) => ({
|
|
8
|
+
title: `${label} - ${result ?? ''}`,
|
|
9
|
+
name: label,
|
|
10
|
+
status: result ?? '',
|
|
11
|
+
value: key,
|
|
12
|
+
logLines,
|
|
13
|
+
}))
|
|
14
|
+
.filter(step => step.status !== 'skipped');
|
|
15
|
+
}
|
|
16
|
+
function stepLogTail(step, maxLogLines // -1 means no limit
|
|
17
|
+
) {
|
|
18
|
+
const logLines = step.logLines ?? [];
|
|
19
|
+
const tail = maxLogLines === -1 ? logLines : logLines.slice(-maxLogLines);
|
|
20
|
+
return tail.map(line => line.msg);
|
|
21
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { JobLogs, RawLogLine } from './types';
|
|
2
|
+
export declare function parseLogLines(rawLogs: string): {
|
|
3
|
+
logLines: RawLogLine[];
|
|
4
|
+
errors: Error[];
|
|
5
|
+
};
|
|
6
|
+
export declare function mergeLogLines<T extends RawLogLine>(...logLineGroups: T[][]): T[];
|
|
7
|
+
export declare function groupLogLinesIntoSteps(logLines: RawLogLine[], accumulator?: JobLogs): JobLogs;
|
|
@@ -3,12 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.parseLogLines = parseLogLines;
|
|
4
4
|
exports.mergeLogLines = mergeLogLines;
|
|
5
5
|
exports.groupLogLinesIntoSteps = groupLogLinesIntoSteps;
|
|
6
|
-
exports.fetchAndParseLogsFromJobAsync = fetchAndParseLogsFromJobAsync;
|
|
7
|
-
exports.fetchAndProcessLogsFromJobAsync = fetchAndProcessLogsFromJobAsync;
|
|
8
6
|
const tslib_1 = require("tslib");
|
|
9
|
-
const
|
|
10
|
-
const log_1 = tslib_1.__importDefault(require("../../../log"));
|
|
11
|
-
const uniqBy_1 = tslib_1.__importDefault(require("../../../utils/expodash/uniqBy"));
|
|
7
|
+
const uniqBy_1 = tslib_1.__importDefault(require("../../utils/expodash/uniqBy"));
|
|
12
8
|
function parseLogLines(rawLogs) {
|
|
13
9
|
const logLines = [];
|
|
14
10
|
const errors = [];
|
|
@@ -51,19 +47,3 @@ function groupLogLinesIntoSteps(logLines, accumulator = new Map()) {
|
|
|
51
47
|
}
|
|
52
48
|
return accumulator;
|
|
53
49
|
}
|
|
54
|
-
async function fetchAndParseLogsFromJobAsync(state, job) {
|
|
55
|
-
const rawLogs = await (0, fetchLogs_1.fetchRawLogsForJobAsync)(state, job);
|
|
56
|
-
if (!rawLogs) {
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
log_1.default.debug(`rawLogs = ${JSON.stringify(rawLogs, null, 2)}`);
|
|
60
|
-
const { logLines, errors } = parseLogLines(rawLogs);
|
|
61
|
-
for (const error of errors) {
|
|
62
|
-
log_1.default.debug(`Failed to parse a log line: ${error.message}`);
|
|
63
|
-
}
|
|
64
|
-
return logLines;
|
|
65
|
-
}
|
|
66
|
-
async function fetchAndProcessLogsFromJobAsync(state, job) {
|
|
67
|
-
const logLines = await fetchAndParseLogsFromJobAsync(state, job);
|
|
68
|
-
return logLines && groupLogLinesIntoSteps(logLines);
|
|
69
|
-
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { JobLogs, RawLogLine } from './types';
|
|
2
|
+
export declare class LogsState {
|
|
3
|
+
private fileLogIds;
|
|
4
|
+
private realtimeLogLines;
|
|
5
|
+
private realtimeLogIds;
|
|
6
|
+
private haveFileLogsCaughtUp;
|
|
7
|
+
private realtimeLogsRevealed;
|
|
8
|
+
private jobLogs;
|
|
9
|
+
ingestFileLogLines(logLines: RawLogLine[]): void;
|
|
10
|
+
ingestRealtimeLogLines(data: unknown): boolean;
|
|
11
|
+
markCompleted(): void;
|
|
12
|
+
getLogs(): JobLogs;
|
|
13
|
+
private revealRealtimeLogs;
|
|
14
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LogsState = void 0;
|
|
4
|
+
const parseLogs_1 = require("./parseLogs");
|
|
5
|
+
function isRealtimeLogLine(entry) {
|
|
6
|
+
return (typeof entry === 'object' &&
|
|
7
|
+
entry !== null &&
|
|
8
|
+
typeof entry.logId === 'string');
|
|
9
|
+
}
|
|
10
|
+
class LogsState {
|
|
11
|
+
fileLogIds = new Set();
|
|
12
|
+
realtimeLogLines = [];
|
|
13
|
+
realtimeLogIds = new Set();
|
|
14
|
+
haveFileLogsCaughtUp = false;
|
|
15
|
+
realtimeLogsRevealed = false;
|
|
16
|
+
jobLogs = new Map();
|
|
17
|
+
ingestFileLogLines(logLines) {
|
|
18
|
+
this.fileLogIds = new Set(logLines.flatMap(logLine => (logLine.logId ? [logLine.logId] : [])));
|
|
19
|
+
if (!this.haveFileLogsCaughtUp &&
|
|
20
|
+
this.realtimeLogLines.some(logLine => this.fileLogIds.has(logLine.logId))) {
|
|
21
|
+
this.haveFileLogsCaughtUp = true;
|
|
22
|
+
}
|
|
23
|
+
this.realtimeLogLines = this.realtimeLogLines.filter(logLine => !this.fileLogIds.has(logLine.logId));
|
|
24
|
+
this.realtimeLogIds = new Set(this.realtimeLogLines.map(logLine => logLine.logId));
|
|
25
|
+
if (this.haveFileLogsCaughtUp) {
|
|
26
|
+
this.realtimeLogsRevealed = true;
|
|
27
|
+
}
|
|
28
|
+
this.jobLogs = (0, parseLogs_1.groupLogLinesIntoSteps)((0, parseLogs_1.mergeLogLines)(logLines, this.realtimeLogsRevealed ? this.realtimeLogLines : []));
|
|
29
|
+
}
|
|
30
|
+
ingestRealtimeLogLines(data) {
|
|
31
|
+
if (!Array.isArray(data)) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
const publishedLogLines = data.filter(isRealtimeLogLine);
|
|
35
|
+
if (publishedLogLines.length === 0) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
if (!this.haveFileLogsCaughtUp &&
|
|
39
|
+
publishedLogLines.some(logLine => this.fileLogIds.has(logLine.logId))) {
|
|
40
|
+
this.haveFileLogsCaughtUp = true;
|
|
41
|
+
}
|
|
42
|
+
const newLogLines = publishedLogLines.filter(logLine => !this.fileLogIds.has(logLine.logId) && !this.realtimeLogIds.has(logLine.logId));
|
|
43
|
+
for (const logLine of newLogLines) {
|
|
44
|
+
this.realtimeLogLines.push(logLine);
|
|
45
|
+
this.realtimeLogIds.add(logLine.logId);
|
|
46
|
+
}
|
|
47
|
+
if (!this.realtimeLogsRevealed) {
|
|
48
|
+
if (this.haveFileLogsCaughtUp) {
|
|
49
|
+
this.revealRealtimeLogs();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else if (newLogLines.length > 0) {
|
|
53
|
+
(0, parseLogs_1.groupLogLinesIntoSteps)(newLogLines, this.jobLogs);
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
markCompleted() {
|
|
58
|
+
this.revealRealtimeLogs();
|
|
59
|
+
}
|
|
60
|
+
getLogs() {
|
|
61
|
+
return this.jobLogs;
|
|
62
|
+
}
|
|
63
|
+
revealRealtimeLogs() {
|
|
64
|
+
if (this.realtimeLogsRevealed) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
this.realtimeLogsRevealed = true;
|
|
68
|
+
(0, parseLogs_1.groupLogLinesIntoSteps)(this.realtimeLogLines, this.jobLogs);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.LogsState = LogsState;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type RawLogLine = {
|
|
2
|
+
logId?: string;
|
|
3
|
+
buildStepId?: string;
|
|
4
|
+
buildStepDisplayName?: string;
|
|
5
|
+
phase?: string;
|
|
6
|
+
time?: string;
|
|
7
|
+
msg?: string;
|
|
8
|
+
result?: string;
|
|
9
|
+
marker?: string;
|
|
10
|
+
err?: any;
|
|
11
|
+
};
|
|
12
|
+
export type LogLine = Pick<RawLogLine, 'time' | 'result' | 'marker' | 'err'> & Required<Pick<RawLogLine, 'msg'>>;
|
|
13
|
+
export type StepLogs = {
|
|
14
|
+
key: string;
|
|
15
|
+
label: string;
|
|
16
|
+
result?: string;
|
|
17
|
+
logLines: LogLine[];
|
|
18
|
+
};
|
|
19
|
+
export type JobLogs = Map<string, StepLogs>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { LogsState } from './state';
|
|
2
|
+
import { RawLogLine } from './types';
|
|
3
|
+
import { RealtimeLogsTargetInput } from '../../graphql/generated';
|
|
4
|
+
import { RealtimeLogsClient } from '../../utils/centrifuge';
|
|
5
|
+
export type LogSource = {
|
|
6
|
+
key: string;
|
|
7
|
+
realtimeTarget: RealtimeLogsTargetInput | null;
|
|
8
|
+
isInProgress: boolean;
|
|
9
|
+
fetchRawLogLinesAsync: () => Promise<RawLogLine[] | null>;
|
|
10
|
+
};
|
|
11
|
+
export declare class LogsWatcher {
|
|
12
|
+
private readonly createRealtimeLogsClient;
|
|
13
|
+
private readonly onRealtimeLogs;
|
|
14
|
+
private readonly trackedSources;
|
|
15
|
+
private realtimeLogsClient?;
|
|
16
|
+
constructor(createRealtimeLogsClient: () => RealtimeLogsClient | null, onRealtimeLogs: () => void);
|
|
17
|
+
syncAsync(sources: LogSource[]): Promise<Map<string, LogsState>>;
|
|
18
|
+
close(): void;
|
|
19
|
+
private syncSourceAsync;
|
|
20
|
+
private fetchLogsAsync;
|
|
21
|
+
private getRealtimeLogsClient;
|
|
22
|
+
private subscribeAsync;
|
|
23
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LogsWatcher = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const state_1 = require("./state");
|
|
6
|
+
const log_1 = tslib_1.__importDefault(require("../../log"));
|
|
7
|
+
const nullthrows_1 = tslib_1.__importDefault(require("nullthrows"));
|
|
8
|
+
class LogsWatcher {
|
|
9
|
+
createRealtimeLogsClient;
|
|
10
|
+
onRealtimeLogs;
|
|
11
|
+
trackedSources = new Map();
|
|
12
|
+
realtimeLogsClient;
|
|
13
|
+
constructor(createRealtimeLogsClient, onRealtimeLogs) {
|
|
14
|
+
this.createRealtimeLogsClient = createRealtimeLogsClient;
|
|
15
|
+
this.onRealtimeLogs = onRealtimeLogs;
|
|
16
|
+
}
|
|
17
|
+
async syncAsync(sources) {
|
|
18
|
+
await Promise.all(sources.map(source => this.syncSourceAsync(source)));
|
|
19
|
+
return new Map(sources.map(source => [
|
|
20
|
+
source.key,
|
|
21
|
+
(0, nullthrows_1.default)(this.trackedSources.get(source.key), 'source has to be in tracked sources after it was synced').logsState,
|
|
22
|
+
]));
|
|
23
|
+
}
|
|
24
|
+
close() {
|
|
25
|
+
for (const trackedSource of this.trackedSources.values()) {
|
|
26
|
+
trackedSource.subscription?.close();
|
|
27
|
+
trackedSource.subscription = null;
|
|
28
|
+
}
|
|
29
|
+
this.realtimeLogsClient?.close();
|
|
30
|
+
}
|
|
31
|
+
async syncSourceAsync(source) {
|
|
32
|
+
let trackedSource = this.trackedSources.get(source.key);
|
|
33
|
+
if (!trackedSource) {
|
|
34
|
+
trackedSource = { logsState: new state_1.LogsState(), subscription: null };
|
|
35
|
+
this.trackedSources.set(source.key, trackedSource);
|
|
36
|
+
}
|
|
37
|
+
if (!source.isInProgress) {
|
|
38
|
+
trackedSource.subscription?.close();
|
|
39
|
+
trackedSource.subscription = null;
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
await Promise.all([
|
|
43
|
+
trackedSource.subscription ? Promise.resolve() : this.subscribeAsync(source, trackedSource),
|
|
44
|
+
this.fetchLogsAsync(source, trackedSource),
|
|
45
|
+
]);
|
|
46
|
+
}
|
|
47
|
+
async fetchLogsAsync(source, trackedSource) {
|
|
48
|
+
try {
|
|
49
|
+
const logLines = await source.fetchRawLogLinesAsync();
|
|
50
|
+
if (logLines) {
|
|
51
|
+
trackedSource.logsState.ingestFileLogLines(logLines);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
log_1.default.debug(`Failed to fetch logs for job ${source.key}: ${err.message}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
getRealtimeLogsClient() {
|
|
59
|
+
if (this.realtimeLogsClient === undefined) {
|
|
60
|
+
this.realtimeLogsClient = this.createRealtimeLogsClient();
|
|
61
|
+
}
|
|
62
|
+
return this.realtimeLogsClient;
|
|
63
|
+
}
|
|
64
|
+
async subscribeAsync(source, trackedSource) {
|
|
65
|
+
const target = source.realtimeTarget;
|
|
66
|
+
if (!target) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const realtimeLogsClient = this.getRealtimeLogsClient();
|
|
70
|
+
if (!realtimeLogsClient) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
trackedSource.subscription = await realtimeLogsClient.subscribeAsync({ target }, data => {
|
|
74
|
+
if (trackedSource.logsState.ingestRealtimeLogLines(data)) {
|
|
75
|
+
this.onRealtimeLogs();
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.LogsWatcher = LogsWatcher;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { WorkflowJobResult } from '
|
|
2
|
-
import { ExpoGraphqlClient } from '
|
|
1
|
+
import { WorkflowJobResult } from './types';
|
|
2
|
+
import { ExpoGraphqlClient } from '../context/contextUtils/createGraphqlClient';
|
|
3
3
|
export declare function fetchRawLogsForJobAsync(state: {
|
|
4
4
|
graphqlClient: ExpoGraphqlClient;
|
|
5
5
|
}, job: WorkflowJobResult): Promise<string | null>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.fetchRawLogsForJobAsync = fetchRawLogsForJobAsync;
|
|
4
|
-
const BuildQuery_1 = require("
|
|
4
|
+
const BuildQuery_1 = require("../../graphql/queries/BuildQuery");
|
|
5
5
|
async function fetchRawLogsForJobAsync(state, job) {
|
|
6
6
|
const turtleLogFileUrl = job.turtleJobRun?.logFileUrls?.[0];
|
|
7
7
|
if (turtleLogFileUrl) {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { WorkflowJobResult } from './types';
|
|
2
|
+
import { JobLogs } from '../logs/types';
|
|
3
|
+
import { LogSource } from '../logs/watcher';
|
|
4
|
+
import { ExpoGraphqlClient } from '../context/contextUtils/createGraphqlClient';
|
|
5
|
+
export declare function fetchAndProcessLogsFromJobAsync(state: {
|
|
6
|
+
graphqlClient: ExpoGraphqlClient;
|
|
7
|
+
}, job: WorkflowJobResult): Promise<JobLogs | null>;
|
|
8
|
+
export declare function logSourceForWorkflowJob(graphqlClient: ExpoGraphqlClient, job: WorkflowJobResult): LogSource;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchAndProcessLogsFromJobAsync = fetchAndProcessLogsFromJobAsync;
|
|
4
|
+
exports.logSourceForWorkflowJob = logSourceForWorkflowJob;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const fetchLogs_1 = require("./fetchLogs");
|
|
7
|
+
const generated_1 = require("../../graphql/generated");
|
|
8
|
+
const log_1 = tslib_1.__importDefault(require("../../log"));
|
|
9
|
+
const parseLogs_1 = require("../logs/parseLogs");
|
|
10
|
+
async function fetchAndParseLogsFromJobAsync(state, job) {
|
|
11
|
+
const rawLogs = await (0, fetchLogs_1.fetchRawLogsForJobAsync)(state, job);
|
|
12
|
+
if (!rawLogs) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
log_1.default.debug(`rawLogs = ${JSON.stringify(rawLogs, null, 2)}`);
|
|
16
|
+
const { logLines, errors } = (0, parseLogs_1.parseLogLines)(rawLogs);
|
|
17
|
+
for (const error of errors) {
|
|
18
|
+
log_1.default.debug(`Failed to parse a log line: ${error.message}`);
|
|
19
|
+
}
|
|
20
|
+
return logLines;
|
|
21
|
+
}
|
|
22
|
+
async function fetchAndProcessLogsFromJobAsync(state, job) {
|
|
23
|
+
const logLines = await fetchAndParseLogsFromJobAsync(state, job);
|
|
24
|
+
return logLines && (0, parseLogs_1.groupLogLinesIntoSteps)(logLines);
|
|
25
|
+
}
|
|
26
|
+
function logSourceForWorkflowJob(graphqlClient, job) {
|
|
27
|
+
return {
|
|
28
|
+
key: job.id,
|
|
29
|
+
realtimeTarget: realtimeLogsTargetForJob(job),
|
|
30
|
+
isInProgress: job.status === generated_1.WorkflowJobStatus.InProgress,
|
|
31
|
+
fetchRawLogLinesAsync: async () => await fetchAndParseLogsFromJobAsync({ graphqlClient }, job),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function realtimeLogsTargetForJob(job) {
|
|
35
|
+
if (job.turtleJobRun?.id) {
|
|
36
|
+
return { type: generated_1.RealtimeLogsTargetType.JobRun, id: job.turtleJobRun.id };
|
|
37
|
+
}
|
|
38
|
+
const buildId = job.turtleBuild?.id ?? job.outputs?.build_id;
|
|
39
|
+
if (buildId) {
|
|
40
|
+
return { type: generated_1.RealtimeLogsTargetType.Build, id: buildId };
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { WorkflowJobResult
|
|
1
|
+
import { WorkflowJobResult } from './types';
|
|
2
|
+
import { JobLogs } from '../logs/types';
|
|
2
3
|
import { ExpoGraphqlClient } from '../context/contextUtils/createGraphqlClient';
|
|
3
4
|
export declare enum WorkflowCommandSelectionStateValue {
|
|
4
5
|
WORKFLOW_RUN_SELECTION = "WORKFLOW_RUN_SELECTION",
|
|
@@ -17,7 +18,7 @@ export type WorkflowCommandSelectionState = {
|
|
|
17
18
|
jobId?: string;
|
|
18
19
|
step?: string;
|
|
19
20
|
job?: WorkflowJobResult;
|
|
20
|
-
logs?:
|
|
21
|
+
logs?: JobLogs | null;
|
|
21
22
|
message?: string;
|
|
22
23
|
};
|
|
23
24
|
export type WorkflowCommandSelectionStateParameters = Omit<WorkflowCommandSelectionState, 'graphqlClient' | 'projectId' | 'state' | 'nonInteractive' | 'allSteps'>;
|
|
@@ -35,7 +36,7 @@ export declare function moveToWorkflowStepSelectionState(previousState: Workflow
|
|
|
35
36
|
}): WorkflowCommandSelectionState;
|
|
36
37
|
export declare function moveToWorkflowSelectionFinishedState(previousState: WorkflowCommandSelectionState, params: {
|
|
37
38
|
step: string;
|
|
38
|
-
logs:
|
|
39
|
+
logs: JobLogs;
|
|
39
40
|
}): WorkflowCommandSelectionState;
|
|
40
41
|
export declare function moveToWorkflowSelectionErrorState(previousState: WorkflowCommandSelectionState, message: string): WorkflowCommandSelectionState;
|
|
41
42
|
export declare const workflowRunSelectionAction: WorkflowCommandSelectionAction;
|