@solidactions/cli 3.8.0 → 3.10.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/command-manifest.json +1 -1
- package/dist/commands/deploy.js +3 -1
- package/dist/commands/device-login.js +39 -6
- package/dist/commands/env-pull.js +11 -0
- package/dist/commands/env-set.js +6 -2
- package/dist/commands/run-list.js +47 -4
- package/dist/utils/api.js +15 -0
- package/dist/utils/source-provenance.js +53 -4
- package/package.json +1 -1
package/dist/commands/deploy.js
CHANGED
|
@@ -506,7 +506,9 @@ async function deploy(projectName, sourcePath, options = {}) {
|
|
|
506
506
|
}
|
|
507
507
|
// Provenance is optional, best effort, and collected before archiving so
|
|
508
508
|
// the deploy artifact itself can never make the source look dirty.
|
|
509
|
-
const sourceMetadata = safeCollectSourceMetadata(sourceDir, options)
|
|
509
|
+
const sourceMetadata = safeCollectSourceMetadata(sourceDir, options, (directory) => (0, source_provenance_1.collectSourceMetadata)(directory, process.env, (hint) => {
|
|
510
|
+
console.log(chalk_1.default.yellow(`Git provenance hint: ${hint}`));
|
|
511
|
+
}));
|
|
510
512
|
if (sourceMetadata) {
|
|
511
513
|
console.log(chalk_1.default.gray(`Revision to upload (client-reported): ${(0, source_provenance_1.formatRevisionSummary)(sourceMetadata)}`));
|
|
512
514
|
}
|
|
@@ -16,13 +16,46 @@ const login_1 = require("./login");
|
|
|
16
16
|
const CLI_OAUTH_CLIENT_ID = '9f1b6e2a-9c1e-4b6e-8f0a-6c9f2b1e7d4c';
|
|
17
17
|
// CLI capability scopes requested at device-code issuance — the server
|
|
18
18
|
// rejects any scope not pre-registered via Passport::tokensCan().
|
|
19
|
-
|
|
19
|
+
//
|
|
20
|
+
// `env:reveal` is REQUESTED here but not necessarily GRANTED: the consent
|
|
21
|
+
// screen renders it as a default-off checkbox, and the server strips it from
|
|
22
|
+
// the issued token unless the user ticks it. Requesting it is what makes the
|
|
23
|
+
// opt-in reachable at all — a scope absent from this string can never be
|
|
24
|
+
// added at consent time, because the device code's scope set is frozen when
|
|
25
|
+
// the code is created (#1252).
|
|
26
|
+
const CLI_SCOPES_WITH_REVEAL = 'env env:reveal deploy runs docs databases';
|
|
27
|
+
// Pre-#1252 scope list, kept as the fallback for servers that haven't
|
|
28
|
+
// registered `env:reveal` yet (older production, a lagging staging, a
|
|
29
|
+
// self-hosted install). Passport rejects the entire device-code request with
|
|
30
|
+
// `invalid_scope` if ANY requested scope is unregistered, so requesting
|
|
31
|
+
// `env:reveal` unconditionally would hard-break device login everywhere
|
|
32
|
+
// until every server picks up the companion change.
|
|
33
|
+
const CLI_SCOPES_LEGACY = 'env deploy runs docs databases';
|
|
34
|
+
/**
|
|
35
|
+
* Request a device code with the full (env:reveal-including) scope list. If
|
|
36
|
+
* the server doesn't yet recognize `env:reveal` it rejects the whole request
|
|
37
|
+
* with 400 `invalid_scope` — retry once with the legacy scope list so login
|
|
38
|
+
* still succeeds. Any other rejection (e.g. a bad client_id) still fails
|
|
39
|
+
* loudly; only this specific, detectable condition is swallowed.
|
|
40
|
+
*/
|
|
20
41
|
async function requestDeviceCode(host) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
42
|
+
try {
|
|
43
|
+
const response = await axios_1.default.post(`${host}/oauth/device/code`, {
|
|
44
|
+
client_id: CLI_OAUTH_CLIENT_ID,
|
|
45
|
+
scope: CLI_SCOPES_WITH_REVEAL,
|
|
46
|
+
});
|
|
47
|
+
return response.data;
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
if (e?.response?.status === 400 && e.response.data?.error === 'invalid_scope') {
|
|
51
|
+
const response = await axios_1.default.post(`${host}/oauth/device/code`, {
|
|
52
|
+
client_id: CLI_OAUTH_CLIENT_ID,
|
|
53
|
+
scope: CLI_SCOPES_LEGACY,
|
|
54
|
+
});
|
|
55
|
+
return response.data;
|
|
56
|
+
}
|
|
57
|
+
throw e;
|
|
58
|
+
}
|
|
26
59
|
}
|
|
27
60
|
function sleep(ms) {
|
|
28
61
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -213,6 +213,17 @@ async function envPull(projectName, options = {}) {
|
|
|
213
213
|
console.log(chalk_1.default.gray(`Try deploying with: solidactions project deploy ${projectName} -e ${environment} --create`));
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
|
+
else if (error.response.status === 403) {
|
|
217
|
+
// Only the reveal step is named as the culprit — a 403 here can
|
|
218
|
+
// also be a workspace-scope or project-policy denial, and
|
|
219
|
+
// blaming env:reveal for those sends the user to the wrong fix.
|
|
220
|
+
const detail = typeof error.response.data?.message === 'string' ? error.response.data.message : undefined;
|
|
221
|
+
const needsReveal = error.response.data?.required_ability === 'env:reveal';
|
|
222
|
+
const lead = needsReveal
|
|
223
|
+
? "Reading variable values requires the 'env:reveal' ability."
|
|
224
|
+
: 'Permission denied.';
|
|
225
|
+
console.error(chalk_1.default.red(detail ? `${lead}\n\n${detail}` : lead));
|
|
226
|
+
}
|
|
216
227
|
else {
|
|
217
228
|
console.error(chalk_1.default.red(`Failed: ${error.response.status}`), error.response.data);
|
|
218
229
|
}
|
package/dist/commands/env-set.js
CHANGED
|
@@ -81,9 +81,13 @@ async function envSet(keyOrProject, valueOrKey, valueIfProject, options = {}) {
|
|
|
81
81
|
`in project "${projectName}" (${environment}).`));
|
|
82
82
|
return;
|
|
83
83
|
}
|
|
84
|
-
// Check if variable already has a value
|
|
84
|
+
// Check if variable already has a value. Deliberately do NOT pass
|
|
85
|
+
// reveal=true: this only reads `existing.has_value` (returned
|
|
86
|
+
// unconditionally by the mappings projection), never the
|
|
87
|
+
// plaintext value, so requesting reveal would force every write
|
|
88
|
+
// to also carry the env:reveal ability it doesn't need (#1252).
|
|
85
89
|
if (!options.yes) {
|
|
86
|
-
const mappingsResponse = await axios_1.default.get(`${config.host}/api/v1/projects/${projectSlug}/variable-mappings
|
|
90
|
+
const mappingsResponse = await axios_1.default.get(`${config.host}/api/v1/projects/${projectSlug}/variable-mappings`, { headers: (0, api_1.getApiHeaders)(config) });
|
|
87
91
|
const mappings = mappingsResponse.data || [];
|
|
88
92
|
const existing = mappings.find((m) => m.env_name === key);
|
|
89
93
|
if (existing && existing.has_value) {
|
|
@@ -7,10 +7,15 @@ exports.buildRunListParams = buildRunListParams;
|
|
|
7
7
|
exports.runs = runs;
|
|
8
8
|
exports.summaryStatusLabel = summaryStatusLabel;
|
|
9
9
|
exports.detailedOutcomeTag = detailedOutcomeTag;
|
|
10
|
+
exports.formatRevisionCell = formatRevisionCell;
|
|
11
|
+
exports.formatDetailedRevision = formatDetailedRevision;
|
|
12
|
+
exports.displaySummaryTable = displaySummaryTable;
|
|
13
|
+
exports.displayDetailedList = displayDetailedList;
|
|
10
14
|
const axios_1 = __importDefault(require("axios"));
|
|
11
15
|
const chalk_1 = __importDefault(require("chalk"));
|
|
12
16
|
const api_1 = require("../utils/api");
|
|
13
17
|
const table_1 = require("../utils/table");
|
|
18
|
+
const source_provenance_1 = require("../utils/source-provenance");
|
|
14
19
|
/**
|
|
15
20
|
* Build the params object for GET /api/v1/runs.
|
|
16
21
|
* Extracted as a pure function so it can be unit-tested without mocking axios.
|
|
@@ -121,11 +126,43 @@ function detailedOutcomeTag(run) {
|
|
|
121
126
|
return ' [DEGRADED]';
|
|
122
127
|
return '';
|
|
123
128
|
}
|
|
129
|
+
function revisionSha(revision) {
|
|
130
|
+
if (!revision)
|
|
131
|
+
return null;
|
|
132
|
+
return (0, source_provenance_1.sanitizeDisplayText)(revision.short_sha, 16)
|
|
133
|
+
?? (0, source_provenance_1.sanitizeDisplayText)(revision.commit_sha, 64);
|
|
134
|
+
}
|
|
135
|
+
function formatRevisionCell(revision) {
|
|
136
|
+
const sha = revisionSha(revision);
|
|
137
|
+
if (!sha)
|
|
138
|
+
return '-';
|
|
139
|
+
const dirty = revision?.dirty === true ? '*' : revision?.dirty === false ? '' : '?';
|
|
140
|
+
const behind = typeof revision?.commits_behind === 'number'
|
|
141
|
+
&& Number.isSafeInteger(revision.commits_behind)
|
|
142
|
+
&& revision.commits_behind > 0
|
|
143
|
+
? ` ↓${revision.commits_behind}`
|
|
144
|
+
: '';
|
|
145
|
+
return (0, table_1.sanitizeCell)(`${sha}${dirty}${behind}`);
|
|
146
|
+
}
|
|
147
|
+
function formatDetailedRevision(revision) {
|
|
148
|
+
const sha = revisionSha(revision);
|
|
149
|
+
if (!sha)
|
|
150
|
+
return 'unknown';
|
|
151
|
+
const states = [revision?.dirty === true
|
|
152
|
+
? 'DIRTY'
|
|
153
|
+
: revision?.dirty === false ? 'clean' : 'dirty state unknown'];
|
|
154
|
+
const branch = (0, source_provenance_1.sanitizeDisplayText)(revision?.default_branch, 255);
|
|
155
|
+
if (branch && typeof revision?.commits_behind === 'number'
|
|
156
|
+
&& Number.isSafeInteger(revision.commits_behind) && revision.commits_behind > 0) {
|
|
157
|
+
states.push(`${revision.commits_behind} behind origin/${branch} at deploy`);
|
|
158
|
+
}
|
|
159
|
+
return (0, table_1.sanitizeCell)(`${sha} (${states.join(', ')})`);
|
|
160
|
+
}
|
|
124
161
|
function displaySummaryTable(runsList, projectName) {
|
|
125
162
|
const header = projectName ? `Recent runs for "${projectName}":` : 'Recent runs:';
|
|
126
163
|
console.log(chalk_1.default.blue(header));
|
|
127
164
|
console.log('');
|
|
128
|
-
const headers = ['ID', 'WORKFLOW', 'STATUS', 'TRIGGERED', 'TRIGGERED BY'];
|
|
165
|
+
const headers = ['ID', 'WORKFLOW', 'STATUS', 'REVISION', 'TRIGGERED', 'TRIGGERED BY'];
|
|
129
166
|
const rows = runsList.map((run) => {
|
|
130
167
|
const { label: status } = summaryStatusLabel(run);
|
|
131
168
|
const triggeredAt = run.triggered_at ? new Date(run.triggered_at).toLocaleString() : '-';
|
|
@@ -133,25 +170,28 @@ function displaySummaryTable(runsList, projectName) {
|
|
|
133
170
|
String(run.id || '?'),
|
|
134
171
|
(0, table_1.sanitizeCell)((0, table_1.truncateCell)(run.workflow_name || '?', 24)),
|
|
135
172
|
status,
|
|
173
|
+
formatRevisionCell(run.deployed_revision ?? null),
|
|
136
174
|
triggeredAt,
|
|
137
175
|
(0, table_1.sanitizeCell)(run.triggered_by || '-'),
|
|
138
176
|
];
|
|
139
177
|
});
|
|
140
|
-
const widths = (0, table_1.computeColumnWidths)(headers, rows, { minWidths: [8, 25, 12, 22, 0] });
|
|
178
|
+
const widths = (0, table_1.computeColumnWidths)(headers, rows, { minWidths: [8, 25, 12, 14, 22, 0] });
|
|
141
179
|
console.log(chalk_1.default.gray(headers.map((h, i) => h.padEnd(widths[i])).join('')));
|
|
142
180
|
console.log(chalk_1.default.gray('-'.repeat(widths.reduce((a, b) => a + b, 0))));
|
|
143
181
|
for (let i = 0; i < runsList.length; i++) {
|
|
144
182
|
const run = runsList[i];
|
|
145
|
-
const [id, workflow, status, triggeredAt, triggeredBy] = rows[i];
|
|
183
|
+
const [id, workflow, status, revision, triggeredAt, triggeredBy] = rows[i];
|
|
146
184
|
const { attention } = summaryStatusLabel(run);
|
|
147
185
|
const statusColor = attention ? chalk_1.default.yellow : getStatusColor(status);
|
|
148
186
|
console.log(chalk_1.default.gray(id.padEnd(widths[0])) +
|
|
149
187
|
workflow.padEnd(widths[1]) +
|
|
150
188
|
statusColor(status.padEnd(widths[2])) +
|
|
151
|
-
chalk_1.default.gray(
|
|
189
|
+
chalk_1.default.gray(revision.padEnd(widths[3])) +
|
|
190
|
+
chalk_1.default.gray(triggeredAt.padEnd(widths[4])) +
|
|
152
191
|
chalk_1.default.gray(triggeredBy));
|
|
153
192
|
}
|
|
154
193
|
console.log('');
|
|
194
|
+
console.log(chalk_1.default.gray('REVISION shows latest session: * dirty, ? dirty state unknown, ↓N behind default branch at deploy.'));
|
|
155
195
|
console.log(chalk_1.default.gray(`Showing ${runsList.length} run(s)`));
|
|
156
196
|
}
|
|
157
197
|
function displayDetailedList(runsList, projectName) {
|
|
@@ -167,6 +207,9 @@ function displayDetailedList(runsList, projectName) {
|
|
|
167
207
|
console.log(chalk_1.default.bold(` Run #${run.id}`) + chalk_1.default.gray(` — ${run.workflow_name || '?'} (${run.project_name || '?'})`) + silentTag);
|
|
168
208
|
console.log(` Status: ${statusColor(status)}${chalk_1.default.gray(exitStr)}`);
|
|
169
209
|
console.log(` Trigger: ${chalk_1.default.gray(run.triggered_by || '-')}`);
|
|
210
|
+
if (Object.prototype.hasOwnProperty.call(run, 'deployed_revision')) {
|
|
211
|
+
console.log(` Revision (latest session): ${chalk_1.default.gray(formatDetailedRevision(run.deployed_revision))}`);
|
|
212
|
+
}
|
|
170
213
|
// Timeline
|
|
171
214
|
if (run.timeline) {
|
|
172
215
|
const formatTs = (iso) => iso ? new Date(iso).toLocaleString() : '-';
|
package/dist/utils/api.js
CHANGED
|
@@ -156,6 +156,21 @@ function augmentTokenMissingAbilityMessage(error) {
|
|
|
156
156
|
response.data.message = `${message}\n\n${hint}`;
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
|
+
const isEnvRevealAbility = requiredAbility === 'env:reveal';
|
|
160
|
+
if (response?.status === 403
|
|
161
|
+
&& response.data?.code === 'token_missing_ability'
|
|
162
|
+
&& isEnvRevealAbility) {
|
|
163
|
+
const hint = "The 'env:reveal' ability grants plaintext disclosure of secret values. "
|
|
164
|
+
+ 'Re-run `solidactions login --device` and tick "Reveal secret values" on the consent screen, '
|
|
165
|
+
+ 'or create an API key with the \'env:reveal\' ability checked at Settings → API keys '
|
|
166
|
+
+ 'and `solidactions login` with that key.';
|
|
167
|
+
const message = typeof response.data.message === 'string' && response.data.message.length > 0
|
|
168
|
+
? response.data.message
|
|
169
|
+
: "This session does not have the 'env:reveal' ability.";
|
|
170
|
+
if (!message.includes('Settings → API keys')) {
|
|
171
|
+
response.data.message = `${message}\n\n${hint}`;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
159
174
|
return error;
|
|
160
175
|
}
|
|
161
176
|
axios_1.default.interceptors.response.use((response) => response, (error) => Promise.reject(augmentTokenMissingAbilityMessage(augmentWorkspaceForbiddenMessage(augmentNotFoundMessage(augmentSandboxEgressMessage(error))))));
|
|
@@ -109,7 +109,51 @@ function git(sourceDir, args) {
|
|
|
109
109
|
}
|
|
110
110
|
return result.stdout.trim();
|
|
111
111
|
}
|
|
112
|
-
|
|
112
|
+
const NULL_DEFAULT_BRANCH_EVIDENCE = {
|
|
113
|
+
default_branch: null,
|
|
114
|
+
default_branch_sha: null,
|
|
115
|
+
commits_behind: null,
|
|
116
|
+
};
|
|
117
|
+
function defaultBranchEvidence(sourceDir, hasOrigin, hint) {
|
|
118
|
+
if (!hasOrigin || git(sourceDir, ['rev-parse', '--is-shallow-repository']) !== 'false') {
|
|
119
|
+
return NULL_DEFAULT_BRANCH_EVIDENCE;
|
|
120
|
+
}
|
|
121
|
+
let trackingRef = git(sourceDir, ['symbolic-ref', '--quiet', 'refs/remotes/origin/HEAD']);
|
|
122
|
+
if (trackingRef === null) {
|
|
123
|
+
// Only a genuinely absent origin/HEAD permits the conventional-name fallback.
|
|
124
|
+
// An unexpected direct ref is existing-but-invalid evidence, just like a stale
|
|
125
|
+
// symbolic target, and must not be silently replaced with a guess.
|
|
126
|
+
if (git(sourceDir, ['rev-parse', '--verify', 'refs/remotes/origin/HEAD']) !== null) {
|
|
127
|
+
return NULL_DEFAULT_BRANCH_EVIDENCE;
|
|
128
|
+
}
|
|
129
|
+
const candidates = ['main', 'master'].filter((branch) => git(sourceDir, ['rev-parse', '--verify', `refs/remotes/origin/${branch}^{commit}`]) !== null);
|
|
130
|
+
if (candidates.length !== 1) {
|
|
131
|
+
hint?.('Unable to determine origin default branch; run `git remote set-head origin -a`.');
|
|
132
|
+
return NULL_DEFAULT_BRANCH_EVIDENCE;
|
|
133
|
+
}
|
|
134
|
+
trackingRef = `refs/remotes/origin/${candidates[0]}`;
|
|
135
|
+
}
|
|
136
|
+
const prefix = 'refs/remotes/origin/';
|
|
137
|
+
if (!trackingRef.startsWith(prefix)) {
|
|
138
|
+
return NULL_DEFAULT_BRANCH_EVIDENCE;
|
|
139
|
+
}
|
|
140
|
+
const branch = displayValue(trackingRef.slice(prefix.length), 255);
|
|
141
|
+
const sha = shaValue(git(sourceDir, ['rev-parse', '--verify', `${trackingRef}^{commit}`]) ?? undefined);
|
|
142
|
+
if (!branch || !sha) {
|
|
143
|
+
return NULL_DEFAULT_BRANCH_EVIDENCE;
|
|
144
|
+
}
|
|
145
|
+
const counts = git(sourceDir, ['rev-list', '--left-right', '--count', `HEAD...${trackingRef}`]);
|
|
146
|
+
const match = counts?.match(/^(\d+)\s+(\d+)$/);
|
|
147
|
+
if (!match) {
|
|
148
|
+
return NULL_DEFAULT_BRANCH_EVIDENCE;
|
|
149
|
+
}
|
|
150
|
+
const behind = Number(match[2]);
|
|
151
|
+
if (!Number.isSafeInteger(behind) || behind < 0 || behind > 2_147_483_647) {
|
|
152
|
+
return NULL_DEFAULT_BRANCH_EVIDENCE;
|
|
153
|
+
}
|
|
154
|
+
return { default_branch: branch, default_branch_sha: sha, commits_behind: behind };
|
|
155
|
+
}
|
|
156
|
+
function localGitMetadata(sourceDir, hint) {
|
|
113
157
|
if (git(sourceDir, ['rev-parse', '--is-inside-work-tree']) !== 'true') {
|
|
114
158
|
return null;
|
|
115
159
|
}
|
|
@@ -119,6 +163,7 @@ function localGitMetadata(sourceDir) {
|
|
|
119
163
|
}
|
|
120
164
|
const status = git(sourceDir, ['status', '--porcelain=v1', '--untracked-files=all', '--', '.']);
|
|
121
165
|
const shortSha = shaValue(git(sourceDir, ['rev-parse', '--short=12', 'HEAD']) ?? undefined);
|
|
166
|
+
const remoteUrl = sanitizeRemoteUrl(git(sourceDir, ['config', '--get', 'remote.origin.url']) ?? undefined);
|
|
122
167
|
return {
|
|
123
168
|
metadata_source: 'git',
|
|
124
169
|
commit_sha: commitSha,
|
|
@@ -127,8 +172,9 @@ function localGitMetadata(sourceDir) {
|
|
|
127
172
|
tag: displayValue(git(sourceDir, ['describe', '--tags', '--exact-match', 'HEAD']) ?? undefined, 255),
|
|
128
173
|
commit_subject: displayValue(git(sourceDir, ['show', '-s', '--format=%s', 'HEAD']) ?? undefined, 500),
|
|
129
174
|
commit_author_date: authorDateValue(git(sourceDir, ['show', '-s', '--format=%aI', 'HEAD']) ?? undefined),
|
|
130
|
-
remote_url:
|
|
175
|
+
remote_url: remoteUrl,
|
|
131
176
|
dirty: status === null ? null : status !== '',
|
|
177
|
+
...defaultBranchEvidence(sourceDir, remoteUrl !== null, hint),
|
|
132
178
|
};
|
|
133
179
|
}
|
|
134
180
|
function baseCiMetadata(source, sha) {
|
|
@@ -142,6 +188,9 @@ function baseCiMetadata(source, sha) {
|
|
|
142
188
|
commit_author_date: null,
|
|
143
189
|
remote_url: null,
|
|
144
190
|
dirty: null,
|
|
191
|
+
default_branch: null,
|
|
192
|
+
default_branch_sha: null,
|
|
193
|
+
commits_behind: null,
|
|
145
194
|
};
|
|
146
195
|
}
|
|
147
196
|
function githubMetadata(environment) {
|
|
@@ -196,8 +245,8 @@ function bitbucketMetadata(environment) {
|
|
|
196
245
|
remote_url: sanitizeRemoteUrl(environment.BITBUCKET_GIT_HTTP_ORIGIN || environment.BITBUCKET_GIT_SSH_ORIGIN),
|
|
197
246
|
};
|
|
198
247
|
}
|
|
199
|
-
function collectSourceMetadata(sourceDir, environment = process.env) {
|
|
200
|
-
return localGitMetadata(path_1.default.resolve(sourceDir))
|
|
248
|
+
function collectSourceMetadata(sourceDir, environment = process.env, hint) {
|
|
249
|
+
return localGitMetadata(path_1.default.resolve(sourceDir), hint)
|
|
201
250
|
?? githubMetadata(environment)
|
|
202
251
|
?? gitlabMetadata(environment)
|
|
203
252
|
?? circleMetadata(environment)
|