@solidactions/cli 3.10.1 → 3.11.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 +2 -2
- package/dist/command-manifest.json +13 -1
- package/dist/commands/env-pull.js +8 -3
- package/dist/commands/project-view.js +51 -6
- package/dist/commands/run-list.js +5 -23
- package/dist/commands/run-view.js +7 -0
- package/dist/index.js +1 -0
- package/dist/utils/secure-write.js +104 -0
- package/dist/utils/source-provenance.js +23 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -237,7 +237,7 @@ Use `solidactions <command> --help` for full flag details on any command.
|
|
|
237
237
|
| `project deploy <name> [path]` | `-e`, `--create`, `--config-only`, `--paused`, `--no-git-metadata` | Deploy or sync config only; optionally land YAML schedules paused |
|
|
238
238
|
| `project enable <project>` | `-e` (default `dev`) | Allow new starts through this project gate |
|
|
239
239
|
| `project disable <project>` | `-e` (default `dev`) | Block new root starts without cancelling existing roots |
|
|
240
|
-
| `project view <project>` | `-e` (default `dev`) | View status, `Enabled: on|off`, and client-reported deployed revision |
|
|
240
|
+
| `project view <project>` | `-e` (default `dev`), `--json` | View status, `Enabled: on|off`, and client-reported deployed revision, incl. an `N behind origin/<branch> at deploy` drift clause when the deployment is behind the default branch |
|
|
241
241
|
| `project pull <name> [path]` | `-y` | Pull source (warns before overwriting) |
|
|
242
242
|
| `project logs <name>` | | View build logs |
|
|
243
243
|
| `project list` | `--json` | List project families; environments render as `environment:on/off` |
|
|
@@ -277,7 +277,7 @@ its project or schedule.
|
|
|
277
277
|
|---------|-----------|-------------|
|
|
278
278
|
| `run start <project> <workflow>` | `-e`, `-i`, `--wait` | Trigger a workflow run |
|
|
279
279
|
| `run list [project]` | `--json`, `--detailed`, `--status`, `--since`, `--workflow`, `--limit`, `--offset` | List and filter runs |
|
|
280
|
-
| `run view <run-id>` | `--json`, `--timeline`, `--steps`, `--logs` | Inspect a run |
|
|
280
|
+
| `run view <run-id>` | `--json`, `--timeline`, `--steps`, `--logs` | Inspect a run, incl. the deployed revision (`Revision (latest session): ...`, or `deployed_revision` under `--json`) |
|
|
281
281
|
|
|
282
282
|
### env
|
|
283
283
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schema_version": 1,
|
|
3
3
|
"cli_name": "solidactions",
|
|
4
|
-
"cli_version": "3.
|
|
4
|
+
"cli_version": "3.11.0",
|
|
5
5
|
"global_options": [
|
|
6
6
|
{
|
|
7
7
|
"flags": "-V, --version",
|
|
@@ -985,6 +985,18 @@
|
|
|
985
985
|
"hidden": false,
|
|
986
986
|
"default": "dev"
|
|
987
987
|
},
|
|
988
|
+
{
|
|
989
|
+
"flags": "--json",
|
|
990
|
+
"long": "--json",
|
|
991
|
+
"short": null,
|
|
992
|
+
"description": "Output as JSON",
|
|
993
|
+
"required": false,
|
|
994
|
+
"value_required": false,
|
|
995
|
+
"value_optional": false,
|
|
996
|
+
"variadic": false,
|
|
997
|
+
"negated": false,
|
|
998
|
+
"hidden": false
|
|
999
|
+
},
|
|
988
1000
|
{
|
|
989
1001
|
"flags": "-h, --help",
|
|
990
1002
|
"long": "--help",
|
|
@@ -10,6 +10,7 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
10
10
|
const chalk_1 = __importDefault(require("chalk"));
|
|
11
11
|
const readline_1 = __importDefault(require("readline"));
|
|
12
12
|
const api_1 = require("../utils/api");
|
|
13
|
+
const secure_write_1 = require("../utils/secure-write");
|
|
13
14
|
/**
|
|
14
15
|
* Prompt the user for confirmation (unless --yes flag is set).
|
|
15
16
|
*/
|
|
@@ -96,7 +97,7 @@ async function envPull(projectName, options = {}) {
|
|
|
96
97
|
// No .env file — create with just OAuth vars
|
|
97
98
|
console.log(chalk_1.default.yellow('No .env file found — creating with OAuth vars only. Run a full env:pull for all variables.'));
|
|
98
99
|
const content = oauthLines.join('\n') + '\n';
|
|
99
|
-
|
|
100
|
+
(0, secure_write_1.writeSecretFileSync)(outputPath, content);
|
|
100
101
|
}
|
|
101
102
|
else {
|
|
102
103
|
// Merge into existing .env file
|
|
@@ -133,7 +134,7 @@ async function envPull(projectName, options = {}) {
|
|
|
133
134
|
preservedLines.push(`# OAuth tokens (updated ${new Date().toISOString()})`);
|
|
134
135
|
preservedLines.push(...oauthLines);
|
|
135
136
|
preservedLines.push('');
|
|
136
|
-
|
|
137
|
+
(0, secure_write_1.writeSecretFileSync)(outputPath, preservedLines.join('\n'));
|
|
137
138
|
}
|
|
138
139
|
console.log(chalk_1.default.green(`\n✓ Updated ${oauthVars.length} OAuth token(s) in ${outputFile}`));
|
|
139
140
|
// Print any OAuth warnings
|
|
@@ -190,7 +191,7 @@ async function envPull(projectName, options = {}) {
|
|
|
190
191
|
}
|
|
191
192
|
lines.push('');
|
|
192
193
|
// Write to file
|
|
193
|
-
|
|
194
|
+
(0, secure_write_1.writeSecretFileSync)(outputPath, lines.join('\n'));
|
|
194
195
|
console.log(chalk_1.default.green(`\n✓ Wrote ${count} variables to ${outputFile}`));
|
|
195
196
|
if (secretCount > 0) {
|
|
196
197
|
console.log(chalk_1.default.yellow(` (includes ${secretCount} secret value${secretCount > 1 ? 's' : ''})`));
|
|
@@ -228,6 +229,10 @@ async function envPull(projectName, options = {}) {
|
|
|
228
229
|
console.error(chalk_1.default.red(`Failed: ${error.response.status}`), error.response.data);
|
|
229
230
|
}
|
|
230
231
|
}
|
|
232
|
+
else if (!axios_1.default.isAxiosError(error) && error.code) {
|
|
233
|
+
// A filesystem failure writing the .env — not a connection problem.
|
|
234
|
+
console.error(chalk_1.default.red(`Failed to write ${outputFile}: ${error.message}`));
|
|
235
|
+
}
|
|
231
236
|
else {
|
|
232
237
|
console.error(chalk_1.default.red('Connection failed:'), error.message);
|
|
233
238
|
}
|
|
@@ -3,6 +3,7 @@ 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.projectViewJsonProjection = projectViewJsonProjection;
|
|
6
7
|
exports.projectSlugForView = projectSlugForView;
|
|
7
8
|
exports.formatDeploymentRevision = formatDeploymentRevision;
|
|
8
9
|
exports.formatProjectView = formatProjectView;
|
|
@@ -13,6 +14,47 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
13
14
|
const api_1 = require("../utils/api");
|
|
14
15
|
const slug_1 = require("../utils/slug");
|
|
15
16
|
const source_provenance_1 = require("../utils/source-provenance");
|
|
17
|
+
/**
|
|
18
|
+
* Projects exactly the fields `DeploymentDetail` declares.
|
|
19
|
+
*
|
|
20
|
+
* The server's DeploymentResource serializes more than this — `failure_reason`
|
|
21
|
+
* today, more tomorrow — and that field is always null for a *successful*
|
|
22
|
+
* deployment, which is the only kind this endpoint returns here. Listing the
|
|
23
|
+
* fields explicitly keeps `--json` a documented contract instead of a mirror of
|
|
24
|
+
* whatever the API happens to add next.
|
|
25
|
+
*/
|
|
26
|
+
function deploymentJsonProjection(deployment) {
|
|
27
|
+
return {
|
|
28
|
+
id: deployment.id,
|
|
29
|
+
status: deployment.status,
|
|
30
|
+
source_hash: deployment.source_hash,
|
|
31
|
+
metadata_source: deployment.metadata_source ?? null,
|
|
32
|
+
commit_sha: deployment.commit_sha ?? null,
|
|
33
|
+
short_sha: deployment.short_sha ?? null,
|
|
34
|
+
branch: deployment.branch ?? null,
|
|
35
|
+
tag: deployment.tag ?? null,
|
|
36
|
+
commit_subject: deployment.commit_subject ?? null,
|
|
37
|
+
commit_author_date: deployment.commit_author_date ?? null,
|
|
38
|
+
remote_url: deployment.remote_url ?? null,
|
|
39
|
+
dirty: deployment.dirty ?? null,
|
|
40
|
+
default_branch: deployment.default_branch ?? null,
|
|
41
|
+
default_branch_sha: deployment.default_branch_sha ?? null,
|
|
42
|
+
commits_behind: deployment.commits_behind ?? null,
|
|
43
|
+
completed_at: deployment.completed_at ?? null,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function projectViewJsonProjection(project) {
|
|
47
|
+
const deployment = project.latest_successful_deployment ?? null;
|
|
48
|
+
return {
|
|
49
|
+
slug: project.slug ?? null,
|
|
50
|
+
name: project.name ?? null,
|
|
51
|
+
status: project.status ?? null,
|
|
52
|
+
enabled: project.enabled ?? null,
|
|
53
|
+
deployed_hash: project.deployed_hash ?? null,
|
|
54
|
+
deployment_matches_deployed_hash: project.deployment_matches_deployed_hash ?? false,
|
|
55
|
+
latest_successful_deployment: deployment === null ? null : deploymentJsonProjection(deployment),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
16
58
|
function projectSlugForView(project, environment) {
|
|
17
59
|
if (environment === undefined) {
|
|
18
60
|
return project;
|
|
@@ -39,9 +81,7 @@ function metadataSourceLabel(source) {
|
|
|
39
81
|
return safe ? labels[safe] ?? safe : null;
|
|
40
82
|
}
|
|
41
83
|
function formatDeploymentRevision(deployment) {
|
|
42
|
-
|
|
43
|
-
?? (0, source_provenance_1.sanitizeDisplayText)(deployment.commit_sha, 64);
|
|
44
|
-
if (!sha) {
|
|
84
|
+
if ((0, source_provenance_1.revisionSha)(deployment) === null) {
|
|
45
85
|
const archiveHash = (0, source_provenance_1.sanitizeDisplayText)(deployment.source_hash, 64);
|
|
46
86
|
return [
|
|
47
87
|
'No source revision was reported.',
|
|
@@ -49,7 +89,7 @@ function formatDeploymentRevision(deployment) {
|
|
|
49
89
|
];
|
|
50
90
|
}
|
|
51
91
|
const lines = [
|
|
52
|
-
`Revision (Client-reported): ${(0, source_provenance_1.
|
|
92
|
+
`Revision (Client-reported): ${(0, source_provenance_1.formatDetailedRevision)(deployment)}`,
|
|
53
93
|
];
|
|
54
94
|
const source = metadataSourceLabel(deployment.metadata_source);
|
|
55
95
|
if (source) {
|
|
@@ -112,8 +152,13 @@ async function projectViewWithConfig(project, options, config, writeLine = conso
|
|
|
112
152
|
}
|
|
113
153
|
try {
|
|
114
154
|
const response = await axios_1.default.get(`${config.host}/api/v1/projects/${encodeURIComponent(slug)}?include=deployment`, { headers: (0, api_1.getApiHeaders)(config) });
|
|
115
|
-
|
|
116
|
-
writeLine(
|
|
155
|
+
if (options.json) {
|
|
156
|
+
writeLine(JSON.stringify(projectViewJsonProjection(response.data), null, 2));
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
for (const line of formatProjectView(response.data)) {
|
|
160
|
+
writeLine(line);
|
|
161
|
+
}
|
|
117
162
|
}
|
|
118
163
|
}
|
|
119
164
|
catch (error) {
|
|
@@ -3,12 +3,12 @@ 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.formatDetailedRevision = void 0;
|
|
6
7
|
exports.buildRunListParams = buildRunListParams;
|
|
7
8
|
exports.runs = runs;
|
|
8
9
|
exports.summaryStatusLabel = summaryStatusLabel;
|
|
9
10
|
exports.detailedOutcomeTag = detailedOutcomeTag;
|
|
10
11
|
exports.formatRevisionCell = formatRevisionCell;
|
|
11
|
-
exports.formatDetailedRevision = formatDetailedRevision;
|
|
12
12
|
exports.displaySummaryTable = displaySummaryTable;
|
|
13
13
|
exports.displayDetailedList = displayDetailedList;
|
|
14
14
|
const axios_1 = __importDefault(require("axios"));
|
|
@@ -16,6 +16,8 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
16
16
|
const api_1 = require("../utils/api");
|
|
17
17
|
const table_1 = require("../utils/table");
|
|
18
18
|
const source_provenance_1 = require("../utils/source-provenance");
|
|
19
|
+
var source_provenance_2 = require("../utils/source-provenance");
|
|
20
|
+
Object.defineProperty(exports, "formatDetailedRevision", { enumerable: true, get: function () { return source_provenance_2.formatDetailedRevision; } });
|
|
19
21
|
/**
|
|
20
22
|
* Build the params object for GET /api/v1/runs.
|
|
21
23
|
* Extracted as a pure function so it can be unit-tested without mocking axios.
|
|
@@ -126,14 +128,8 @@ function detailedOutcomeTag(run) {
|
|
|
126
128
|
return ' [DEGRADED]';
|
|
127
129
|
return '';
|
|
128
130
|
}
|
|
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
131
|
function formatRevisionCell(revision) {
|
|
136
|
-
const sha = revisionSha(revision);
|
|
132
|
+
const sha = (0, source_provenance_1.revisionSha)(revision);
|
|
137
133
|
if (!sha)
|
|
138
134
|
return '-';
|
|
139
135
|
const dirty = revision?.dirty === true ? '*' : revision?.dirty === false ? '' : '?';
|
|
@@ -144,20 +140,6 @@ function formatRevisionCell(revision) {
|
|
|
144
140
|
: '';
|
|
145
141
|
return (0, table_1.sanitizeCell)(`${sha}${dirty}${behind}`);
|
|
146
142
|
}
|
|
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
|
-
}
|
|
161
143
|
function displaySummaryTable(runsList, projectName) {
|
|
162
144
|
const header = projectName ? `Recent runs for "${projectName}":` : 'Recent runs:';
|
|
163
145
|
console.log(chalk_1.default.blue(header));
|
|
@@ -208,7 +190,7 @@ function displayDetailedList(runsList, projectName) {
|
|
|
208
190
|
console.log(` Status: ${statusColor(status)}${chalk_1.default.gray(exitStr)}`);
|
|
209
191
|
console.log(` Trigger: ${chalk_1.default.gray(run.triggered_by || '-')}`);
|
|
210
192
|
if (Object.prototype.hasOwnProperty.call(run, 'deployed_revision')) {
|
|
211
|
-
console.log(` Revision (latest session): ${chalk_1.default.gray(formatDetailedRevision(run.deployed_revision))}`);
|
|
193
|
+
console.log(` Revision (latest session): ${chalk_1.default.gray((0, source_provenance_1.formatDetailedRevision)(run.deployed_revision))}`);
|
|
212
194
|
}
|
|
213
195
|
// Timeline
|
|
214
196
|
if (run.timeline) {
|
|
@@ -11,6 +11,7 @@ exports.errorMessage = errorMessage;
|
|
|
11
11
|
const axios_1 = __importDefault(require("axios"));
|
|
12
12
|
const chalk_1 = __importDefault(require("chalk"));
|
|
13
13
|
const api_1 = require("../utils/api");
|
|
14
|
+
const source_provenance_1 = require("../utils/source-provenance");
|
|
14
15
|
async function runView(runId, options) {
|
|
15
16
|
if (!/^\d+$/.test(runId)) {
|
|
16
17
|
console.error(chalk_1.default.red(`Invalid run id: "${runId}" (run ids are numeric — see \`solidactions run list\`).`));
|
|
@@ -96,6 +97,9 @@ async function runView(runId, options) {
|
|
|
96
97
|
steps: flatSteps,
|
|
97
98
|
logs: logsResponse.data.logs || '',
|
|
98
99
|
};
|
|
100
|
+
if (Object.prototype.hasOwnProperty.call(runData, 'deployed_revision')) {
|
|
101
|
+
output.deployed_revision = runData.deployed_revision;
|
|
102
|
+
}
|
|
99
103
|
if (runData.output)
|
|
100
104
|
output.output = runData.output;
|
|
101
105
|
if (runData.error)
|
|
@@ -137,6 +141,9 @@ function displayFullView(runData, timeline, steps, logsData) {
|
|
|
137
141
|
const exitStr = exitCode !== null && exitCode !== undefined ? ` (exit ${exitCode})` : '';
|
|
138
142
|
console.log(` Status: ${statusColor(status)}${chalk_1.default.gray(exitStr)}`);
|
|
139
143
|
console.log(` Trigger: ${chalk_1.default.gray(runData.triggered_by || '-')}`);
|
|
144
|
+
if (Object.prototype.hasOwnProperty.call(runData, 'deployed_revision')) {
|
|
145
|
+
console.log(` Revision (latest session): ${chalk_1.default.gray((0, source_provenance_1.formatDetailedRevision)(runData.deployed_revision))}`);
|
|
146
|
+
}
|
|
140
147
|
// Timeline
|
|
141
148
|
displayTimeline(runData, timeline, steps);
|
|
142
149
|
// Steps
|
package/dist/index.js
CHANGED
|
@@ -314,6 +314,7 @@ project
|
|
|
314
314
|
.description('View project status and the client-reported deployed revision')
|
|
315
315
|
.argument('<project>', 'Project family slug or name')
|
|
316
316
|
.option('-e, --env <environment>', 'Target environment (production/staging/dev). Defaults to dev.', 'dev')
|
|
317
|
+
.option('--json', 'Output as JSON')
|
|
317
318
|
.addHelpText('after', `
|
|
318
319
|
Defaults to dev: <project> is normalized as a project family and "-dev" is
|
|
319
320
|
appended. Use --env staging for the "-staging" target. Use --env production to
|
|
@@ -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.writeSecretFileSync = writeSecretFileSync;
|
|
7
|
+
exports.writeViaTempFileSync = writeViaTempFileSync;
|
|
8
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
/** The kernel's own symlink-resolution limit. */
|
|
12
|
+
const MAX_SYMLINK_HOPS = 40;
|
|
13
|
+
/**
|
|
14
|
+
* Find where a path that does not currently resolve should be created,
|
|
15
|
+
* following any symlink chain by hand.
|
|
16
|
+
*
|
|
17
|
+
* realpathSync cannot be used here: it throws ENOENT on a dangling symlink,
|
|
18
|
+
* and today's writeFileSync creates the link's target instead of failing.
|
|
19
|
+
*/
|
|
20
|
+
function resolveCreationPath(filePath) {
|
|
21
|
+
let current = filePath;
|
|
22
|
+
for (let hop = 0; hop <= MAX_SYMLINK_HOPS; hop++) {
|
|
23
|
+
let stats;
|
|
24
|
+
try {
|
|
25
|
+
stats = fs_1.default.lstatSync(current);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return current; // nothing here — this is the creation point
|
|
29
|
+
}
|
|
30
|
+
if (!stats.isSymbolicLink()) {
|
|
31
|
+
return current;
|
|
32
|
+
}
|
|
33
|
+
current = path_1.default.resolve(path_1.default.dirname(current), fs_1.default.readlinkSync(current));
|
|
34
|
+
}
|
|
35
|
+
// Defensive guard, unreachable in practice: statSync raises ELOOP first.
|
|
36
|
+
const error = new Error(`Too many symbolic links resolving ${filePath}`);
|
|
37
|
+
error.code = 'ELOOP';
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Write a secret-bearing file so the result is owner-only, whether or not the
|
|
42
|
+
* destination already exists.
|
|
43
|
+
*
|
|
44
|
+
* writeFileSync's `mode` only applies when it creates the file, so an existing
|
|
45
|
+
* world-readable file would silently keep its mode and receive fresh plaintext
|
|
46
|
+
* secrets. Writing to a sibling temp file at 0600 and renaming over the
|
|
47
|
+
* destination gives the final path a fresh inode carrying 0600 on both the
|
|
48
|
+
* create and the overwrite path, and makes the replacement atomic — readers
|
|
49
|
+
* never observe a partial file.
|
|
50
|
+
*
|
|
51
|
+
* The mode is masked by the process umask, which can only subtract bits, so
|
|
52
|
+
* the result is always <= 0600: never group- or world-readable.
|
|
53
|
+
*/
|
|
54
|
+
function writeSecretFileSync(filePath, contents) {
|
|
55
|
+
let stats;
|
|
56
|
+
try {
|
|
57
|
+
// statSync follows the whole chain, including magic /proc links.
|
|
58
|
+
stats = fs_1.default.statSync(filePath);
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
if (error.code !== 'ENOENT') {
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// FIFOs, sockets and character devices (`-o /dev/stdout`) have no
|
|
66
|
+
// persistent inode to protect, and a temp+rename beside them fails.
|
|
67
|
+
// Directories deliberately stay on the temp+rename path so they keep
|
|
68
|
+
// failing loudly.
|
|
69
|
+
if (stats && !stats.isFile() && !stats.isDirectory()) {
|
|
70
|
+
fs_1.default.writeFileSync(filePath, contents);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const target = stats ? fs_1.default.realpathSync(filePath) : resolveCreationPath(filePath);
|
|
74
|
+
const tempPath = path_1.default.join(path_1.default.dirname(target), `.${path_1.default.basename(target)}.${process.pid}.${crypto_1.default.randomBytes(4).toString('hex')}.tmp`);
|
|
75
|
+
writeViaTempFileSync(target, tempPath, contents);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Write `contents` to `tempPath` at 0600 and rename it over `target`.
|
|
79
|
+
*
|
|
80
|
+
* Exported so tests can stage a collision at a known temp path; production
|
|
81
|
+
* callers go through writeSecretFileSync, which randomizes that path.
|
|
82
|
+
*/
|
|
83
|
+
function writeViaTempFileSync(target, tempPath, contents) {
|
|
84
|
+
let created = false;
|
|
85
|
+
try {
|
|
86
|
+
// 'wx' refuses to follow or clobber an existing (or planted) temp path.
|
|
87
|
+
fs_1.default.writeFileSync(tempPath, contents, { flag: 'wx', mode: 0o600 });
|
|
88
|
+
created = true;
|
|
89
|
+
fs_1.default.renameSync(tempPath, target);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
// Only our own temp file may be removed: a failed 'wx' means the path
|
|
93
|
+
// holds someone else's file, which is not ours to delete.
|
|
94
|
+
if (created) {
|
|
95
|
+
try {
|
|
96
|
+
fs_1.default.unlinkSync(tempPath);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
// Nothing to clean up.
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -5,6 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.sanitizeDisplayText = sanitizeDisplayText;
|
|
7
7
|
exports.formatRevisionSummary = formatRevisionSummary;
|
|
8
|
+
exports.revisionSha = revisionSha;
|
|
9
|
+
exports.formatDetailedRevision = formatDetailedRevision;
|
|
8
10
|
exports.sanitizeRemoteUrl = sanitizeRemoteUrl;
|
|
9
11
|
exports.collectSourceMetadata = collectSourceMetadata;
|
|
10
12
|
exports.shouldCollectGitMetadata = shouldCollectGitMetadata;
|
|
@@ -16,6 +18,7 @@ const os_1 = __importDefault(require("os"));
|
|
|
16
18
|
const path_1 = __importDefault(require("path"));
|
|
17
19
|
const child_process_1 = require("child_process");
|
|
18
20
|
const form_data_1 = __importDefault(require("form-data"));
|
|
21
|
+
const table_1 = require("./table");
|
|
19
22
|
const DISPLAY_FORMATTING = /[\x00-\x1f\x7f\u061c\u200b-\u200f\u202a-\u202e\u2060\u2066-\u2069\ufeff]/g;
|
|
20
23
|
const SHA_PATTERN = /^[0-9a-f]{7,64}$/i;
|
|
21
24
|
const STRICT_ISO_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/;
|
|
@@ -46,6 +49,26 @@ function formatRevisionSummary(metadata) {
|
|
|
46
49
|
}
|
|
47
50
|
return `${sha} (${dirtyLabel(typeof metadata.dirty === 'boolean' ? metadata.dirty : null)})`;
|
|
48
51
|
}
|
|
52
|
+
function revisionSha(revision) {
|
|
53
|
+
if (!revision)
|
|
54
|
+
return null;
|
|
55
|
+
return sanitizeDisplayText(revision.short_sha, 16)
|
|
56
|
+
?? sanitizeDisplayText(revision.commit_sha, 64);
|
|
57
|
+
}
|
|
58
|
+
function formatDetailedRevision(revision) {
|
|
59
|
+
const sha = revisionSha(revision);
|
|
60
|
+
if (!sha)
|
|
61
|
+
return 'unknown';
|
|
62
|
+
const states = [revision?.dirty === true
|
|
63
|
+
? 'DIRTY'
|
|
64
|
+
: revision?.dirty === false ? 'clean' : 'dirty state unknown'];
|
|
65
|
+
const branch = sanitizeDisplayText(revision?.default_branch, 255);
|
|
66
|
+
if (branch && typeof revision?.commits_behind === 'number'
|
|
67
|
+
&& Number.isSafeInteger(revision.commits_behind) && revision.commits_behind > 0) {
|
|
68
|
+
states.push(`${revision.commits_behind} behind origin/${branch} at deploy`);
|
|
69
|
+
}
|
|
70
|
+
return (0, table_1.sanitizeCell)(`${sha} (${states.join(', ')})`);
|
|
71
|
+
}
|
|
49
72
|
function shaValue(value) {
|
|
50
73
|
const sanitized = displayValue(value, 64);
|
|
51
74
|
return sanitized && SHA_PATTERN.test(sanitized) ? sanitized : null;
|