@solidactions/cli 3.9.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/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
|
}
|
|
@@ -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() : '-';
|
|
@@ -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)
|