@treeseed/sdk 0.4.10 → 0.4.12
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/operations/services/workspace-save-script.d.ts +26 -0
- package/dist/operations/services/workspace-save-script.js +50 -0
- package/dist/platform/tenant-config.js +9 -0
- package/dist/scripts/workspace-command-e2e.js +0 -2
- package/dist/scripts/workspace-save.js +47 -107
- package/package.json +1 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { TreeseedWorkflowResult } from '../../workflow.ts';
|
|
2
|
+
export type SaveScriptArgs = {
|
|
3
|
+
hotfix: boolean;
|
|
4
|
+
message: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function parseWorkspaceSaveScriptArgs(argv: string[]): SaveScriptArgs;
|
|
7
|
+
export declare function formatWorkspaceSaveSuccessReport(result: TreeseedWorkflowResult<Record<string, unknown>>): {
|
|
8
|
+
ok: boolean;
|
|
9
|
+
kind: string;
|
|
10
|
+
operation: import("../../workflow.ts").TreeseedWorkflowOperationId;
|
|
11
|
+
};
|
|
12
|
+
export declare function formatWorkspaceSaveFailureReport(error: unknown): {
|
|
13
|
+
ok: boolean;
|
|
14
|
+
kind: import("../../workflow.ts").TreeseedWorkflowErrorCode;
|
|
15
|
+
operation: import("../../workflow.ts").TreeseedWorkflowOperationId;
|
|
16
|
+
message: string;
|
|
17
|
+
details: Record<string, unknown> | null;
|
|
18
|
+
exitCode: number;
|
|
19
|
+
} | {
|
|
20
|
+
ok: boolean;
|
|
21
|
+
kind: string;
|
|
22
|
+
operation: string;
|
|
23
|
+
message: string;
|
|
24
|
+
exitCode: number;
|
|
25
|
+
details?: undefined;
|
|
26
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { TreeseedWorkflowError } from "../../workflow/operations.js";
|
|
2
|
+
function parseWorkspaceSaveScriptArgs(argv) {
|
|
3
|
+
const parsed = {
|
|
4
|
+
hotfix: false,
|
|
5
|
+
messageParts: []
|
|
6
|
+
};
|
|
7
|
+
for (const current of argv) {
|
|
8
|
+
if (current === "--hotfix") {
|
|
9
|
+
parsed.hotfix = true;
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
parsed.messageParts.push(current);
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
hotfix: parsed.hotfix,
|
|
16
|
+
message: parsed.messageParts.join(" ").trim()
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function formatWorkspaceSaveSuccessReport(result) {
|
|
20
|
+
return {
|
|
21
|
+
ok: true,
|
|
22
|
+
kind: "success",
|
|
23
|
+
operation: result.operation,
|
|
24
|
+
...result.payload
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function formatWorkspaceSaveFailureReport(error) {
|
|
28
|
+
if (error instanceof TreeseedWorkflowError) {
|
|
29
|
+
return {
|
|
30
|
+
ok: false,
|
|
31
|
+
kind: error.code,
|
|
32
|
+
operation: error.operation,
|
|
33
|
+
message: error.message,
|
|
34
|
+
details: error.details ?? null,
|
|
35
|
+
exitCode: error.exitCode ?? 1
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
ok: false,
|
|
40
|
+
kind: "unsupported_state",
|
|
41
|
+
operation: "save",
|
|
42
|
+
message: error instanceof Error ? error.message : String(error),
|
|
43
|
+
exitCode: 1
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export {
|
|
47
|
+
formatWorkspaceSaveFailureReport,
|
|
48
|
+
formatWorkspaceSaveSuccessReport,
|
|
49
|
+
parseWorkspaceSaveScriptArgs
|
|
50
|
+
};
|
|
@@ -69,6 +69,15 @@ function tenantRootCandidates() {
|
|
|
69
69
|
return uniqueCandidates([...cwdCandidates, packageFixtureRoot, ...packageCandidates]);
|
|
70
70
|
}
|
|
71
71
|
function resolveTenantPath(manifestPath) {
|
|
72
|
+
if (existsSync(manifestPath) && resolve(manifestPath) === manifestPath) {
|
|
73
|
+
return resolve(manifestPath);
|
|
74
|
+
}
|
|
75
|
+
if (explicitTenantRoot) {
|
|
76
|
+
const explicitCandidate = resolve(explicitTenantRoot, manifestPath);
|
|
77
|
+
if (existsSync(explicitCandidate)) {
|
|
78
|
+
return explicitCandidate;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
72
81
|
if (existsSync(manifestPath)) {
|
|
73
82
|
return resolve(manifestPath);
|
|
74
83
|
}
|
|
@@ -549,7 +549,6 @@ async function runLocalSuite() {
|
|
|
549
549
|
try {
|
|
550
550
|
return runCommand('save-no-changes', process.execPath, [packageScriptPath('treeseed'), 'save', 'test: no-op save'], {
|
|
551
551
|
cwd: clonedWorkspace.workingRoot,
|
|
552
|
-
allowedExitCodes: [1],
|
|
553
552
|
env: cacheEnv(),
|
|
554
553
|
});
|
|
555
554
|
}
|
|
@@ -643,7 +642,6 @@ async function runStagingSuite() {
|
|
|
643
642
|
return runCommand('staging-save-no-op', 'npm', ['run', 'save', '--', 'test: staging no-op save'], {
|
|
644
643
|
cwd: staging.workingRoot,
|
|
645
644
|
env: cacheEnv(createWranglerCommandEnv()),
|
|
646
|
-
allowedExitCodes: [1],
|
|
647
645
|
timeoutMs: 180000,
|
|
648
646
|
});
|
|
649
647
|
});
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { dirname, resolve } from 'node:path';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { remoteBranchExists, STAGING_BRANCH, PRODUCTION_BRANCH } from '../operations/services/git-workflow.js';
|
|
7
|
-
import { run, workspaceRoot } from '../operations/services/workspace-tools.js';
|
|
8
|
-
import { runWorkspaceSavePreflight } from '../operations/services/save-deploy-preflight.js';
|
|
4
|
+
import { TreeseedWorkflowError, TreeseedWorkflowSdk } from '../workflow.js';
|
|
5
|
+
import { formatWorkspaceSaveFailureReport, formatWorkspaceSaveSuccessReport, parseWorkspaceSaveScriptArgs, } from '../operations/services/workspace-save-script.js';
|
|
9
6
|
function writeSaveReport(payload) {
|
|
10
7
|
const target = process.env.TREESEED_SAVE_REPORT_PATH;
|
|
11
8
|
if (!target) {
|
|
@@ -15,110 +12,53 @@ function writeSaveReport(payload) {
|
|
|
15
12
|
mkdirSync(dirname(filePath), { recursive: true });
|
|
16
13
|
writeFileSync(filePath, `${JSON.stringify(payload, null, 2)}\n`, 'utf8');
|
|
17
14
|
}
|
|
18
|
-
function
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
parsed.hotfix = true;
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
|
-
parsed.messageParts.push(current);
|
|
29
|
-
}
|
|
30
|
-
return {
|
|
31
|
-
hotfix: parsed.hotfix,
|
|
32
|
-
message: parsed.messageParts.join(' ').trim(),
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
const options = parseArgs(process.argv.slice(2));
|
|
36
|
-
const message = options.message;
|
|
37
|
-
const root = workspaceRoot();
|
|
38
|
-
const gitRoot = repoRoot(root);
|
|
39
|
-
const branch = currentBranch(gitRoot);
|
|
40
|
-
const scope = branch === STAGING_BRANCH ? 'staging' : branch === PRODUCTION_BRANCH ? 'prod' : 'local';
|
|
41
|
-
applyTreeseedEnvironmentToProcess({ tenantRoot: root, scope, override: true });
|
|
42
|
-
if (!message) {
|
|
43
|
-
writeSaveReport({ ok: false, kind: 'usage', message: 'Treeseed save requires a commit message.' });
|
|
44
|
-
console.error('Treeseed save requires a commit message. Usage: treeseed save <message>');
|
|
45
|
-
process.exit(1);
|
|
46
|
-
}
|
|
47
|
-
if (!branch) {
|
|
48
|
-
writeSaveReport({ ok: false, kind: 'missing_branch', message: 'Treeseed save requires an active git branch.' });
|
|
49
|
-
console.error('Treeseed save requires an active git branch.');
|
|
50
|
-
process.exit(1);
|
|
51
|
-
}
|
|
52
|
-
if (branch === PRODUCTION_BRANCH && !options.hotfix) {
|
|
53
|
-
writeSaveReport({
|
|
54
|
-
ok: false,
|
|
55
|
-
kind: 'protected_branch',
|
|
56
|
-
branch,
|
|
57
|
-
message: 'Treeseed save is blocked on main. Use `treeseed release` for normal production promotion or `treeseed save --hotfix` for an explicit hotfix.',
|
|
58
|
-
});
|
|
59
|
-
console.error('Treeseed save is blocked on main. Use `treeseed release` for normal production promotion or `treeseed save --hotfix` for an explicit hotfix.');
|
|
60
|
-
process.exit(1);
|
|
61
|
-
}
|
|
62
|
-
try {
|
|
63
|
-
originRemoteUrl(gitRoot);
|
|
64
|
-
}
|
|
65
|
-
catch {
|
|
66
|
-
writeSaveReport({ ok: false, kind: 'missing_origin', message: 'Treeseed save requires an origin remote.' });
|
|
67
|
-
console.error('Treeseed save requires an origin remote.');
|
|
68
|
-
process.exit(1);
|
|
69
|
-
}
|
|
70
|
-
try {
|
|
71
|
-
runWorkspaceSavePreflight({ cwd: root });
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
const kind = error?.kind ?? 'preflight_failed';
|
|
75
|
-
writeSaveReport({
|
|
76
|
-
ok: false,
|
|
77
|
-
kind,
|
|
78
|
-
message: error instanceof Error ? error.message : String(error),
|
|
79
|
-
});
|
|
80
|
-
console.error(error instanceof Error ? error.message : String(error));
|
|
81
|
-
process.exit(error?.exitCode ?? 1);
|
|
82
|
-
}
|
|
83
|
-
if (!hasMeaningfulChanges(gitRoot)) {
|
|
84
|
-
writeSaveReport({ ok: false, kind: 'no_changes', message: 'Treeseed save found no meaningful repository changes to commit.' });
|
|
85
|
-
console.error('Treeseed save found no meaningful repository changes to commit.');
|
|
86
|
-
process.exit(1);
|
|
87
|
-
}
|
|
88
|
-
run('git', ['add', '-A'], { cwd: gitRoot });
|
|
89
|
-
run('git', ['commit', '-m', message], { cwd: gitRoot });
|
|
90
|
-
try {
|
|
91
|
-
if (remoteBranchExists(gitRoot, branch)) {
|
|
92
|
-
run('git', ['pull', '--rebase', 'origin', branch], { cwd: gitRoot });
|
|
93
|
-
run('git', ['push', 'origin', branch], { cwd: gitRoot });
|
|
15
|
+
function printSaveSummary(payload) {
|
|
16
|
+
const commitSha = typeof payload.commitSha === 'string' ? payload.commitSha : '';
|
|
17
|
+
const previewStatus = typeof payload.previewAction?.status === 'string'
|
|
18
|
+
? String(payload.previewAction.status)
|
|
19
|
+
: 'skipped';
|
|
20
|
+
if (payload.noChanges === true) {
|
|
21
|
+
console.log('Treeseed save found no new changes and confirmed branch sync.');
|
|
94
22
|
}
|
|
95
23
|
else {
|
|
96
|
-
|
|
24
|
+
console.log('Treeseed save completed successfully.');
|
|
25
|
+
}
|
|
26
|
+
if (typeof payload.branch === 'string') {
|
|
27
|
+
console.log(`Branch: ${payload.branch}`);
|
|
28
|
+
}
|
|
29
|
+
if (typeof payload.scope === 'string') {
|
|
30
|
+
console.log(`Environment scope: ${payload.scope}`);
|
|
97
31
|
}
|
|
32
|
+
if (commitSha) {
|
|
33
|
+
console.log(`Commit: ${commitSha.slice(0, 12)}`);
|
|
34
|
+
}
|
|
35
|
+
console.log(`Preview action: ${previewStatus}`);
|
|
98
36
|
}
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
branch,
|
|
105
|
-
report,
|
|
106
|
-
formatted: formatMergeConflictReport(report, gitRoot, branch),
|
|
37
|
+
async function main() {
|
|
38
|
+
const options = parseWorkspaceSaveScriptArgs(process.argv.slice(2));
|
|
39
|
+
const workflow = new TreeseedWorkflowSdk({
|
|
40
|
+
cwd: process.cwd(),
|
|
41
|
+
env: process.env,
|
|
107
42
|
});
|
|
108
|
-
|
|
109
|
-
|
|
43
|
+
try {
|
|
44
|
+
const result = await workflow.save({
|
|
45
|
+
message: options.message,
|
|
46
|
+
hotfix: options.hotfix,
|
|
47
|
+
});
|
|
48
|
+
const payload = result.payload;
|
|
49
|
+
writeSaveReport(formatWorkspaceSaveSuccessReport(result));
|
|
50
|
+
printSaveSummary(payload);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
if (error instanceof TreeseedWorkflowError) {
|
|
54
|
+
writeSaveReport(formatWorkspaceSaveFailureReport(error));
|
|
55
|
+
console.error(error.message);
|
|
56
|
+
process.exit(error.exitCode ?? 1);
|
|
57
|
+
}
|
|
58
|
+
const report = formatWorkspaceSaveFailureReport(error);
|
|
59
|
+
console.error(report.message);
|
|
60
|
+
writeSaveReport(report);
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
110
63
|
}
|
|
111
|
-
|
|
112
|
-
ok: true,
|
|
113
|
-
kind: 'success',
|
|
114
|
-
message,
|
|
115
|
-
branch,
|
|
116
|
-
scope,
|
|
117
|
-
hotfix: options.hotfix,
|
|
118
|
-
root,
|
|
119
|
-
repositoryRoot: gitRoot,
|
|
120
|
-
};
|
|
121
|
-
writeSaveReport(summary);
|
|
122
|
-
console.log('Treeseed save completed successfully.');
|
|
123
|
-
console.log(`Branch: ${branch}`);
|
|
124
|
-
console.log(`Environment scope: ${scope}`);
|
|
64
|
+
await main();
|