@solidactions/cli 3.0.0 → 3.2.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 +16 -1
- package/dist/commands/connection-list.js +61 -0
- package/dist/commands/deploy.js +145 -14
- package/dist/commands/device-login.js +7 -5
- package/dist/commands/env-reset.js +60 -0
- package/dist/commands/env-set.js +19 -2
- package/dist/commands/login.js +201 -44
- package/dist/commands/project-view.js +134 -0
- package/dist/index.js +41 -3
- package/dist/utils/api.js +89 -5
- package/dist/utils/archiver-loader.cjs +1 -0
- package/dist/utils/config-write-target.js +47 -10
- package/dist/utils/source-provenance.js +241 -0
- package/dist/utils/tar-archive.js +12 -0
- package/package.json +6 -6
package/dist/utils/api.js
CHANGED
|
@@ -3,6 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SANDBOX_EGRESS_MESSAGE = void 0;
|
|
7
|
+
exports.augmentSandboxEgressMessage = augmentSandboxEgressMessage;
|
|
6
8
|
exports.augmentNotFoundMessage = augmentNotFoundMessage;
|
|
7
9
|
exports.augmentWorkspaceForbiddenMessage = augmentWorkspaceForbiddenMessage;
|
|
8
10
|
exports.getApiHeaders = getApiHeaders;
|
|
@@ -22,6 +24,85 @@ const workspace_lookup_1 = require("./workspace-lookup");
|
|
|
22
24
|
// We require the literal single-quotes around the slug so plausible future error messages
|
|
23
25
|
// like "Project files not found ..." don't false-match.
|
|
24
26
|
const NOT_FOUND_IN_WORKSPACE = /Project '.+' not found in your active workspace/;
|
|
27
|
+
exports.SANDBOX_EGRESS_MESSAGE = 'Sandbox network egress appears to be blocking app.solidactions.com. '
|
|
28
|
+
+ "Allow-list app.solidactions.com in your provider's network settings, "
|
|
29
|
+
+ 'start a new agent session if required, then retry. '
|
|
30
|
+
+ 'See https://www.solidactions.com/docs/troubleshooting/#sandbox-egress';
|
|
31
|
+
const SANDBOX_EGRESS_PHRASES = [
|
|
32
|
+
/\bhost (?:is )?not permitted\b/i,
|
|
33
|
+
/\bnetwork access denied\b/i,
|
|
34
|
+
/\bnetwork egress\b[\s\S]*?\b(?:blocked|disabled)\b/i,
|
|
35
|
+
/\bdestination\b[\s\S]*?\bnot allowed\b/i,
|
|
36
|
+
];
|
|
37
|
+
function responseServerHeader(headers) {
|
|
38
|
+
if (!headers) {
|
|
39
|
+
return '';
|
|
40
|
+
}
|
|
41
|
+
if (typeof headers.get === 'function') {
|
|
42
|
+
const value = headers.get('server') ?? headers.get('Server');
|
|
43
|
+
return value == null ? '' : String(value).trim();
|
|
44
|
+
}
|
|
45
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
46
|
+
if (name.toLowerCase() === 'server') {
|
|
47
|
+
return value == null ? '' : String(value).trim();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return '';
|
|
51
|
+
}
|
|
52
|
+
function flattenProxyResponseText(data) {
|
|
53
|
+
if (typeof data === 'string') {
|
|
54
|
+
return data;
|
|
55
|
+
}
|
|
56
|
+
if (data instanceof Error) {
|
|
57
|
+
return data.message;
|
|
58
|
+
}
|
|
59
|
+
if (!data || typeof data !== 'object' || Array.isArray(data)) {
|
|
60
|
+
return '';
|
|
61
|
+
}
|
|
62
|
+
return ['error', 'message']
|
|
63
|
+
.map((field) => flattenProxyResponseText(data[field]))
|
|
64
|
+
.filter(Boolean)
|
|
65
|
+
.join('\n');
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Diagnose a provider proxy's observed Cloud-host 403 without rewriting
|
|
69
|
+
* SolidActions authorization errors or failures against custom hosts.
|
|
70
|
+
*/
|
|
71
|
+
function augmentSandboxEgressMessage(error) {
|
|
72
|
+
const response = error?.response;
|
|
73
|
+
if (response?.status !== 403 || responseServerHeader(response.headers)) {
|
|
74
|
+
return error;
|
|
75
|
+
}
|
|
76
|
+
const data = response.data;
|
|
77
|
+
const responseCode = data && typeof data === 'object' && !Array.isArray(data)
|
|
78
|
+
? data.code
|
|
79
|
+
: null;
|
|
80
|
+
if (responseCode != null && String(responseCode).trim() !== '') {
|
|
81
|
+
return error;
|
|
82
|
+
}
|
|
83
|
+
const requestConfig = error.config ?? response.config;
|
|
84
|
+
let hostname = '';
|
|
85
|
+
try {
|
|
86
|
+
hostname = new URL(requestConfig?.url, requestConfig?.baseURL).hostname;
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return error;
|
|
90
|
+
}
|
|
91
|
+
if (hostname !== 'app.solidactions.com') {
|
|
92
|
+
return error;
|
|
93
|
+
}
|
|
94
|
+
const proxyText = flattenProxyResponseText(data).trim();
|
|
95
|
+
if (!proxyText || !SANDBOX_EGRESS_PHRASES.some((phrase) => phrase.test(proxyText))) {
|
|
96
|
+
return error;
|
|
97
|
+
}
|
|
98
|
+
error.message = exports.SANDBOX_EGRESS_MESSAGE;
|
|
99
|
+
response.data = {
|
|
100
|
+
...(data && typeof data === 'object' && !Array.isArray(data) ? data : {}),
|
|
101
|
+
message: `${exports.SANDBOX_EGRESS_MESSAGE}\n\nProvider response: ${proxyText}`,
|
|
102
|
+
providerResponse: data,
|
|
103
|
+
};
|
|
104
|
+
return error;
|
|
105
|
+
}
|
|
25
106
|
/**
|
|
26
107
|
* Inspect an axios error and, if its response message matches the new
|
|
27
108
|
* workspace-not-found 404 from solidactions-app PR #128, append a
|
|
@@ -54,7 +135,7 @@ function augmentWorkspaceForbiddenMessage(error) {
|
|
|
54
135
|
}
|
|
55
136
|
return error;
|
|
56
137
|
}
|
|
57
|
-
axios_1.default.interceptors.response.use((response) => response, (error) => Promise.reject(augmentWorkspaceForbiddenMessage(augmentNotFoundMessage(error))));
|
|
138
|
+
axios_1.default.interceptors.response.use((response) => response, (error) => Promise.reject(augmentWorkspaceForbiddenMessage(augmentNotFoundMessage(augmentSandboxEgressMessage(error)))));
|
|
58
139
|
function getApiHeaders(config, contentType) {
|
|
59
140
|
const headers = {
|
|
60
141
|
'Authorization': `Bearer ${config.apiKey}`,
|
|
@@ -165,6 +246,7 @@ async function ensureWorkspaceSelected(config) {
|
|
|
165
246
|
workspaces.push({
|
|
166
247
|
id: ws.id,
|
|
167
248
|
name: ws.name,
|
|
249
|
+
slug: ws.slug,
|
|
168
250
|
org_name: ws.tenant_name || orgName,
|
|
169
251
|
role: ws.role,
|
|
170
252
|
});
|
|
@@ -199,6 +281,11 @@ async function ensureWorkspaceSelected(config) {
|
|
|
199
281
|
console.log(chalk_1.default.gray(`Auto-selected workspace: ${selected.name}`));
|
|
200
282
|
}
|
|
201
283
|
else {
|
|
284
|
+
if (!process.stdin.isTTY) {
|
|
285
|
+
console.error(chalk_1.default.red('Multiple workspaces are available and no workspace is set for this config. '
|
|
286
|
+
+ 'Run `solidactions workspace set <name-or-id> --local` (or --global).'));
|
|
287
|
+
process.exit(1);
|
|
288
|
+
}
|
|
202
289
|
console.log(chalk_1.default.blue('\nSelect your default workspace (change anytime with `solidactions workspace set`):\n'));
|
|
203
290
|
workspaces.forEach((ws, i) => {
|
|
204
291
|
console.log(` ${chalk_1.default.white(`${i + 1}.`)} ${ws.name} ${chalk_1.default.gray(`(${ws.org_name}, ${ws.role})`)}`);
|
|
@@ -216,6 +303,7 @@ async function ensureWorkspaceSelected(config) {
|
|
|
216
303
|
}
|
|
217
304
|
selected = workspaces[index];
|
|
218
305
|
}
|
|
306
|
+
config.workspace = selected.slug ?? selected.name;
|
|
219
307
|
config.workspaceId = selected.id;
|
|
220
308
|
if (workspaceSource !== 'env') {
|
|
221
309
|
const targetPath = resolved?.activePath ?? (0, config_1.getGlobalConfigPath)();
|
|
@@ -235,9 +323,5 @@ async function requireConfigWithWorkspace() {
|
|
|
235
323
|
config = { ...config, workspace: ws.slug ?? ws.name, workspaceId: ws.id };
|
|
236
324
|
return config;
|
|
237
325
|
}
|
|
238
|
-
if (!config.workspaceId && !process.stdin.isTTY) {
|
|
239
|
-
console.error(chalk_1.default.red('No workspace set for this config. Run `solidactions workspace set <name-or-id> --local` (or --global).'));
|
|
240
|
-
process.exit(1);
|
|
241
|
-
}
|
|
242
326
|
return ensureWorkspaceSelected(config);
|
|
243
327
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = () => import('archiver');
|
|
@@ -12,6 +12,23 @@ const path_1 = __importDefault(require("path"));
|
|
|
12
12
|
const readline_1 = __importDefault(require("readline"));
|
|
13
13
|
const chalk_1 = __importDefault(require("chalk"));
|
|
14
14
|
const config_1 = require("./config");
|
|
15
|
+
async function askReadlineQuestion(rl, label) {
|
|
16
|
+
if (rl.closed)
|
|
17
|
+
return undefined;
|
|
18
|
+
return new Promise((resolve) => {
|
|
19
|
+
let answered = false;
|
|
20
|
+
const onClose = () => {
|
|
21
|
+
if (!answered)
|
|
22
|
+
resolve(undefined);
|
|
23
|
+
};
|
|
24
|
+
rl.once('close', onClose);
|
|
25
|
+
rl.question(label, (answer) => {
|
|
26
|
+
answered = true;
|
|
27
|
+
rl.removeListener('close', onClose);
|
|
28
|
+
resolve(answer);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
}
|
|
15
32
|
/**
|
|
16
33
|
* Decide whether a write should target the local or global config file,
|
|
17
34
|
* mirroring the contract used by `login`:
|
|
@@ -20,7 +37,7 @@ const config_1 = require("./config");
|
|
|
20
37
|
* - Else if TTY, prompt.
|
|
21
38
|
* - Else error and exit.
|
|
22
39
|
*/
|
|
23
|
-
async function decideWriteTarget(options, promptLabel = 'Save config locally (./.solidactions) or globally (~/.solidactions)? [global] ', refusalMessage = 'Refusing to write config non-interactively. Pass --local or --global.') {
|
|
40
|
+
async function decideWriteTarget(options, promptLabel = 'Save config locally (./.solidactions) or globally (~/.solidactions)? [global] ', refusalMessage = 'Refusing to write config non-interactively. Pass --local or --global.', dependencies = {}) {
|
|
24
41
|
if (options.local && options.global) {
|
|
25
42
|
console.error(chalk_1.default.red('Error: --local and --global are mutually exclusive.'));
|
|
26
43
|
process.exit(1);
|
|
@@ -29,11 +46,21 @@ async function decideWriteTarget(options, promptLabel = 'Save config locally (./
|
|
|
29
46
|
return 'local';
|
|
30
47
|
if (options.global)
|
|
31
48
|
return 'global';
|
|
32
|
-
|
|
33
|
-
|
|
49
|
+
const isTTY = dependencies.isTTY ?? process.stdin.isTTY === true;
|
|
50
|
+
if (isTTY) {
|
|
51
|
+
const rl = dependencies.question
|
|
52
|
+
? null
|
|
53
|
+
: readline_1.default.createInterface({ input: process.stdin, output: process.stdout });
|
|
34
54
|
try {
|
|
35
55
|
while (true) {
|
|
36
|
-
const
|
|
56
|
+
const label = chalk_1.default.blue(promptLabel);
|
|
57
|
+
const answer = dependencies.question
|
|
58
|
+
? await dependencies.question(label)
|
|
59
|
+
: await askReadlineQuestion(rl, label);
|
|
60
|
+
if (answer === undefined) {
|
|
61
|
+
console.error(chalk_1.default.red('Input closed before a config destination was selected. No changes were made.'));
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
37
64
|
const normalized = answer.trim().toLowerCase();
|
|
38
65
|
if (normalized === '' || normalized === 'global' || normalized === 'g')
|
|
39
66
|
return 'global';
|
|
@@ -43,7 +70,7 @@ async function decideWriteTarget(options, promptLabel = 'Save config locally (./
|
|
|
43
70
|
}
|
|
44
71
|
}
|
|
45
72
|
finally {
|
|
46
|
-
rl
|
|
73
|
+
rl?.close();
|
|
47
74
|
}
|
|
48
75
|
}
|
|
49
76
|
console.error(chalk_1.default.red(refusalMessage));
|
|
@@ -59,19 +86,29 @@ function pathForTarget(target) {
|
|
|
59
86
|
* automatically so they never wedge; an interactive TTY additionally asks a
|
|
60
87
|
* y/N confirm (default N).
|
|
61
88
|
*/
|
|
62
|
-
async function confirmOverwrite(existingPath, backupPath) {
|
|
89
|
+
async function confirmOverwrite(existingPath, backupPath, dependencies = {}) {
|
|
63
90
|
const notice = `Existing config at ${existingPath} will be overwritten (backup will be saved to ${backupPath}).`;
|
|
64
|
-
|
|
91
|
+
const isTTY = dependencies.isTTY ?? process.stdin.isTTY === true;
|
|
92
|
+
if (!isTTY) {
|
|
65
93
|
console.log(chalk_1.default.yellow(notice));
|
|
66
94
|
return true;
|
|
67
95
|
}
|
|
68
|
-
const rl =
|
|
96
|
+
const rl = dependencies.question
|
|
97
|
+
? null
|
|
98
|
+
: readline_1.default.createInterface({ input: process.stdin, output: process.stdout });
|
|
69
99
|
try {
|
|
70
|
-
const
|
|
100
|
+
const label = chalk_1.default.yellow(`${notice} Continue? [y/N] `);
|
|
101
|
+
const answer = dependencies.question
|
|
102
|
+
? await dependencies.question(label)
|
|
103
|
+
: await askReadlineQuestion(rl, label);
|
|
104
|
+
if (answer === undefined) {
|
|
105
|
+
console.log(chalk_1.default.yellow('Overwrite confirmation input closed; treating it as a decline.'));
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
71
108
|
return answer.trim().toLowerCase().startsWith('y');
|
|
72
109
|
}
|
|
73
110
|
finally {
|
|
74
|
-
rl
|
|
111
|
+
rl?.close();
|
|
75
112
|
}
|
|
76
113
|
}
|
|
77
114
|
/**
|
|
@@ -0,0 +1,241 @@
|
|
|
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.sanitizeDisplayText = sanitizeDisplayText;
|
|
7
|
+
exports.formatRevisionSummary = formatRevisionSummary;
|
|
8
|
+
exports.sanitizeRemoteUrl = sanitizeRemoteUrl;
|
|
9
|
+
exports.collectSourceMetadata = collectSourceMetadata;
|
|
10
|
+
exports.shouldCollectGitMetadata = shouldCollectGitMetadata;
|
|
11
|
+
exports.buildDeployForm = buildDeployForm;
|
|
12
|
+
exports.createDeployArchiveLocation = createDeployArchiveLocation;
|
|
13
|
+
exports.parseDeployAcceptance = parseDeployAcceptance;
|
|
14
|
+
const fs_1 = __importDefault(require("fs"));
|
|
15
|
+
const os_1 = __importDefault(require("os"));
|
|
16
|
+
const path_1 = __importDefault(require("path"));
|
|
17
|
+
const child_process_1 = require("child_process");
|
|
18
|
+
const form_data_1 = __importDefault(require("form-data"));
|
|
19
|
+
const DISPLAY_FORMATTING = /[\x00-\x1f\x7f\u061c\u200b-\u200f\u202a-\u202e\u2060\u2066-\u2069\ufeff]/g;
|
|
20
|
+
const SHA_PATTERN = /^[0-9a-f]{7,64}$/i;
|
|
21
|
+
const STRICT_ISO_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/;
|
|
22
|
+
function displayValue(value, maxLength) {
|
|
23
|
+
if (!value) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
const sanitized = value.replace(DISPLAY_FORMATTING, '').trim().slice(0, maxLength);
|
|
27
|
+
return sanitized === '' ? null : sanitized;
|
|
28
|
+
}
|
|
29
|
+
function sanitizeDisplayText(value, maxLength = 2048) {
|
|
30
|
+
return typeof value === 'string' ? displayValue(value, maxLength) : null;
|
|
31
|
+
}
|
|
32
|
+
function dirtyLabel(dirty) {
|
|
33
|
+
if (dirty === true) {
|
|
34
|
+
return 'DIRTY';
|
|
35
|
+
}
|
|
36
|
+
if (dirty === false) {
|
|
37
|
+
return 'clean';
|
|
38
|
+
}
|
|
39
|
+
return 'dirty state unknown';
|
|
40
|
+
}
|
|
41
|
+
function formatRevisionSummary(metadata) {
|
|
42
|
+
const sha = sanitizeDisplayText(metadata.short_sha, 16)
|
|
43
|
+
?? sanitizeDisplayText(metadata.commit_sha, 64);
|
|
44
|
+
if (!sha) {
|
|
45
|
+
return 'No source revision was reported.';
|
|
46
|
+
}
|
|
47
|
+
return `${sha} (${dirtyLabel(typeof metadata.dirty === 'boolean' ? metadata.dirty : null)})`;
|
|
48
|
+
}
|
|
49
|
+
function shaValue(value) {
|
|
50
|
+
const sanitized = displayValue(value, 64);
|
|
51
|
+
return sanitized && SHA_PATTERN.test(sanitized) ? sanitized : null;
|
|
52
|
+
}
|
|
53
|
+
function authorDateValue(value) {
|
|
54
|
+
const sanitized = displayValue(value, 40);
|
|
55
|
+
return sanitized && STRICT_ISO_PATTERN.test(sanitized) ? sanitized : null;
|
|
56
|
+
}
|
|
57
|
+
const SCP_STYLE_PATTERN = /^[^@\s/]+@([^\s/:]+):(.+)$/;
|
|
58
|
+
// Git remote helper syntax: `<helper>::<address>`, e.g. `hg::https://host/repo`.
|
|
59
|
+
// https://git-scm.com/docs/gitremote-helpers
|
|
60
|
+
const HELPER_PREFIX_PATTERN = /^([a-zA-Z0-9-]+::)(.*)$/;
|
|
61
|
+
function sanitizeRemoteUrl(value) {
|
|
62
|
+
const sanitized = displayValue(value, 2048);
|
|
63
|
+
if (!sanitized) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
const helperMatch = HELPER_PREFIX_PATTERN.exec(sanitized);
|
|
67
|
+
if (helperMatch) {
|
|
68
|
+
const [, prefix, remainder] = helperMatch;
|
|
69
|
+
const sanitizedRemainder = sanitizeRemoteUrl(remainder);
|
|
70
|
+
return sanitizedRemainder === null ? null : `${prefix}${sanitizedRemainder}`;
|
|
71
|
+
}
|
|
72
|
+
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(sanitized)) {
|
|
73
|
+
try {
|
|
74
|
+
const remote = new URL(sanitized);
|
|
75
|
+
remote.username = '';
|
|
76
|
+
remote.password = '';
|
|
77
|
+
remote.search = '';
|
|
78
|
+
remote.hash = '';
|
|
79
|
+
return remote.toString();
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (/^\/\//.test(sanitized)) {
|
|
86
|
+
// Protocol-relative: //[user[:pass]@]host[:port]/path[?query][#fragment]
|
|
87
|
+
return sanitized
|
|
88
|
+
.split('#')[0]
|
|
89
|
+
.split('?')[0]
|
|
90
|
+
.replace(/^\/\/[^/@]*@/, '//');
|
|
91
|
+
}
|
|
92
|
+
const scpMatch = SCP_STYLE_PATTERN.exec(sanitized);
|
|
93
|
+
if (scpMatch) {
|
|
94
|
+
const [, host, path] = scpMatch;
|
|
95
|
+
return `${host}:${path}`;
|
|
96
|
+
}
|
|
97
|
+
return sanitized;
|
|
98
|
+
}
|
|
99
|
+
function git(sourceDir, args) {
|
|
100
|
+
const result = (0, child_process_1.spawnSync)('git', ['-C', sourceDir, ...args], {
|
|
101
|
+
encoding: 'utf8',
|
|
102
|
+
timeout: 2_000,
|
|
103
|
+
maxBuffer: 1024 * 1024,
|
|
104
|
+
windowsHide: true,
|
|
105
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
106
|
+
});
|
|
107
|
+
if (result.status !== 0 || result.error) {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
return result.stdout.trim();
|
|
111
|
+
}
|
|
112
|
+
function localGitMetadata(sourceDir) {
|
|
113
|
+
if (git(sourceDir, ['rev-parse', '--is-inside-work-tree']) !== 'true') {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
const commitSha = shaValue(git(sourceDir, ['rev-parse', 'HEAD']) ?? undefined);
|
|
117
|
+
if (!commitSha) {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
const status = git(sourceDir, ['status', '--porcelain=v1', '--untracked-files=all', '--', '.']);
|
|
121
|
+
const shortSha = shaValue(git(sourceDir, ['rev-parse', '--short=12', 'HEAD']) ?? undefined);
|
|
122
|
+
return {
|
|
123
|
+
metadata_source: 'git',
|
|
124
|
+
commit_sha: commitSha,
|
|
125
|
+
short_sha: shortSha,
|
|
126
|
+
branch: displayValue(git(sourceDir, ['symbolic-ref', '--short', '-q', 'HEAD']) ?? undefined, 255),
|
|
127
|
+
tag: displayValue(git(sourceDir, ['describe', '--tags', '--exact-match', 'HEAD']) ?? undefined, 255),
|
|
128
|
+
commit_subject: displayValue(git(sourceDir, ['show', '-s', '--format=%s', 'HEAD']) ?? undefined, 500),
|
|
129
|
+
commit_author_date: authorDateValue(git(sourceDir, ['show', '-s', '--format=%aI', 'HEAD']) ?? undefined),
|
|
130
|
+
remote_url: sanitizeRemoteUrl(git(sourceDir, ['config', '--get', 'remote.origin.url']) ?? undefined),
|
|
131
|
+
dirty: status === null ? null : status !== '',
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function baseCiMetadata(source, sha) {
|
|
135
|
+
return {
|
|
136
|
+
metadata_source: source,
|
|
137
|
+
commit_sha: sha,
|
|
138
|
+
short_sha: sha.slice(0, 12),
|
|
139
|
+
branch: null,
|
|
140
|
+
tag: null,
|
|
141
|
+
commit_subject: null,
|
|
142
|
+
commit_author_date: null,
|
|
143
|
+
remote_url: null,
|
|
144
|
+
dirty: null,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function githubMetadata(environment) {
|
|
148
|
+
const sha = shaValue(environment.GITHUB_SHA);
|
|
149
|
+
if (!sha) {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
const metadata = baseCiMetadata('github_actions', sha);
|
|
153
|
+
metadata.branch = displayValue(environment.GITHUB_HEAD_REF
|
|
154
|
+
|| (environment.GITHUB_REF_TYPE === 'branch' ? environment.GITHUB_REF_NAME : undefined), 255);
|
|
155
|
+
metadata.tag = displayValue(environment.GITHUB_REF_TYPE === 'tag' ? environment.GITHUB_REF_NAME : undefined, 255);
|
|
156
|
+
const server = displayValue(environment.GITHUB_SERVER_URL, 1024);
|
|
157
|
+
const repository = displayValue(environment.GITHUB_REPOSITORY, 1024);
|
|
158
|
+
metadata.remote_url = sanitizeRemoteUrl(server && repository ? `${server.replace(/\/$/, '')}/${repository}` : undefined);
|
|
159
|
+
return metadata;
|
|
160
|
+
}
|
|
161
|
+
function gitlabMetadata(environment) {
|
|
162
|
+
const sha = shaValue(environment.CI_COMMIT_SHA);
|
|
163
|
+
if (!sha) {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
...baseCiMetadata('gitlab_ci', sha),
|
|
168
|
+
branch: displayValue(environment.CI_COMMIT_REF_NAME, 255),
|
|
169
|
+
tag: displayValue(environment.CI_COMMIT_TAG, 255),
|
|
170
|
+
commit_subject: displayValue(environment.CI_COMMIT_TITLE, 500),
|
|
171
|
+
commit_author_date: authorDateValue(environment.CI_COMMIT_TIMESTAMP),
|
|
172
|
+
remote_url: sanitizeRemoteUrl(environment.CI_REPOSITORY_URL),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
function circleMetadata(environment) {
|
|
176
|
+
const sha = shaValue(environment.CIRCLE_SHA1);
|
|
177
|
+
if (!sha) {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
return {
|
|
181
|
+
...baseCiMetadata('circleci', sha),
|
|
182
|
+
branch: displayValue(environment.CIRCLE_BRANCH, 255),
|
|
183
|
+
tag: displayValue(environment.CIRCLE_TAG, 255),
|
|
184
|
+
remote_url: sanitizeRemoteUrl(environment.CIRCLE_REPOSITORY_URL),
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
function bitbucketMetadata(environment) {
|
|
188
|
+
const sha = shaValue(environment.BITBUCKET_COMMIT);
|
|
189
|
+
if (!sha) {
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
return {
|
|
193
|
+
...baseCiMetadata('bitbucket_pipelines', sha),
|
|
194
|
+
branch: displayValue(environment.BITBUCKET_BRANCH, 255),
|
|
195
|
+
tag: displayValue(environment.BITBUCKET_TAG, 255),
|
|
196
|
+
remote_url: sanitizeRemoteUrl(environment.BITBUCKET_GIT_HTTP_ORIGIN || environment.BITBUCKET_GIT_SSH_ORIGIN),
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
function collectSourceMetadata(sourceDir, environment = process.env) {
|
|
200
|
+
return localGitMetadata(path_1.default.resolve(sourceDir))
|
|
201
|
+
?? githubMetadata(environment)
|
|
202
|
+
?? gitlabMetadata(environment)
|
|
203
|
+
?? circleMetadata(environment)
|
|
204
|
+
?? bitbucketMetadata(environment);
|
|
205
|
+
}
|
|
206
|
+
function shouldCollectGitMetadata(options, environment = process.env) {
|
|
207
|
+
return options.gitMetadata !== false && environment.SOLIDACTIONS_NO_GIT_METADATA !== '1';
|
|
208
|
+
}
|
|
209
|
+
function appendSourceMetadata(form, metadata) {
|
|
210
|
+
if (metadata) {
|
|
211
|
+
form.append('source_metadata', JSON.stringify(metadata));
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
function buildDeployForm(archivePath, metadata) {
|
|
215
|
+
const form = new form_data_1.default();
|
|
216
|
+
form.append('source', fs_1.default.createReadStream(archivePath));
|
|
217
|
+
appendSourceMetadata(form, metadata);
|
|
218
|
+
return form;
|
|
219
|
+
}
|
|
220
|
+
function createDeployArchiveLocation() {
|
|
221
|
+
const directory = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), 'solidactions-deploy-'));
|
|
222
|
+
return {
|
|
223
|
+
directory,
|
|
224
|
+
archivePath: path_1.default.join(directory, 'source.tar.gz'),
|
|
225
|
+
cleanup: () => fs_1.default.rmSync(directory, { recursive: true, force: true }),
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
function nullableString(value) {
|
|
229
|
+
return typeof value === 'string' && value !== '' ? value : null;
|
|
230
|
+
}
|
|
231
|
+
function parseDeployAcceptance(data) {
|
|
232
|
+
const body = data && typeof data === 'object' ? data : {};
|
|
233
|
+
const sourceMetadata = body.source_metadata && typeof body.source_metadata === 'object'
|
|
234
|
+
? body.source_metadata
|
|
235
|
+
: null;
|
|
236
|
+
return {
|
|
237
|
+
deploymentId: nullableString(body.deployment_id),
|
|
238
|
+
sourceMetadata,
|
|
239
|
+
sourceMetadataRejected: nullableString(body.source_metadata_rejected),
|
|
240
|
+
};
|
|
241
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTarArchive = createTarArchive;
|
|
4
|
+
// Kept in an untransformed CommonJS bridge because TypeScript rewrites
|
|
5
|
+
// import() to require() for this project, and require() cannot load archiver
|
|
6
|
+
// v8's ESM-only entry point on Node 18.
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
8
|
+
const importArchiver = require('./archiver-loader.cjs');
|
|
9
|
+
async function createTarArchive(options) {
|
|
10
|
+
const { TarArchive } = await importArchiver();
|
|
11
|
+
return new TarArchive(options);
|
|
12
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidactions/cli",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "SolidActions CLI - Deploy and manage workflow automation",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"engines": {
|
|
25
|
-
"node": ">=
|
|
25
|
+
"node": ">=20.0.0"
|
|
26
26
|
},
|
|
27
27
|
"keywords": [
|
|
28
28
|
"solidactions",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"deploy"
|
|
33
33
|
],
|
|
34
34
|
"scripts": {
|
|
35
|
-
"build": "tsc && cp src/commands/dev-shim.mjs dist/commands/dev-shim.mjs",
|
|
35
|
+
"build": "tsc && cp src/commands/dev-shim.mjs dist/commands/dev-shim.mjs && cp src/utils/archiver-loader.cjs dist/utils/archiver-loader.cjs",
|
|
36
36
|
"check:release": "npm run build && npm run test && npm run smoke:init",
|
|
37
37
|
"prepublishOnly": "npm run build",
|
|
38
38
|
"smoke:init": "node scripts/smoke-init.mjs",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"test:watch": "vitest"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"archiver": "^
|
|
43
|
+
"archiver": "^8.0.0",
|
|
44
44
|
"axios": "^1.18.1",
|
|
45
45
|
"chalk": "^4.1.2",
|
|
46
46
|
"commander": "^11.0.0",
|
|
@@ -50,11 +50,11 @@
|
|
|
50
50
|
"ignore": "^7.0.5",
|
|
51
51
|
"js-yaml": "^4.3.0",
|
|
52
52
|
"prompts": "^2.4.2",
|
|
53
|
-
"tar": "^7.5.
|
|
53
|
+
"tar": "^7.5.22"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@solidactions/sdk": "^0.7.3",
|
|
57
|
-
"@types/archiver": "^
|
|
57
|
+
"@types/archiver": "^8.0.0",
|
|
58
58
|
"@types/fs-extra": "^11.0.0",
|
|
59
59
|
"@types/js-yaml": "^4.0.9",
|
|
60
60
|
"@types/node": "^20.0.0",
|