projectops 4.104.5 → 4.104.7
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 +1 -1
- package/bin/projectops.js +4 -4
- package/package.json +1 -1
- package/src/cli/args.js +43 -43
- package/src/cli/errors.js +8 -8
- package/src/cli/help.js +4 -4
- package/src/commands/doctor.js +39 -39
- package/src/commands/full.js +29 -29
- package/src/commands/interactive.js +86 -86
- package/src/commands/issues.js +5 -5
- package/src/commands/skills.js +13 -13
- package/src/commands/version.js +8 -8
- package/src/commands/workflows.js +19 -19
- package/src/context.js +24 -24
- package/src/core/agent-guide.js +5 -5
- package/src/core/assets.js +11 -11
- package/src/core/baseline.js +24 -24
- package/src/core/branch-sub.js +23 -23
- package/src/core/breaking-check.js +21 -21
- package/src/core/breaking.js +6 -6
- package/src/core/ci-minutes-sub.js +13 -13
- package/src/core/constants.js +17 -17
- package/src/core/copy/coderabbit.js +10 -10
- package/src/core/copy/gitignore.js +9 -9
- package/src/core/copy/readme.js +7 -7
- package/src/core/copy/simple.js +35 -35
- package/src/core/copy/util.js +9 -9
- package/src/core/copy/workflows.js +99 -99
- package/src/core/detect-fs.js +21 -21
- package/src/core/detect.js +12 -12
- package/src/core/development-branch.js +11 -11
- package/src/core/exclusions.js +12 -12
- package/src/core/fsutil.js +9 -9
- package/src/core/git-branch.js +11 -11
- package/src/core/ide/adapter.js +23 -23
- package/src/core/ide/adapters/claude.js +12 -12
- package/src/core/ide/adapters/codex.js +4 -4
- package/src/core/ide/adapters/copilot.js +12 -12
- package/src/core/ide/adapters/cursor.js +7 -7
- package/src/core/ide/adapters/gemini.js +5 -5
- package/src/core/ide/adapters/pi-common.js +12 -12
- package/src/core/ide/adapters/pi-harness.js +7 -7
- package/src/core/ide/adapters/pi.js +3 -3
- package/src/core/ide/home-skills.js +6 -6
- package/src/core/ide/legacy.js +8 -8
- package/src/core/ide/registry.js +6 -6
- package/src/core/ide/runner.js +15 -15
- package/src/core/ide/skills-copy.js +34 -34
- package/src/core/ide/stable-entry.js +11 -11
- package/src/core/ide/util.js +4 -4
- package/src/core/incoming.js +13 -13
- package/src/core/label-style.js +12 -12
- package/src/core/migration-guide.js +19 -19
- package/src/core/migrations/index.js +16 -16
- package/src/core/migrations/registry.js +39 -39
- package/src/core/migrations/rules/legacy-dirs.js +6 -6
- package/src/core/migrations/rules/obsolete-workflows.js +4 -4
- package/src/core/migrations/rules/root-files.js +3 -3
- package/src/core/migrations/rules/settings-extractors.js +8 -8
- package/src/core/options-ask.js +104 -104
- package/src/core/options-schema.js +23 -23
- package/src/core/orphan-workflows.js +14 -14
- package/src/core/paths-resolve.js +54 -54
- package/src/core/paths.js +2 -2
- package/src/core/placeholder-triggers.js +10 -10
- package/src/core/repo-language.js +10 -10
- package/src/core/resolve-options.js +30 -30
- package/src/core/run-trace.js +54 -54
- package/src/core/store-locales-hint.js +13 -13
- package/src/core/verify.js +27 -27
- package/src/core/version-yml.js +115 -115
- package/src/core/wizard-env.js +42 -42
- package/src/core/wizard-labels.js +31 -31
- package/src/core/workflow-groups.js +14 -14
- package/src/i18n/core.en.js +1 -1
- package/src/i18n/doctor.en.js +1 -1
- package/src/i18n/ide.en.js +1 -1
- package/src/i18n/migrate.en.js +1 -1
- package/src/i18n/options.en.js +1 -1
- package/src/index.js +60 -60
- package/src/ui/ansi.js +5 -5
- package/src/ui/env-plan.js +44 -44
- package/src/ui/prompts.js +21 -21
- package/src/ui/readline-engine.js +38 -38
- package/src/ui/skills-prompts.js +4 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Workflow copy engine.
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
// -
|
|
3
|
+
// Conflict decisions (differs from the existing file) come in via hooks.decisions (Map<filename, 'skip'|'backup'|'template'>).
|
|
4
|
+
// - The real wizard (commands/interactive.js) gets the conflict list from listWorkflowConflicts and builds the Map itself.
|
|
5
5
|
import { join, basename } from "node:path";
|
|
6
6
|
import { existsSync, readFileSync, writeFileSync, renameSync } from "node:fs";
|
|
7
7
|
import { PATHS } from "../paths.js";
|
|
@@ -15,9 +15,9 @@ import { PUBLISH_TARGETS } from "../constants.js";
|
|
|
15
15
|
import { commonOptionalGroups, serverDeployEnabled, SERVER_DEPLOY_DIR } from "../workflow-groups.js";
|
|
16
16
|
import { t } from "../../i18n/index.js";
|
|
17
17
|
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
//
|
|
18
|
+
// Are all branch filters in the on: block develop only? (#810)
|
|
19
|
+
// Spots workflows that would never run when installed in a repo without a development branch.
|
|
20
|
+
// Any event other than workflow_dispatch (schedule, issues, etc.) can make it run on its own, so false.
|
|
21
21
|
export function onlyTriggersOnDevelop(content) {
|
|
22
22
|
const m = String(content).match(/^on:\s*\n((?:[ \t]+.*\n|\s*\n)+)/m);
|
|
23
23
|
if (!m) return false;
|
|
@@ -27,15 +27,15 @@ export function onlyTriggersOnDevelop(content) {
|
|
|
27
27
|
const branches = [];
|
|
28
28
|
for (const b of block.matchAll(/^\s+branches:\s*\[([^\]]*)\]/gm)) branches.push(...b[1].split(",").map((s) => s.trim().replace(/["']/g, "")).filter(Boolean));
|
|
29
29
|
for (const b of block.matchAll(/^\s+branches:\s*\n((?:\s+-\s*.*\n)+)/gm)) branches.push(...[...b[1].matchAll(/-\s*["']?([^"'\s#]+)/g)].map((x) => x[1]));
|
|
30
|
-
// push/pull_request
|
|
30
|
+
// Every push/pull_request needs a branches filter — a push without a filter runs on every branch
|
|
31
31
|
const filtered = (block.match(/^\s+branches:/gm) || []).length;
|
|
32
32
|
const needFilter = events.filter((e) => e !== "workflow_dispatch").length;
|
|
33
33
|
return branches.length > 0 && filtered >= needFilter && branches.every((b) => b === "develop");
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
//
|
|
37
|
-
// values/useDefaults: env
|
|
38
|
-
// trace(#494):
|
|
36
|
+
// Apply env substitution to one file and update the target file.
|
|
37
|
+
// values/useDefaults: env plan (promptEnvPlan) result — if unset, the default path (current force behavior).
|
|
38
|
+
// trace (#494): one env.substituted event per substitution (with before/after — evidence to spot substitution mismatch bugs at once).
|
|
39
39
|
function configureEnv(targetPath, filename, { type, projectPath = ".", repoName = "", resolvers = {}, collectAsks = null, values = new Map(), useDefaults = true, trace = null }) {
|
|
40
40
|
const content = readFileSync(targetPath, "utf8");
|
|
41
41
|
if (!content.includes("@wizard")) return;
|
|
@@ -47,23 +47,23 @@ function configureEnv(targetPath, filename, { type, projectPath = ".", repoName
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
// util
|
|
51
|
-
// util
|
|
50
|
+
// util version sync workflow (#491) — meaningful only in repos with .github/util/ modules (version.json).
|
|
51
|
+
// Copied into a repo without util (e.g. spring alone), its trigger never fires — no-op pollution.
|
|
52
52
|
const UTIL_VERSION_SYNC = "PROJECT-COMMON-TEMPLATE-UTIL-VERSION-SYNC.yml";
|
|
53
53
|
|
|
54
|
-
//
|
|
55
|
-
//
|
|
54
|
+
// Will util modules exist in this integration — true if already in the target (update),
|
|
55
|
+
// or if the selected types' util is in the template and about to be copied (runFull step 6).
|
|
56
56
|
function utilSyncApplies(tempDir, targetRoot, types) {
|
|
57
57
|
if (exists(join(targetRoot, ".github", "util"))) return true;
|
|
58
58
|
return types.some((t) => exists(join(tempDir, ".github", "util", t)));
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
// 4
|
|
61
|
+
// 4 classes (new/unchanged/upstream/changed) — relative to the target workflow directory.
|
|
62
62
|
//
|
|
63
|
-
// upstream(#557):
|
|
64
|
-
//
|
|
65
|
-
// baseline
|
|
66
|
-
// (
|
|
63
|
+
// upstream (#557): the user did not touch it, only the template changed. No reason to ask,
|
|
64
|
+
// so just bring it up to date. Needs the baseline (install-time hashes) to decide.
|
|
65
|
+
// Without a baseline or a record for the file, it cannot be decided → falls into changed as before
|
|
66
|
+
// (behavior of existing integrated repos does not change).
|
|
67
67
|
function classify(srcDir, workflowsDir, envOpts, baseline = null) {
|
|
68
68
|
const result = { newFiles: [], unchanged: [], changed: [], upstream: [] };
|
|
69
69
|
for (const filename of listYamlFiles(srcDir)) {
|
|
@@ -73,8 +73,8 @@ function classify(srcDir, workflowsDir, envOpts, baseline = null) {
|
|
|
73
73
|
const tpl = readFileSync(src, "utf8");
|
|
74
74
|
const inst = readFileSync(dst, "utf8");
|
|
75
75
|
if (isUnchanged(tpl, inst, { ...envOpts, filename })) { result.unchanged.push(filename); continue; }
|
|
76
|
-
//
|
|
77
|
-
// baseline
|
|
76
|
+
// Reaching here means "current template render ≠ installed copy" — either a user edit or an upstream change.
|
|
77
|
+
// The baseline tells the two apart.
|
|
78
78
|
const modified = isUserModified(baseline, filename, inst);
|
|
79
79
|
if (modified === false) result.upstream.push(filename);
|
|
80
80
|
else result.changed.push(filename);
|
|
@@ -85,42 +85,42 @@ function classify(srcDir, workflowsDir, envOpts, baseline = null) {
|
|
|
85
85
|
return result;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
// copy_workflows
|
|
88
|
+
// copy_workflows main body (sync — existing callers unchanged).
|
|
89
89
|
// context: { types:[], paths:Map, deployTarget, publishTargets:[], includeSecretBackup, aiPrSummary, force, repoName, resolvers,
|
|
90
|
-
// envValues?:Map<key,value>, envUseDefaults?:boolean } ← env
|
|
91
|
-
// deployTarget(#439
|
|
92
|
-
// common/deploy/<target
|
|
93
|
-
// hooks: { decisions?: Map<filename, 'skip'|'backup'|'template'> } —
|
|
94
|
-
//
|
|
90
|
+
// envValues?:Map<key,value>, envUseDefaults?:boolean } ← injection point for the env plan (promptEnvPlan) result
|
|
91
|
+
// deployTarget (#439 pick one): 'docker-ssh' (default) | 'vercel' | 'none' — server-deploy only with docker-ssh,
|
|
92
|
+
// common/deploy/<target>/ copied for that target. publishTargets (#439 multiple): 'nexus'|'npm'|'github-packages'.
|
|
93
|
+
// hooks: { decisions?: Map<filename, 'skip'|'backup'|'template'> } — conflict decisions for existing (changed) files.
|
|
94
|
+
// Returns {copied, skipped, templateAdded, optionalCopied, copiedFiles[]} — copiedFiles are the file names actually copied or replaced (#473 summary)
|
|
95
95
|
export function copyWorkflows(context, tempDir, targetRoot = ".", hooks = {}) {
|
|
96
96
|
const { types = [], paths = new Map(), deployTarget = "docker-ssh", publishTargets = [], includeSecretBackup = false, aiPrSummary = true, projectsSync = true, repoName = "", resolvers = {}, envValues = new Map(), envUseDefaults = true, branch = "", deployBranch = "", deployTriggerBranch = "", ciMinutesSaver = false } = context;
|
|
97
97
|
const decisions = hooks.decisions instanceof Map ? hooks.decisions : new Map();
|
|
98
|
-
const trace = hooks.trace ?? null; // #494 —
|
|
98
|
+
const trace = hooks.trace ?? null; // #494 — run trace (null-safe: every event is a no-op when not injected)
|
|
99
99
|
const workflowsDir = join(targetRoot, PATHS.workflowsDir);
|
|
100
|
-
//
|
|
100
|
+
// Install-time reference point (#557) — null if missing, and classify falls back to the old 2-way check.
|
|
101
101
|
const baseline = readBaseline(targetRoot);
|
|
102
102
|
const projectTypesDir = join(tempDir, PATHS.workflowsDir, PATHS.projectTypesDir);
|
|
103
103
|
if (!exists(projectTypesDir)) throw new Error(t("copy.templateStructureError"));
|
|
104
104
|
|
|
105
105
|
const counters = { copied: 0, skipped: 0, templateAdded: 0, optionalCopied: 0, copiedFiles: [],
|
|
106
|
-
replacedBak: [], // #673 —
|
|
107
|
-
skippedConflicts: [] }; // #654 —
|
|
108
|
-
const deployValues = new Map(); // Map<type, Map<key,value>> —
|
|
106
|
+
replacedBak: [], // #673 — files replaced after a .bak backup without knowing whether they were edited (no reference point)
|
|
107
|
+
skippedConflicts: [] }; // #654 — { filename, incoming, added, removed } per kept user-edited file
|
|
108
|
+
const deployValues = new Map(); // Map<type, Map<key,value>> — ask values for the deploy block
|
|
109
109
|
counters.deployValues = deployValues;
|
|
110
|
-
//
|
|
110
|
+
// Branch strategy (#477) — with the standard (main/develop), substitution and virtual comparison are both no-ops
|
|
111
111
|
const branches = { defaultBranch: branch || "main", deployBranch: deployBranch || "develop", deployTriggerBranch: deployTriggerBranch || "", ciMinutesSaver: !!ciMinutesSaver };
|
|
112
|
-
// values/useDefaults
|
|
112
|
+
// values/useDefaults matter only on the substitution path (isUnchanged forces useDefaults:true internally — virtual comparison intact)
|
|
113
113
|
const envOptsFor = (type) => ({ type, projectPath: paths.get(type) || ".", repoName, resolvers, values: envValues, useDefaults: envUseDefaults, branches });
|
|
114
114
|
|
|
115
|
-
//
|
|
116
|
-
// excluded : version.yml options.excluded_workflows
|
|
117
|
-
// deleted-by-user :
|
|
118
|
-
// no-dev-branch :
|
|
115
|
+
// New files not to install (#810) — the ones that came back on every install.
|
|
116
|
+
// excluded : files the user listed in version.yml options.excluded_workflows
|
|
117
|
+
// deleted-by-user : we have an install record (baseline) but the file is gone = the user deleted it (.bak files are our own cleanup, so excluded)
|
|
118
|
+
// no-dev-branch : workflows that run only on the development branch when it is definitely missing on the remote
|
|
119
119
|
const notInstalled = [];
|
|
120
120
|
Object.defineProperty(counters, "notInstalled", { value: notInstalled, enumerable: false });
|
|
121
121
|
const excludedSet = new Set(context.excludedWorkflows || []);
|
|
122
122
|
const devName = branches.deployBranch;
|
|
123
|
-
let devMissing = null; //
|
|
123
|
+
let devMissing = null; // Query the remote only once, when needed
|
|
124
124
|
const isDevMissing = () => {
|
|
125
125
|
if (devMissing === null) {
|
|
126
126
|
const st = devName === branches.defaultBranch ? null : branchStatus(targetRoot, devName);
|
|
@@ -138,23 +138,23 @@ export function copyWorkflows(context, tempDir, targetRoot = ".", hooks = {}) {
|
|
|
138
138
|
if (!reason) return false;
|
|
139
139
|
const info = { filename, reason, incoming: "" };
|
|
140
140
|
try {
|
|
141
|
-
//
|
|
141
|
+
// Leave the render in incoming so a change of mind can restore it with one cp
|
|
142
142
|
const rendered = substituteBranches(substituteEnv(readFileSync(join(srcDir, filename), "utf8"),
|
|
143
143
|
{ ...envOptsFor(group.split("/")[0]), useDefaults: true }), branches, filename);
|
|
144
144
|
info.incoming = saveIncoming(targetRoot, filename, rendered);
|
|
145
|
-
} catch { /*
|
|
145
|
+
} catch { /* Only the notice is lost */ }
|
|
146
146
|
notInstalled.push(info);
|
|
147
147
|
trace?.event("copy", "not-installed", filename, { group, reason });
|
|
148
148
|
return true;
|
|
149
149
|
};
|
|
150
150
|
Object.defineProperty(counters, "skipNew", { value: skipNew, enumerable: false });
|
|
151
151
|
|
|
152
|
-
//
|
|
153
|
-
//
|
|
152
|
+
// When keeping a user-edited file, leave a copy of the new template in incoming (#654).
|
|
153
|
+
// Failures shrink to one warning line — the merge notice must not kill the whole copy.
|
|
154
154
|
const onSkip = (srcDir, filename, type) => {
|
|
155
155
|
const info = { filename, incoming: "", added: null, removed: null };
|
|
156
156
|
try {
|
|
157
|
-
//
|
|
157
|
+
// Must go through the same render as install (default substitution + branch substitution) so the diff shows only "real differences"
|
|
158
158
|
const rendered = substituteBranches(
|
|
159
159
|
substituteEnv(readFileSync(join(srcDir, filename), "utf8"), { ...envOptsFor(type), useDefaults: true }), branches, filename);
|
|
160
160
|
info.incoming = saveIncoming(targetRoot, filename, rendered);
|
|
@@ -167,18 +167,18 @@ export function copyWorkflows(context, tempDir, targetRoot = ".", hooks = {}) {
|
|
|
167
167
|
counters.skippedConflicts.push(info);
|
|
168
168
|
return info;
|
|
169
169
|
};
|
|
170
|
-
//
|
|
170
|
+
// Do not add enumerable fields to the returned object (existing callers and tests rely on the counters shape)
|
|
171
171
|
Object.defineProperty(counters, "onSkip", { value: onSkip, enumerable: false });
|
|
172
172
|
|
|
173
|
-
// (1) common —
|
|
174
|
-
//
|
|
175
|
-
//
|
|
173
|
+
// (1) common — gets the same checks and protection as per-type files (#560).
|
|
174
|
+
// Workflows like the release pipeline, where each project appends different steps, get edited by users even in common.
|
|
175
|
+
// So edited files are not blindly overwritten; they go through the same conflict check and backup as per-type files.
|
|
176
176
|
const commonDir = join(projectTypesDir, "common");
|
|
177
177
|
if (exists(commonDir)) {
|
|
178
178
|
const commonEnv = envOptsFor("common");
|
|
179
179
|
const commonClass = classify(commonDir, workflowsDir, commonEnv, baseline);
|
|
180
180
|
for (const filename of listYamlFiles(commonDir)) {
|
|
181
|
-
// #491 — util
|
|
181
|
+
// #491 — copy the util sync workflow only to repos that have (or will have) util modules
|
|
182
182
|
if (filename === UTIL_VERSION_SYNC && !utilSyncApplies(tempDir, targetRoot, types)) {
|
|
183
183
|
trace?.event("copy", "excluded", filename, { reason: "util-modules-absent" });
|
|
184
184
|
continue;
|
|
@@ -188,7 +188,7 @@ export function copyWorkflows(context, tempDir, targetRoot = ".", hooks = {}) {
|
|
|
188
188
|
trace?.event("copy", "skipped-unchanged", filename, { group: "common" });
|
|
189
189
|
continue;
|
|
190
190
|
}
|
|
191
|
-
//
|
|
191
|
+
// Never touched by the user, only the template changed — bring it up to date without asking (as before).
|
|
192
192
|
if (commonClass.newFiles.includes(filename) && skipNew(commonDir, filename, "common")) continue;
|
|
193
193
|
if (commonClass.newFiles.includes(filename) || commonClass.upstream.includes(filename)) {
|
|
194
194
|
copyFileSync(join(commonDir, filename), join(workflowsDir, filename));
|
|
@@ -198,38 +198,38 @@ export function copyWorkflows(context, tempDir, targetRoot = ".", hooks = {}) {
|
|
|
198
198
|
filename, { group: "common" });
|
|
199
199
|
continue;
|
|
200
200
|
}
|
|
201
|
-
//
|
|
201
|
+
// From here on, changed — "current template render ≠ installed copy". It splits two ways.
|
|
202
202
|
const dst = join(workflowsDir, filename);
|
|
203
203
|
const modified = isUserModified(baseline, filename, readFileSync(dst, "utf8"));
|
|
204
204
|
if (modified === null) {
|
|
205
|
-
//
|
|
206
|
-
//
|
|
207
|
-
//
|
|
205
|
+
// Cannot decide (no reference point = existing integrated repo). common's old contract is "always update to latest",
|
|
206
|
+
// so skipping here would leave existing repos without updates forever. Keep the contract but leave a way
|
|
207
|
+
// back — a .bak before overwriting. (#560: even common/deploy left a .bak, only the main body did not)
|
|
208
208
|
renameSync(dst, dst + ".bak");
|
|
209
209
|
copyFileSync(join(commonDir, filename), dst);
|
|
210
210
|
counters.copied++;
|
|
211
211
|
counters.copiedFiles.push(filename);
|
|
212
212
|
trace?.event("copy", "replaced-bak", filename, { group: "common", reason: "baseline-absent" });
|
|
213
|
-
counters.replacedBak.push(filename); // #673 —
|
|
213
|
+
counters.replacedBak.push(filename); // #673 — show on screen that a possibly edited file was replaced
|
|
214
214
|
continue;
|
|
215
215
|
}
|
|
216
|
-
//
|
|
216
|
+
// A file confirmed as touched by the user — handled by the decision (kept if unset).
|
|
217
217
|
applyDecision(decisions.get(filename), commonDir, workflowsDir, filename, counters, trace, "common");
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
-
// (2~4)
|
|
221
|
+
// (2~4) per type
|
|
222
222
|
for (const type of types) {
|
|
223
223
|
const asks = new Map();
|
|
224
224
|
copyWorkflowsForType(type, projectTypesDir, workflowsDir, { deployTarget, publishTargets, ...context, envOptsFor, collectAsks: asks, decisions, trace, baseline }, counters);
|
|
225
225
|
if (asks.size) deployValues.set(type, asks);
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
-
// (4.5~5)
|
|
229
|
-
//
|
|
230
|
-
// bak-replace:
|
|
231
|
-
// new-only :
|
|
232
|
-
//
|
|
228
|
+
// (4.5~5) optional folders under common/ — deploy/<target>, pr-summary, projects-sync, secret-backup.
|
|
229
|
+
// Which folders are on is decided in one place, workflow-groups.js (#851). Orphan detection uses the same table.
|
|
230
|
+
// bak-replace: skip if identical to the template, else keep a .bak and replace.
|
|
231
|
+
// new-only : leave alone if it exists. Fill in the repo name only on a fresh install (#729 — with a fixed value,
|
|
232
|
+
// every project would overwrite secrets in the same server folder).
|
|
233
233
|
for (const group of commonOptionalGroups(commonDir, { includeSecretBackup, aiPrSummary, projectsSync, deployTarget })) {
|
|
234
234
|
const groupDir = join(commonDir, group.dir);
|
|
235
235
|
if (!group.enabled || !exists(groupDir)) continue;
|
|
@@ -266,8 +266,8 @@ export function copyWorkflows(context, tempDir, targetRoot = ".", hooks = {}) {
|
|
|
266
266
|
}
|
|
267
267
|
}
|
|
268
268
|
|
|
269
|
-
// (6)
|
|
270
|
-
// isUnchanged
|
|
269
|
+
// (6) Branch substitution post-pass (#477) — applied to copied files only for a non-standard branch strategy or the CI minutes saver (#1114).
|
|
270
|
+
// The isUnchanged virtual comparison uses the same branches, so the next update has no recopy churn.
|
|
271
271
|
if (branches.defaultBranch !== "main" || branches.deployBranch !== "develop" || branches.deployTriggerBranch || branches.ciMinutesSaver) {
|
|
272
272
|
for (const f of counters.copiedFiles) {
|
|
273
273
|
const p = join(workflowsDir, f);
|
|
@@ -281,16 +281,16 @@ export function copyWorkflows(context, tempDir, targetRoot = ".", hooks = {}) {
|
|
|
281
281
|
}
|
|
282
282
|
}
|
|
283
283
|
|
|
284
|
-
// (7)
|
|
285
|
-
//
|
|
286
|
-
//
|
|
284
|
+
// (7) Record the reference point (#557) — the basis for the next update to tell "who changed it".
|
|
285
|
+
// Update installed only for files actually written this time. Recording kept (skipped) files as if we wrote them
|
|
286
|
+
// would silently overwrite user edits on the next update.
|
|
287
287
|
recordBaseline(workflowsDir, targetRoot, counters, baseline, context.templateVersion, context.now, trace);
|
|
288
288
|
|
|
289
289
|
return counters;
|
|
290
290
|
}
|
|
291
291
|
|
|
292
|
-
//
|
|
293
|
-
//
|
|
292
|
+
// Keep the disk content right after install as the reference point. Failure does not block the integration —
|
|
293
|
+
// without a reference point, the next update just falls back to the old 2-way check.
|
|
294
294
|
function recordBaseline(workflowsDir, targetRoot, counters, previous, templateVersion, now, trace = null) {
|
|
295
295
|
try {
|
|
296
296
|
const entries = new Map();
|
|
@@ -298,10 +298,10 @@ function recordBaseline(workflowsDir, targetRoot, counters, previous, templateVe
|
|
|
298
298
|
const p = join(workflowsDir, f);
|
|
299
299
|
if (!existsSync(p)) continue;
|
|
300
300
|
const content = readFileSync(p, "utf8");
|
|
301
|
-
//
|
|
301
|
+
// The final disk content after substitution is both what we wrote and the render result at this point.
|
|
302
302
|
entries.set(f, { installed: sha256(content), rendered: sha256(content) });
|
|
303
303
|
}
|
|
304
|
-
if (entries.size === 0 && previous) return; //
|
|
304
|
+
if (entries.size === 0 && previous) return; // Nothing newly written — leave the existing reference point alone
|
|
305
305
|
trace?.event("baseline", "recorded", "", { files: entries.size, hadPrevious: !!previous });
|
|
306
306
|
writeBaseline(targetRoot, {
|
|
307
307
|
templateVersion: templateVersion || "unknown",
|
|
@@ -310,18 +310,18 @@ function recordBaseline(workflowsDir, targetRoot, counters, previous, templateVe
|
|
|
310
310
|
previous,
|
|
311
311
|
});
|
|
312
312
|
} catch (e) {
|
|
313
|
-
//
|
|
313
|
+
// Failing to record the reference point is not an integration failure
|
|
314
314
|
trace?.event("baseline", "baseline-failed", "", { message: e?.message || String(e) });
|
|
315
315
|
}
|
|
316
316
|
}
|
|
317
317
|
|
|
318
|
-
// changed(
|
|
319
|
-
// 'skip'(
|
|
318
|
+
// Handle one changed file (exists and content changed) by decision (3 choices: backup and replace, template copy, keep).
|
|
319
|
+
// 'skip' (default): keep existing. 'backup': existing → .bak then replace. 'template': keep existing + new version as .template.yaml.
|
|
320
320
|
function applyDecision(decision, srcDir, workflowsDir, filename, counters, trace = null, type = "") {
|
|
321
321
|
const src = join(srcDir, filename);
|
|
322
322
|
const dst = join(workflowsDir, filename);
|
|
323
323
|
if (decision === "backup") {
|
|
324
|
-
//
|
|
324
|
+
// Backup and replace: back up the existing file as .bak, then replace with the new version
|
|
325
325
|
renameSync(dst, dst + ".bak");
|
|
326
326
|
copyFileSync(src, dst);
|
|
327
327
|
counters.copied++;
|
|
@@ -330,15 +330,15 @@ function applyDecision(decision, srcDir, workflowsDir, filename, counters, trace
|
|
|
330
330
|
return;
|
|
331
331
|
}
|
|
332
332
|
if (decision === "template") {
|
|
333
|
-
//
|
|
333
|
+
// Template copy: `<name>.template.yaml` — strips only .yaml (.yml stays and the suffix is appended)
|
|
334
334
|
const templateName = (filename.endsWith(".yaml") ? filename.slice(0, -".yaml".length) : filename) + ".template.yaml";
|
|
335
|
-
copyFileSync(src, join(workflowsDir, templateName)); //
|
|
335
|
+
copyFileSync(src, join(workflowsDir, templateName)); // Overwrites an existing .template.yaml
|
|
336
336
|
counters.templateAdded++;
|
|
337
337
|
trace?.event("copy", "template-added", templateName, { original: filename });
|
|
338
338
|
return;
|
|
339
339
|
}
|
|
340
|
-
counters.skipped++; // 'skip'
|
|
341
|
-
// #654 —
|
|
340
|
+
counters.skipped++; // 'skip'/unset/ESC → keep existing (force default)
|
|
341
|
+
// #654 — leave the new template in incoming and record diff line counts in detail
|
|
342
342
|
const inc = counters.onSkip?.(srcDir, filename, type) ?? {};
|
|
343
343
|
trace?.event("copy", "skipped-conflict", filename, {
|
|
344
344
|
decision: decision ?? "skip", note: "kept the user-modified file — candidate for merge review",
|
|
@@ -346,19 +346,19 @@ function applyDecision(decision, srcDir, workflowsDir, filename, counters, trace
|
|
|
346
346
|
});
|
|
347
347
|
}
|
|
348
348
|
|
|
349
|
-
//
|
|
350
|
-
//
|
|
349
|
+
// List only changed (conflict) files in the target workflow directory — used by the wizard (commands/interactive.js).
|
|
350
|
+
// Must use the same classify rules as copyWorkflows so the decision Map matches the real targets 1:1.
|
|
351
351
|
export function listWorkflowConflicts(context, tempDir, targetRoot = ".") {
|
|
352
352
|
const { types = [], paths = new Map(), deployTarget = "docker-ssh", repoName = "", resolvers = {}, branch = "", deployBranch = "", deployTriggerBranch = "", ciMinutesSaver = false } = context;
|
|
353
353
|
const workflowsDir = join(targetRoot, PATHS.workflowsDir);
|
|
354
|
-
//
|
|
354
|
+
// Install-time reference point (#557) — null if missing, and classify falls back to the old 2-way check.
|
|
355
355
|
const baseline = readBaseline(targetRoot);
|
|
356
356
|
const projectTypesDir = join(tempDir, PATHS.workflowsDir, PATHS.projectTypesDir);
|
|
357
|
-
const conflicts = []; // [{ filename, type }] —
|
|
358
|
-
const branches = { defaultBranch: branch || "main", deployBranch: deployBranch || "develop", deployTriggerBranch: deployTriggerBranch || "", ciMinutesSaver: !!ciMinutesSaver }; // #477 —
|
|
357
|
+
const conflicts = []; // [{ filename, type }] — same order as the engine (common → type loop → server-deploy)
|
|
358
|
+
const branches = { defaultBranch: branch || "main", deployBranch: deployBranch || "develop", deployTriggerBranch: deployTriggerBranch || "", ciMinutesSaver: !!ciMinutesSaver }; // #477 — same rules as the engine
|
|
359
359
|
|
|
360
|
-
// common (#560) —
|
|
361
|
-
//
|
|
360
|
+
// common (#560) — only files "confirmed" as touched by the user are asked about.
|
|
361
|
+
// Files that cannot be decided (no reference point) are not asked; the engine leaves a .bak and overwrites them.
|
|
362
362
|
const commonDir = join(projectTypesDir, "common");
|
|
363
363
|
if (exists(commonDir)) {
|
|
364
364
|
const commonEnv = { type: "common", projectPath: ".", repoName, resolvers, branches };
|
|
@@ -388,30 +388,30 @@ function copyWorkflowsForType(type, projectTypesDir, workflowsDir, ctx, counters
|
|
|
388
388
|
const typeDir = join(projectTypesDir, type);
|
|
389
389
|
const envOpts = envOptsFor(type);
|
|
390
390
|
let unchangedNames = [];
|
|
391
|
-
//
|
|
392
|
-
//
|
|
391
|
+
// Env values of the installed copy before the upstream update (found while investigating #810). When reinstalling a file where only the template changed,
|
|
392
|
+
// it was re-substituted with defaults, silently turning user choices (JAVA_VERSION 17, etc.) back to 21.
|
|
393
393
|
const carried = new Map(); // Map<filename, Map<key,value>>
|
|
394
394
|
const upstreamCopy = (srcDir, f, group) => {
|
|
395
395
|
const dst = join(workflowsDir, f);
|
|
396
|
-
try { carried.set(f, extractEnvValues(readFileSync(dst, "utf8"))); } catch { /*
|
|
396
|
+
try { carried.set(f, extractEnvValues(readFileSync(dst, "utf8"))); } catch { /* Read failed — use defaults */ }
|
|
397
397
|
copyFileSync(join(srcDir, f), dst);
|
|
398
398
|
counters.copied++; counters.copiedFiles.push(f);
|
|
399
399
|
trace?.event("copy", "upstream-updated", f, { group, reason: "baseline-match", carried: carried.get(f)?.size ?? 0 });
|
|
400
400
|
};
|
|
401
401
|
|
|
402
|
-
//
|
|
402
|
+
// Per-type workflows (direct children)
|
|
403
403
|
if (exists(typeDir)) {
|
|
404
404
|
const { newFiles, unchanged, changed, upstream } = classify(typeDir, workflowsDir, envOpts, baseline);
|
|
405
405
|
unchangedNames = unchanged.slice();
|
|
406
406
|
for (const f of unchanged) { counters.skipped++; trace?.event("copy", "skipped-unchanged", f, { group: type }); }
|
|
407
407
|
for (const f of newFiles) { if (counters.skipNew(typeDir, f, type)) continue; copyFileSync(join(typeDir, f), join(workflowsDir, f)); counters.copied++; counters.copiedFiles.push(f); trace?.event("copy", "copied", f, { group: type }); }
|
|
408
|
-
// upstream(#557):
|
|
408
|
+
// upstream (#557): not touched by the user, only the template changed — bring it up to date without asking.
|
|
409
409
|
for (const f of upstream) upstreamCopy(typeDir, f, type);
|
|
410
|
-
// changed:
|
|
410
|
+
// changed: handled by the decision Map (unset = skip → same as the current force behavior)
|
|
411
411
|
for (const f of changed) applyDecision(decisions.get(f), typeDir, workflowsDir, f, counters, trace, type);
|
|
412
412
|
}
|
|
413
413
|
|
|
414
|
-
// server-deploy — deploy=docker-ssh
|
|
414
|
+
// server-deploy — included only with deploy=docker-ssh (#439)
|
|
415
415
|
const serverDeployDir = join(typeDir, SERVER_DEPLOY_DIR);
|
|
416
416
|
if (exists(serverDeployDir) && serverDeployEnabled(deployTarget)) {
|
|
417
417
|
const { newFiles, unchanged, changed, upstream } = classify(serverDeployDir, workflowsDir, envOpts, baseline);
|
|
@@ -421,7 +421,7 @@ function copyWorkflowsForType(type, projectTypesDir, workflowsDir, ctx, counters
|
|
|
421
421
|
for (const f of changed) applyDecision(decisions.get(f), serverDeployDir, workflowsDir, f, counters, trace, type);
|
|
422
422
|
}
|
|
423
423
|
|
|
424
|
-
// publish/<target> (opt-in — #439 publish
|
|
424
|
+
// publish/<target> (opt-in — #439 publish axis. The type is only the file location, not a gate)
|
|
425
425
|
const pubDirs = [];
|
|
426
426
|
for (const target of PUBLISH_TARGETS) {
|
|
427
427
|
const pubDir = join(typeDir, "publish", target);
|
|
@@ -447,20 +447,20 @@ function copyWorkflowsForType(type, projectTypesDir, workflowsDir, ctx, counters
|
|
|
447
447
|
}
|
|
448
448
|
}
|
|
449
449
|
|
|
450
|
-
// env
|
|
450
|
+
// env substitution — only files copied from this type's source directories that exist and are not unchanged
|
|
451
451
|
for (const srcDir of [typeDir, serverDeployDir, ...pubDirs]) {
|
|
452
452
|
if (!exists(srcDir)) continue;
|
|
453
453
|
for (const filename of listYamlFiles(srcDir)) {
|
|
454
454
|
const target = join(workflowsDir, filename);
|
|
455
|
-
if (!existsSync(target)) continue; //
|
|
456
|
-
if (unchangedNames.includes(filename)) continue; // unchanged
|
|
455
|
+
if (!existsSync(target)) continue; // Skip skipped files
|
|
456
|
+
if (unchangedNames.includes(filename)) continue; // Skip unchanged
|
|
457
457
|
const prev = carried.get(filename);
|
|
458
458
|
if (prev && prev.size) {
|
|
459
|
-
//
|
|
459
|
+
// Overlay values explicitly chosen in this run on top of carried-over values (explicit choice wins)
|
|
460
460
|
const values = new Map([...prev, ...(envOpts.useDefaults ? [] : envOpts.values)]);
|
|
461
461
|
configureEnv(target, filename, { ...envOpts, values, useDefaults: false, collectAsks, trace });
|
|
462
462
|
} else {
|
|
463
|
-
configureEnv(target, filename, { ...envOpts, collectAsks, trace }); // env
|
|
463
|
+
configureEnv(target, filename, { ...envOpts, collectAsks, trace }); // includes env plan values/useDefaults
|
|
464
464
|
}
|
|
465
465
|
}
|
|
466
466
|
}
|
package/src/core/detect-fs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
//
|
|
2
|
-
// SP2-A detect.js
|
|
1
|
+
// Project detection on the real filesystem.
|
|
2
|
+
// Drives the SP2-A detect.js pure functions with fs/git.
|
|
3
3
|
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
4
4
|
import { join, basename } from "node:path";
|
|
5
5
|
import { execFileSync } from "node:child_process";
|
|
@@ -18,11 +18,11 @@ function gitOut(root, args) {
|
|
|
18
18
|
} catch { return ""; }
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
//
|
|
21
|
+
// File list for the extension scan (depth≤3, vendor folders pruned).
|
|
22
22
|
const SCAN_PRUNE = new Set([
|
|
23
23
|
"node_modules", ".git", "build", "dist", ".dart_tool",
|
|
24
24
|
"android", "ios", ".gradle", "venv", ".venv", "__pycache__",
|
|
25
|
-
//
|
|
25
|
+
// Keeps the template's own .github/scripts/*.py from being misdetected as python (#671)
|
|
26
26
|
".github",
|
|
27
27
|
]);
|
|
28
28
|
export function listScanFiles(root, maxDepth = 3) {
|
|
@@ -44,27 +44,27 @@ export function listScanFiles(root, maxDepth = 3) {
|
|
|
44
44
|
return files;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
//
|
|
48
|
-
//
|
|
47
|
+
// Type detection — version.yml project_types first (source of truth), else a marker scan.
|
|
48
|
+
// With no markers at all (basic fallback), a secondary recommendation from extension frequency (#458).
|
|
49
49
|
export function detectTypes(root) {
|
|
50
50
|
const vy = join(root, "version.yml");
|
|
51
51
|
if (existsSync(vy)) {
|
|
52
52
|
const { types } = parseExisting(readFileSync(vy, "utf8"));
|
|
53
|
-
if (types.length) return types; // basic
|
|
54
|
-
// v4.1.0
|
|
55
|
-
//
|
|
53
|
+
if (types.length) return types; // Includes basic; use as is when explicit
|
|
54
|
+
// Singular project_type key from before v4.1.0 (#718) — restore the explicit value even without markers.
|
|
55
|
+
// Otherwise a repo without markers drops to basic and the existing type's workflows are orphaned.
|
|
56
56
|
const legacy = (convertLegacySingularType(readFileSync(vy, "utf8")) || "").match(/^project_types: \["([a-z-]+)"\]/m);
|
|
57
57
|
if (legacy && VALID_TYPES.includes(legacy[1])) return [legacy[1]];
|
|
58
58
|
}
|
|
59
59
|
const byMarkers = detectTypesFromMarkers({ has: hasFile(root), read: readFile(root) });
|
|
60
60
|
if (byMarkers.length === 1 && byMarkers[0] === "basic") {
|
|
61
61
|
const scanned = suggestTypesByExtScan(listScanFiles(root));
|
|
62
|
-
if (scanned.length) return scanned; //
|
|
62
|
+
if (scanned.length) return scanned; // Recommendation — the user confirms it in the wizard's confirm/edit loop
|
|
63
63
|
}
|
|
64
64
|
return byMarkers;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
//
|
|
67
|
+
// Version detection. jq availability is judged by the command existing.
|
|
68
68
|
export function detectVersion(root, { hasJq } = {}) {
|
|
69
69
|
const read = readFile(root);
|
|
70
70
|
const readJson = (rel) => { const c = read(rel); try { return c ? JSON.parse(c) : null; } catch { return null; } };
|
|
@@ -73,20 +73,20 @@ export function detectVersion(root, { hasJq } = {}) {
|
|
|
73
73
|
return detectVersionFromFiles({ read, readJson, hasJq: jq, gitTag });
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
//
|
|
76
|
+
// Default branch detection — symbolic-ref → remote show → main.
|
|
77
77
|
export function detectDefaultBranch(root) {
|
|
78
78
|
let b = gitOut(root, ["symbolic-ref", "refs/remotes/origin/HEAD"]);
|
|
79
79
|
if (b) return b.replace(/^refs\/remotes\/origin\//, "");
|
|
80
80
|
const show = gitOut(root, ["remote", "show", "origin"]);
|
|
81
81
|
const m = show.match(/HEAD branch:\s*(\S+)/);
|
|
82
82
|
if (m) return m[1];
|
|
83
|
-
//
|
|
83
|
+
// Local repo without origin (#477) — the current HEAD branch is the best guess (fixable in the interactive edit menu)
|
|
84
84
|
const head = gitOut(root, ["branch", "--show-current"]);
|
|
85
85
|
if (head) return head;
|
|
86
86
|
return "main";
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
//
|
|
89
|
+
// Repo name — last segment of git remote get-url origin, folder name on failure.
|
|
90
90
|
export function detectRepoName(root) {
|
|
91
91
|
const url = gitOut(root, ["remote", "get-url", "origin"]);
|
|
92
92
|
if (url) {
|
|
@@ -103,18 +103,18 @@ function hasCommand(cmd) {
|
|
|
103
103
|
} catch { return false; }
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
// Spring application*.yml
|
|
107
|
-
// find {base} -path "*/src/main/resources/application*.yml" | head -1
|
|
108
|
-
//
|
|
106
|
+
// Find Spring application*.yml
|
|
107
|
+
// fs recursive version of find {base} -path "*/src/main/resources/application*.yml" | head -1.
|
|
108
|
+
// Returns a path relative to root (e.g. "server/src/main/resources/application.yml") or "".
|
|
109
109
|
export function findSpringAppYml(root, base = ".") {
|
|
110
110
|
const startRel = base === "." ? "" : base;
|
|
111
111
|
const PRUNE = new Set(["node_modules", ".git", "build", ".gradle", "target", ".idea"]);
|
|
112
112
|
let hit = "";
|
|
113
113
|
const walk = (rel, depth) => {
|
|
114
|
-
if (hit || depth > 8) return; // head -1
|
|
114
|
+
if (hit || depth > 8) return; // Equivalent to head -1 — stop at the first match
|
|
115
115
|
let entries;
|
|
116
116
|
try { entries = readdirSync(join(root, rel), { withFileTypes: true }); } catch { return; }
|
|
117
|
-
//
|
|
117
|
+
// Sort to make traversal order deterministic (removes platform differences in find order)
|
|
118
118
|
for (const e of entries.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
119
119
|
if (hit) return;
|
|
120
120
|
const childRel = rel ? `${rel}/${e.name}` : e.name;
|
|
@@ -130,8 +130,8 @@ export function findSpringAppYml(root, base = ".") {
|
|
|
130
130
|
return hit;
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
//
|
|
134
|
-
// paths: Map<type, path> (
|
|
133
|
+
// Builds the real set of 4 resolvers — shared by index and interactive.
|
|
134
|
+
// paths: Map<type, path> (monorepo paths).
|
|
135
135
|
export function makeResolvers(root, repoName, paths) {
|
|
136
136
|
const springBase = (t) => paths.get(t || "spring") || paths.get("spring") || ".";
|
|
137
137
|
return {
|