@solidactions/cli 3.27.0 → 3.28.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/dist/commands/deploy.js
CHANGED
|
@@ -29,6 +29,7 @@ const prompts_1 = __importDefault(require("prompts"));
|
|
|
29
29
|
const env_1 = require("../utils/env");
|
|
30
30
|
const validate_items_1 = require("../utils/validate-items");
|
|
31
31
|
const pages_sync_1 = require("../utils/pages-sync");
|
|
32
|
+
const functions_sync_1 = require("../utils/functions-sync");
|
|
32
33
|
const api_1 = require("../utils/api");
|
|
33
34
|
const host_display_1 = require("../utils/host-display");
|
|
34
35
|
const deploy_ignore_1 = require("../utils/deploy-ignore");
|
|
@@ -616,6 +617,36 @@ async function deploy(projectName, sourcePath, options = {}) {
|
|
|
616
617
|
console.error(chalk_1.default.red(`Failed to read page: ${error.message}`));
|
|
617
618
|
process.exit(1);
|
|
618
619
|
}
|
|
620
|
+
const codeRef = sourceMetadata ? {
|
|
621
|
+
branch: sourceMetadata.branch,
|
|
622
|
+
short_sha: sourceMetadata.short_sha,
|
|
623
|
+
commit_sha: sourceMetadata.commit_sha,
|
|
624
|
+
dirty: sourceMetadata.dirty,
|
|
625
|
+
} : null;
|
|
626
|
+
// Functions sync runs before the workflow archive build (spec 3.1): the
|
|
627
|
+
// server compiles and uploads each code function on its own. Editor
|
|
628
|
+
// pointers are never sent (listCodeFunctions skips them).
|
|
629
|
+
const functionFiles = (0, functions_sync_1.listCodeFunctions)(yamlConfig ?? {});
|
|
630
|
+
let functionSources;
|
|
631
|
+
try {
|
|
632
|
+
functionSources = (0, functions_sync_1.readFunctionSources)(sourceDir, functionFiles);
|
|
633
|
+
}
|
|
634
|
+
catch (error) {
|
|
635
|
+
console.error(chalk_1.default.red(`Failed to read function: ${error.message}`));
|
|
636
|
+
process.exit(1);
|
|
637
|
+
}
|
|
638
|
+
const functionsPayload = (0, functions_sync_1.buildFunctionsSyncPayload)(functionFiles, functionSources, codeRef);
|
|
639
|
+
const functionsResult = await (0, functions_sync_1.syncFunctions)(config, projectSlug, functionsPayload);
|
|
640
|
+
const functionRows = functionsResult.body?.functions ?? [];
|
|
641
|
+
const retiredFunctions = functionsResult.body?.retired ?? [];
|
|
642
|
+
const retireErrors = functionsResult.body?.retire_errors ?? [];
|
|
643
|
+
const functionsInput = { httpStatus: functionsResult.httpStatus, transportError: functionsResult.transportError, sentFunctionCount: functionFiles.length };
|
|
644
|
+
const functionsFailure = (0, functions_sync_1.formatFunctionsSyncFailure)({ ...functionsInput, body: functionsResult.body });
|
|
645
|
+
for (const line of (0, functions_sync_1.formatFunctionsSummary)(functionRows, retiredFunctions, retireErrors))
|
|
646
|
+
console.log(line);
|
|
647
|
+
if (functionsFailure)
|
|
648
|
+
console.error(chalk_1.default.red(functionsFailure));
|
|
649
|
+
const functionsOutcome = (0, functions_sync_1.functionsSyncOutcome)({ ...functionsInput, body: functionsResult.body, rows: functionRows, retireErrors });
|
|
619
650
|
const finishDeploy = async ({ deploymentId, buildFailed }) => {
|
|
620
651
|
let yamlSyncFailed = false;
|
|
621
652
|
if (yamlConfig) {
|
|
@@ -632,12 +663,6 @@ async function deploy(projectName, sourcePath, options = {}) {
|
|
|
632
663
|
}
|
|
633
664
|
}
|
|
634
665
|
}
|
|
635
|
-
const codeRef = sourceMetadata ? {
|
|
636
|
-
branch: sourceMetadata.branch,
|
|
637
|
-
short_sha: sourceMetadata.short_sha,
|
|
638
|
-
commit_sha: sourceMetadata.commit_sha,
|
|
639
|
-
dirty: sourceMetadata.dirty,
|
|
640
|
-
} : null;
|
|
641
666
|
const payload = (0, pages_sync_1.buildPagesSyncPayload)(pageFiles, pageBodies, deploymentId, codeRef);
|
|
642
667
|
const result = await (0, pages_sync_1.syncPages)(config, projectSlug, payload);
|
|
643
668
|
const rows = result.body?.pages ?? [];
|
|
@@ -649,7 +674,8 @@ async function deploy(projectName, sourcePath, options = {}) {
|
|
|
649
674
|
console.log(line);
|
|
650
675
|
if (failure)
|
|
651
676
|
console.error(chalk_1.default.red(failure));
|
|
652
|
-
const
|
|
677
|
+
const pagesOutcome = (0, pages_sync_1.pagesSyncOutcome)({ ...input, rows, trashErrors, stamp: result.body?.stamp });
|
|
678
|
+
const outcome = (0, functions_sync_1.joinSyncOutcomes)(functionsOutcome, pagesOutcome);
|
|
653
679
|
process.exit((0, pages_sync_1.terminalExitCode)({ buildFailed, yamlSyncFailed, outcome }));
|
|
654
680
|
};
|
|
655
681
|
if (!yamlConfig?.workflows) {
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.FUNCTIONS_SYNC_TIMEOUT_MS = void 0;
|
|
7
|
+
exports.listCodeFunctions = listCodeFunctions;
|
|
8
|
+
exports.readFunctionSources = readFunctionSources;
|
|
9
|
+
exports.buildFunctionsSyncPayload = buildFunctionsSyncPayload;
|
|
10
|
+
exports.formatFunctionsSummary = formatFunctionsSummary;
|
|
11
|
+
exports.functionsSyncOutcome = functionsSyncOutcome;
|
|
12
|
+
exports.joinSyncOutcomes = joinSyncOutcomes;
|
|
13
|
+
exports.formatFunctionsSyncFailure = formatFunctionsSyncFailure;
|
|
14
|
+
exports.syncFunctions = syncFunctions;
|
|
15
|
+
const fs_1 = __importDefault(require("fs"));
|
|
16
|
+
const path_1 = __importDefault(require("path"));
|
|
17
|
+
const axios_1 = __importDefault(require("axios"));
|
|
18
|
+
const api_1 = require("./api");
|
|
19
|
+
function listCodeFunctions(config) {
|
|
20
|
+
return (config.functions ?? []).filter(entry => typeof entry === 'object' && entry !== null && entry.owner !== 'editor').map(entry => {
|
|
21
|
+
const fn = entry;
|
|
22
|
+
return {
|
|
23
|
+
id: fn.id,
|
|
24
|
+
name: fn.name,
|
|
25
|
+
file: fn.file,
|
|
26
|
+
...(fn.description === undefined ? {} : { description: fn.description }),
|
|
27
|
+
...(fn.webhook === undefined ? {} : { webhook: fn.webhook }),
|
|
28
|
+
...(fn.webhook_auth === undefined ? {} : { webhook_auth: fn.webhook_auth }),
|
|
29
|
+
...(fn.mcp === undefined ? {} : { mcp: fn.mcp }),
|
|
30
|
+
...(fn.mcp_tool_name === undefined ? {} : { mcp_tool_name: fn.mcp_tool_name }),
|
|
31
|
+
...(fn.timeout === undefined ? {} : { timeout: fn.timeout }),
|
|
32
|
+
...(fn.confirm === undefined ? {} : { confirm: fn.confirm }),
|
|
33
|
+
...(fn.input_schema === undefined ? {} : { input_schema: fn.input_schema }),
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function readFunctionSources(sourceDir, functions) {
|
|
38
|
+
return new Map(functions.map(fn => [fn.id, fs_1.default.readFileSync(path_1.default.join(sourceDir, fn.file), 'utf8')]));
|
|
39
|
+
}
|
|
40
|
+
function buildFunctionsSyncPayload(functions, sources, codeRef) {
|
|
41
|
+
return { code_ref: codeRef, functions: functions.map(fn => ({ ...fn, source: sources.get(fn.id) })) };
|
|
42
|
+
}
|
|
43
|
+
function formatFunctionsSummary(rows, retired, retireErrors) {
|
|
44
|
+
return [
|
|
45
|
+
...rows.map(row => row.status === 'error'
|
|
46
|
+
? `function ${row.id}: error ${row.error.code}: ${row.error.message}`
|
|
47
|
+
: `function ${row.id}: ${row.status}${row.webhook_url === null ? '' : ` ${row.webhook_url}`}`),
|
|
48
|
+
...retired.map(row => `function ${row.id}: retired`),
|
|
49
|
+
...retireErrors.map(row => `function ${row.id}: retired, its script delete failed and will retry: ${row.error.message}`),
|
|
50
|
+
];
|
|
51
|
+
}
|
|
52
|
+
function responseBodyCode(body) {
|
|
53
|
+
if (body !== null && typeof body === 'object' && 'code' in body && typeof body.code === 'string')
|
|
54
|
+
return body.code;
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
function functionsSyncOutcome(input) {
|
|
58
|
+
if (input.transportError)
|
|
59
|
+
return 'failed';
|
|
60
|
+
if (input.httpStatus === 404 && input.sentFunctionCount === 0)
|
|
61
|
+
return 'skipped-old-server';
|
|
62
|
+
if (input.httpStatus === 503 && input.sentFunctionCount === 0 && responseBodyCode(input.body) === 'functions_disabled')
|
|
63
|
+
return 'skipped-old-server';
|
|
64
|
+
if (input.httpStatus === null || input.httpStatus < 200 || input.httpStatus >= 300)
|
|
65
|
+
return 'failed';
|
|
66
|
+
return input.rows.some(row => row.status === 'error') ? 'failed' : 'ok';
|
|
67
|
+
}
|
|
68
|
+
/** Joins the functions and pages outcomes for the deploy exit code. */
|
|
69
|
+
function joinSyncOutcomes(functionsOutcome, pagesOutcome) {
|
|
70
|
+
if (functionsOutcome === 'failed' || pagesOutcome === 'failed')
|
|
71
|
+
return 'failed';
|
|
72
|
+
if (functionsOutcome === 'ok' || pagesOutcome === 'ok')
|
|
73
|
+
return 'ok';
|
|
74
|
+
return 'skipped-old-server';
|
|
75
|
+
}
|
|
76
|
+
function formatFunctionsSyncFailure(input) {
|
|
77
|
+
if (input.transportError)
|
|
78
|
+
return 'functions sync failed: could not reach the server';
|
|
79
|
+
if (input.httpStatus !== null && input.httpStatus >= 200 && input.httpStatus < 300)
|
|
80
|
+
return null;
|
|
81
|
+
if (input.httpStatus === 404)
|
|
82
|
+
return input.sentFunctionCount === 0 ? null : 'This server does not support functions yet; upgrade the platform';
|
|
83
|
+
if (input.httpStatus === 503 && input.sentFunctionCount === 0 && responseBodyCode(input.body) === 'functions_disabled')
|
|
84
|
+
return null;
|
|
85
|
+
if (input.body !== null && typeof input.body === 'object' && 'code' in input.body && 'message' in input.body && typeof input.body.code === 'string' && typeof input.body.message === 'string') {
|
|
86
|
+
return `functions sync failed (${input.httpStatus} ${input.body.code}): ${input.body.message}`;
|
|
87
|
+
}
|
|
88
|
+
// Laravel's own validation 422 carries `message` and `errors` but no `code`.
|
|
89
|
+
if (input.body !== null && typeof input.body === 'object' && 'message' in input.body && typeof input.body.message === 'string') {
|
|
90
|
+
return `functions sync failed (HTTP ${input.httpStatus}): ${input.body.message}`;
|
|
91
|
+
}
|
|
92
|
+
return `functions sync failed (HTTP ${input.httpStatus})`;
|
|
93
|
+
}
|
|
94
|
+
/** HTTP client timeout for the functions/sync call (P7: the server holds the request up to 180 s). */
|
|
95
|
+
exports.FUNCTIONS_SYNC_TIMEOUT_MS = 210_000;
|
|
96
|
+
async function syncFunctions(config, projectSlug, payload) {
|
|
97
|
+
try {
|
|
98
|
+
const response = await axios_1.default.put(`${config.host}/api/v1/projects/${encodeURIComponent(projectSlug)}/functions/sync`, payload, { headers: (0, api_1.getApiHeaders)(config, 'application/json'), timeout: exports.FUNCTIONS_SYNC_TIMEOUT_MS });
|
|
99
|
+
return { httpStatus: response.status, transportError: false, body: response.data };
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
return { httpStatus: error.response?.status ?? null, transportError: !error.response, body: error.response?.data ?? null };
|
|
103
|
+
}
|
|
104
|
+
}
|