@webpieces/pr-gate 0.4.984 → 0.4.986
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/package.json +8 -8
- package/src/scripts/commands/build-push-dev-command.d.ts +79 -0
- package/src/scripts/commands/build-push-dev-command.js +184 -0
- package/src/scripts/commands/build-push-dev-command.js.map +1 -0
- package/src/scripts/commands/finish-push-dev-command.d.ts +73 -17
- package/src/scripts/commands/finish-push-dev-command.js +187 -31
- package/src/scripts/commands/finish-push-dev-command.js.map +1 -1
- package/src/scripts/commands/start-push-dev-command.d.ts +43 -0
- package/src/scripts/commands/start-push-dev-command.js +111 -0
- package/src/scripts/commands/start-push-dev-command.js.map +1 -0
- package/src/scripts/pr-gate-app.d.ts +18 -18
- package/src/scripts/pr-gate-app.js +27 -26
- package/src/scripts/pr-gate-app.js.map +1 -1
- package/src/scripts/pr-gate-cli-app.d.ts +2 -2
- package/src/scripts/pr-gate-cli-app.js +20 -29
- package/src/scripts/pr-gate-cli-app.js.map +1 -1
- package/src/scripts/workflow/build-gate-log.d.ts +1 -0
- package/src/scripts/workflow/build-gate-log.js +7 -3
- package/src/scripts/workflow/build-gate-log.js.map +1 -1
- package/src/scripts/workflow/dev-build.d.ts +8 -5
- package/src/scripts/workflow/dev-build.js +13 -9
- package/src/scripts/workflow/dev-build.js.map +1 -1
- package/src/scripts/workflow/dev-copy-on-main.d.ts +6 -4
- package/src/scripts/workflow/dev-copy-on-main.js +8 -6
- package/src/scripts/workflow/dev-copy-on-main.js.map +1 -1
- package/src/scripts/workflow/dev-deploy-refs.d.ts +4 -17
- package/src/scripts/workflow/dev-deploy-refs.js +5 -21
- package/src/scripts/workflow/dev-deploy-refs.js.map +1 -1
- package/src/scripts/workflow/dev-resolve-runner.d.ts +56 -71
- package/src/scripts/workflow/dev-resolve-runner.js +156 -182
- package/src/scripts/workflow/dev-resolve-runner.js.map +1 -1
- package/src/scripts/workflow/landed-copy-resolver.d.ts +56 -0
- package/src/scripts/workflow/landed-copy-resolver.js +141 -0
- package/src/scripts/workflow/landed-copy-resolver.js.map +1 -0
- package/src/scripts/workflow/main-freshness.d.ts +16 -0
- package/src/scripts/workflow/main-freshness.js +33 -0
- package/src/scripts/workflow/main-freshness.js.map +1 -0
- package/src/scripts/workflow/push-dev-state.d.ts +12 -35
- package/src/scripts/workflow/push-dev-state.js +31 -62
- package/src/scripts/workflow/push-dev-state.js.map +1 -1
- package/src/scripts/workflow/verified-dev-copy.d.ts +46 -0
- package/src/scripts/workflow/verified-dev-copy.js +89 -0
- package/src/scripts/workflow/verified-dev-copy.js.map +1 -0
- package/src/scripts/{wp-build-dev.js → wp-build-push-dev.js} +2 -2
- package/src/scripts/wp-build-push-dev.js.map +1 -0
- package/src/scripts/{wp-push-dev.js → wp-start-push-dev.js} +2 -2
- package/src/scripts/wp-start-push-dev.js.map +1 -0
- package/src/scripts/commands/build-dev-command.d.ts +0 -27
- package/src/scripts/commands/build-dev-command.js +0 -99
- package/src/scripts/commands/build-dev-command.js.map +0 -1
- package/src/scripts/commands/push-dev-command.d.ts +0 -140
- package/src/scripts/commands/push-dev-command.js +0 -356
- package/src/scripts/commands/push-dev-command.js.map +0 -1
- package/src/scripts/wp-build-dev.js.map +0 -1
- package/src/scripts/wp-push-dev.js.map +0 -1
- /package/src/scripts/{wp-build-dev.d.ts → wp-build-push-dev.d.ts} +0 -0
- /package/src/scripts/{wp-push-dev.d.ts → wp-start-push-dev.d.ts} +0 -0
|
@@ -3,187 +3,180 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DevResolveRunner = exports.RESOLUTION_SUBJECT = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const rules_config_1 = require("@webpieces/rules-config");
|
|
6
|
+
const tooling_common_1 = require("@webpieces/tooling-common");
|
|
6
7
|
const to_error_1 = require("@webpieces/tooling-common/to-error");
|
|
7
8
|
const inversify_1 = require("inversify");
|
|
8
9
|
const git_exec_1 = require("./git-exec");
|
|
9
10
|
const dev_deploy_refs_1 = require("./dev-deploy-refs");
|
|
10
11
|
const push_dev_state_1 = require("./push-dev-state");
|
|
11
|
-
const dev_deploy_watch_hints_1 = require("./dev-deploy-watch-hints");
|
|
12
12
|
const dev_build_1 = require("./dev-build");
|
|
13
|
+
const verified_dev_copy_1 = require("./verified-dev-copy");
|
|
14
|
+
const landed_copy_resolver_1 = require("./landed-copy-resolver");
|
|
13
15
|
const SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n';
|
|
14
16
|
/**
|
|
15
17
|
* The subject prefix of the ONE commit this flow writes onto a copy: the recorded conflict resolution.
|
|
16
|
-
* The clobber guard reads it — a remote-only commit with this subject is re-derived by the next publish's
|
|
17
|
-
* check against dev, so replacing it destroys nothing; any other remote-only commit is somebody's work.
|
|
18
18
|
*/
|
|
19
19
|
exports.RESOLUTION_SUBJECT = 'Dev-deploy: conflict resolution for';
|
|
20
20
|
/**
|
|
21
|
-
* The
|
|
22
|
-
*
|
|
21
|
+
* The engine behind `wp-build-push-dev`'s check against dev (#1403): merge `origin/<devBranch>` into a
|
|
22
|
+
* THROWAWAY branch, take the publisher's side on conflicts caused only by copies already on main (#1405),
|
|
23
|
+
* stop on any other conflict, `pnpm install`, run the dev build (compile + tests, no code rules), and record
|
|
24
|
+
* the copy `wp-finish-push-dev` publishes.
|
|
23
25
|
*
|
|
24
|
-
* ONE class owns every git WRITE
|
|
26
|
+
* ONE class owns every git WRITE of the check, and that is a hard requirement rather than tidiness:
|
|
25
27
|
* `redirect-how-to-merge-main` blocks `git merge` in every form INCLUDING `--continue`, and
|
|
26
|
-
* `
|
|
28
|
+
* `merge-in-progress-guard` blocks `git commit`. So an AI cannot be told "now run `git commit`" or
|
|
27
29
|
* "`git merge --continue`" — those instructions are unrunnable by the only party reading them. The command
|
|
28
|
-
* owns the
|
|
29
|
-
*
|
|
30
|
+
* owns the merge and the commits (as child processes the hooks never see); the AI's entire job is editing
|
|
31
|
+
* the conflicted files and `git add`-ing them, neither of which is blocked.
|
|
32
|
+
*
|
|
33
|
+
* It NEVER writes to the feature branch: every merge lands on a throwaway that is deleted at the end, so no
|
|
34
|
+
* other developer's commits can reach the PR head even if the check is abandoned halfway.
|
|
30
35
|
*/
|
|
31
36
|
let DevResolveRunner = class DevResolveRunner {
|
|
32
37
|
gitExec;
|
|
33
38
|
refs;
|
|
34
39
|
store;
|
|
35
|
-
|
|
40
|
+
verified;
|
|
36
41
|
devBuild;
|
|
37
|
-
|
|
42
|
+
processes;
|
|
43
|
+
landedCopies;
|
|
44
|
+
constructor(gitExec, refs, store, verified, devBuild, processes, landedCopies) {
|
|
38
45
|
this.gitExec = gitExec;
|
|
39
46
|
this.refs = refs;
|
|
40
47
|
this.store = store;
|
|
41
|
-
this.
|
|
48
|
+
this.verified = verified;
|
|
42
49
|
this.devBuild = devBuild;
|
|
50
|
+
this.processes = processes;
|
|
51
|
+
this.landedCopies = landedCopies;
|
|
43
52
|
}
|
|
44
53
|
/**
|
|
45
|
-
* Start
|
|
46
|
-
*
|
|
47
|
-
* The checkout is `-B <tmp> <base>` and NEVER the feature branch, which is the cardinal constraint made
|
|
48
|
-
* mechanical — every merge below lands on a branch that is deleted at the end, so no other developer's
|
|
49
|
-
* commits can reach the PR head even if the resolve is abandoned halfway.
|
|
50
|
-
*
|
|
51
|
-
* `base` differs between the callers and the difference IS the semantics. A plain publish starts at the
|
|
52
|
-
* LOCAL HEAD and merges `origin/<devBranch>` in (does this copy merge and build against what is already
|
|
53
|
-
* on dev?). `--resolve` starts at the published copy and merges the other copies in (compose what CI
|
|
54
|
-
* will build). `--rebase-resolution` starts at the LOCAL HEAD and merges the published copy in (replay
|
|
55
|
-
* an existing resolution on top of the new commits, instead of force-pushing over it). What is finally
|
|
56
|
-
* PUBLISHED is the state's DevResolveMode's decision — see finalize.
|
|
57
|
-
*
|
|
58
|
-
* `fetchRefs` is passed separately from the queue because `--rebase-resolution` merges a ref that is
|
|
59
|
-
* also its push destination, so "everything to fetch" and "everything to merge" are not the same list.
|
|
54
|
+
* Start the check: park on a throwaway branch at the feature head, merge `origin/<devBranch>` into it,
|
|
55
|
+
* and either halt on a conflict or go straight on to install, build and record.
|
|
60
56
|
*/
|
|
61
|
-
async start(repoRoot,
|
|
62
|
-
await this.refs.fetchCopies(repoRoot,
|
|
63
|
-
// Pinned to a SHA
|
|
64
|
-
//
|
|
65
|
-
state.baseSha = await this.refs.headSha(repoRoot,
|
|
57
|
+
async start(repoRoot, cfg, state) {
|
|
58
|
+
await this.refs.fetchCopies(repoRoot, [state.devBranch]);
|
|
59
|
+
// Pinned to a SHA: the resolution is recorded on top of exactly what was merged, and stage ③
|
|
60
|
+
// refuses to publish when the feature branch has moved since.
|
|
61
|
+
state.baseSha = await this.refs.headSha(repoRoot, 'HEAD');
|
|
66
62
|
this.store.write(repoRoot, state);
|
|
67
|
-
await this.gitExec.runGitChecked(['-C', repoRoot, 'checkout', '-B', state.tmpBranch,
|
|
68
|
-
await this.
|
|
63
|
+
await this.gitExec.runGitChecked(['-C', repoRoot, 'checkout', '-B', state.tmpBranch, 'HEAD'], `Failed to create the throwaway branch ${state.tmpBranch}`);
|
|
64
|
+
const merged = await this.gitExec.tryGit(['-C', repoRoot, 'merge', '--no-ff', '--no-edit', '-m',
|
|
65
|
+
`Dev-deploy: merge ${state.devBranch} into ${state.targetRef}`, `refs/remotes/origin/${state.devBranch}`], repoRoot);
|
|
66
|
+
if (!merged.ok)
|
|
67
|
+
await this.resolveLandedOrHalt(repoRoot, cfg, state, merged);
|
|
68
|
+
process.stdout.write(` ✓ merged origin/${state.devBranch}\n`);
|
|
69
|
+
await this.finish(repoRoot, state);
|
|
69
70
|
}
|
|
70
71
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* fetched an hour ago rehearses a composition CI will not build — the one freshness gap the sibling
|
|
75
|
-
* update flow is still known to have (only its stage ① ever fetches).
|
|
72
|
+
* The merge conflicted. First take the publisher's side on every file whose dev side comes ONLY from
|
|
73
|
+
* copies already on main (#1405, LandedCopyResolver); when that was every conflicted file, commit the
|
|
74
|
+
* merge and carry on. Otherwise halt on what is left — the developer's job, as before.
|
|
76
75
|
*/
|
|
76
|
+
async resolveLandedOrHalt(repoRoot, cfg, state, merged) {
|
|
77
|
+
const conflicted = await this.unmergedPaths(repoRoot);
|
|
78
|
+
if (conflicted.length === 0)
|
|
79
|
+
await this.mergeFailed(repoRoot, state, merged);
|
|
80
|
+
const resolution = await this.landedCopies.resolve(repoRoot, cfg, conflicted);
|
|
81
|
+
if (resolution.remaining.length > 0)
|
|
82
|
+
await this.halt(repoRoot, state, resolution);
|
|
83
|
+
process.stdout.write(this.landedCopies.describe(resolution));
|
|
84
|
+
await this.gitExec.runGitChecked(['-C', repoRoot, 'commit', '--no-edit'], `Failed to commit the merge with origin/${state.devBranch} after resolving the landed copies' conflicts`);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The merge failed WITHOUT leaving a conflicted file (an untracked file in the way, a broken ref, …).
|
|
88
|
+
* There is nothing to resolve, so the checkout goes back to the feature branch and git's own words say why.
|
|
89
|
+
*/
|
|
90
|
+
async mergeFailed(repoRoot, state, merged) {
|
|
91
|
+
await this.restore(repoRoot, state);
|
|
92
|
+
throw new rules_config_1.CliExitError(1, '\n' + SEP + `⛔ Merging origin/${state.devBranch} failed — and nothing conflicted\n` + SEP + '\n'
|
|
93
|
+
+ `git merge exited ${String(merged.status)} without leaving a conflicted file, so there is nothing to resolve.\n`
|
|
94
|
+
+ 'What git said:\n'
|
|
95
|
+
+ `${(merged.stderr + merged.stdout).trim()}\n\n`
|
|
96
|
+
+ `Nothing was built, recorded or published; you are back on \`${state.originalBranch}\`. Fix what git\n`
|
|
97
|
+
+ `reported, then re-run: ${rules_config_1.WP_BUILD_PUSH_DEV}\n`);
|
|
98
|
+
}
|
|
99
|
+
/** Resume after the conflicted files were resolved and `git add`-ed: commit the merge, then finish. */
|
|
77
100
|
async resume(repoRoot, state) {
|
|
78
|
-
await this.assertNoUnmergedPaths(repoRoot
|
|
101
|
+
await this.assertNoUnmergedPaths(repoRoot);
|
|
79
102
|
await this.gitExec.assertNoUntracked(repoRoot);
|
|
80
103
|
await this.gitExec.runGitChecked(['-C', repoRoot, 'add', '-u'], 'Failed to stage the resolved files (git add -u)');
|
|
81
|
-
await this.gitExec.runGitChecked(['-C', repoRoot, 'commit', '--no-edit'], `Failed to commit the resolution of
|
|
82
|
-
process.stdout.write(`✅ Committed the resolution of
|
|
83
|
-
|
|
84
|
-
await this.refs.fetchCopies(repoRoot, state.queue);
|
|
85
|
-
await this.drain(repoRoot, state);
|
|
104
|
+
await this.gitExec.runGitChecked(['-C', repoRoot, 'commit', '--no-edit'], `Failed to commit the resolution of the merge with origin/${state.devBranch}`);
|
|
105
|
+
process.stdout.write(`✅ Committed the resolution of the merge with origin/${state.devBranch}.\n`);
|
|
106
|
+
await this.finish(repoRoot, state);
|
|
86
107
|
}
|
|
87
108
|
/**
|
|
88
|
-
* Throw the whole
|
|
89
|
-
* throwaway branch and the state file. Nothing
|
|
109
|
+
* Throw the whole check away: undo any halted merge, go back to the original branch, delete the
|
|
110
|
+
* throwaway branch and the state file. Nothing verified, nothing on the feature branch.
|
|
90
111
|
*/
|
|
91
112
|
async abort(repoRoot, state) {
|
|
92
|
-
// Allowed to fail: there is no merge to abort when the resolve halted between merges, and that is
|
|
93
|
-
// not an error condition — the rest of the teardown must still run.
|
|
94
|
-
await this.gitExec.tryGit(['-C', repoRoot, 'merge', '--abort'], repoRoot);
|
|
95
113
|
await this.restore(repoRoot, state);
|
|
96
|
-
process.stdout.write('\n' + SEP + '🛑 Dev-deploy
|
|
114
|
+
process.stdout.write('\n' + SEP + '🛑 Dev-deploy check aborted\n' + SEP + '\n'
|
|
97
115
|
+ `You are back on \`${state.originalBranch}\`; \`${state.tmpBranch}\` and the state file are gone.\n`
|
|
98
|
-
+ `
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Merge queued refs until one conflicts (HALT, hand the tree over) or the queue empties (PUBLISH).
|
|
102
|
-
*
|
|
103
|
-
* A LATER ref can conflict too, which is why this is a loop resumed from a state file rather than a
|
|
104
|
-
* single pass: `wp-finish-push-dev` can legitimately stop again on the next ref in the queue.
|
|
105
|
-
*/
|
|
106
|
-
async drain(repoRoot, state) {
|
|
107
|
-
while (state.queue.length > 0) {
|
|
108
|
-
const ref = state.queue[0];
|
|
109
|
-
state.queue = state.queue.slice(1);
|
|
110
|
-
const outcome = await this.gitExec.tryGit(['-C', repoRoot, 'merge', '--no-ff', '--no-edit', '-m',
|
|
111
|
-
`Dev-deploy: merge ${ref} into ${state.targetRef}`, `refs/remotes/origin/${ref}`], repoRoot);
|
|
112
|
-
if (outcome.ok) {
|
|
113
|
-
process.stdout.write(` ✓ merged ${ref}\n`);
|
|
114
|
-
continue;
|
|
115
|
-
}
|
|
116
|
-
state.current = ref;
|
|
117
|
-
await this.halt(repoRoot, state);
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
await this.finalize(repoRoot, state);
|
|
116
|
+
+ `Nothing was published, and your feature branch is untouched.\n`);
|
|
121
117
|
}
|
|
122
118
|
/** Stop with the conflicted files listed and the ONE command that continues. Exit 2 = "your turn". */
|
|
123
|
-
async halt(repoRoot, state) {
|
|
124
|
-
const conflicted =
|
|
119
|
+
async halt(repoRoot, state, landed) {
|
|
120
|
+
const conflicted = landed.remaining;
|
|
125
121
|
// Remembered so the finish records EXACTLY these files as the resolution — and nothing else the
|
|
126
|
-
// merge brought in, which is other developers' work.
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
state.resolvedPaths.push(file);
|
|
122
|
+
// merge brought in, which is other developers' work. Files resolved to the publisher's side
|
|
123
|
+
// automatically are not among them: they hold what the base already has, so there is nothing to record.
|
|
124
|
+
state.resolvedPaths = conflicted;
|
|
130
125
|
this.store.write(repoRoot, state);
|
|
131
|
-
|
|
132
|
-
? `\nStill queued after this one: ${state.queue.join(', ')}\n`
|
|
133
|
-
+ `\`${rules_config_1.WP_FINISH_PUSH_DEV}\` resumes the queue, so it may stop again on a later ref.\n`
|
|
134
|
-
: '';
|
|
135
|
-
throw new rules_config_1.CliExitError(2, '\n' + SEP + `⚠️ CONFLICT merging ${state.current}\n` + SEP + '\n'
|
|
126
|
+
throw new rules_config_1.CliExitError(2, '\n' + SEP + `⚠️ CONFLICT merging origin/${state.devBranch}\n` + SEP + '\n'
|
|
136
127
|
+ `You are on the throwaway branch \`${state.tmpBranch}\` — NOT \`${state.originalBranch}\`. Nothing here\n`
|
|
137
128
|
+ 'can reach your feature branch or your PR, which is exactly why the resolution happens over here.\n\n'
|
|
138
129
|
+ 'Resolve these files (edit until no conflict markers remain, then `git add` each one):\n'
|
|
139
130
|
+ conflicted.map((f) => ` ${f}`).join('\n') + '\n'
|
|
140
|
-
+
|
|
131
|
+
+ this.landedCopies.describe(landed)
|
|
141
132
|
+ '\nThen run ONE of:\n'
|
|
142
|
-
+ ` ${rules_config_1.
|
|
143
|
-
+ ` ${rules_config_1.
|
|
133
|
+
+ ` ${rules_config_1.WP_BUILD_PUSH_DEV} ← commit the resolution, pnpm install, run the dev build\n`
|
|
134
|
+
+ ` ${rules_config_1.WP_BUILD_PUSH_DEV} --abort ← throw it away and go back to \`${state.originalBranch}\`\n\n`
|
|
144
135
|
+ 'Do NOT run `git merge --continue`, `git commit` or `git push` yourself — they are blocked, and\n'
|
|
145
|
-
+ 'the
|
|
136
|
+
+ 'the commands above do them for you.\n');
|
|
146
137
|
}
|
|
147
138
|
/**
|
|
148
|
-
*
|
|
139
|
+
* The merge is complete. Install and build the MERGED tree, then turn the throwaway into the copy and
|
|
140
|
+
* record it for `wp-finish-push-dev`.
|
|
149
141
|
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
* publishes the merge, as it always has.
|
|
142
|
+
* `pnpm install` runs AFTER the merge, never before: other copies already on dev can add workspace
|
|
143
|
+
* packages main does not have yet, so the feature branch's `node_modules` does not link the merged
|
|
144
|
+
* tree (#1403 — a 30-commits-behind branch failed six minutes into its build on exactly that).
|
|
154
145
|
*/
|
|
155
|
-
async
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
process.stdout.write('\n' + SEP + `✅ ${state.targetRef} composes cleanly — nothing to publish\n` + SEP + '\n'
|
|
166
|
-
+ 'Every other copy merged onto it without a conflict, so your CI composes it as it is. The copy\n'
|
|
167
|
-
+ `is unchanged, and you are back on \`${state.originalBranch}\`.\n`);
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
await this.gitExec.runGitChecked(['-C', repoRoot, 'push', ...this.pushSafety(state), 'origin', `${state.tmpBranch}:refs/heads/${state.targetRef}`], `Failed to publish the dev copy ${state.targetRef}`);
|
|
146
|
+
async finish(repoRoot, state) {
|
|
147
|
+
await this.onThrowaway(repoRoot, state, () => this.install(repoRoot, state));
|
|
148
|
+
await this.onThrowaway(repoRoot, state, () => this.devBuild.run(repoRoot, rules_config_1.WP_BUILD_PUSH_DEV));
|
|
149
|
+
// The install may rewrite the lockfile on the throwaway; drop that before the throwaway moves.
|
|
150
|
+
await this.gitExec.runGitChecked(['-C', repoRoot, 'reset', '--hard', 'HEAD'], `Failed to discard what pnpm install changed on ${state.tmpBranch}`);
|
|
151
|
+
await this.recordResolution(repoRoot, state);
|
|
152
|
+
const copySha = await this.refs.headSha(repoRoot, state.tmpBranch);
|
|
153
|
+
await this.gitExec.runGitChecked(['-C', repoRoot, 'update-ref', this.verified.keepRef(state.originalBranch), copySha], `Failed to keep the verified copy ${copySha.slice(0, 8)} reachable`);
|
|
154
|
+
const devSha = await this.refs.headSha(repoRoot, `refs/remotes/origin/${state.devBranch}`);
|
|
155
|
+
this.verified.write(repoRoot, new verified_dev_copy_1.VerifiedDevCopy(state.originalBranch, state.baseSha, copySha, state.targetRef, state.leaseSha, devSha));
|
|
171
156
|
await this.restore(repoRoot, state);
|
|
172
|
-
process.stdout.write(this.
|
|
173
|
-
|
|
157
|
+
process.stdout.write(this.verifiedBanner(state, devSha));
|
|
158
|
+
}
|
|
159
|
+
async install(repoRoot, state) {
|
|
160
|
+
process.stdout.write(`\nRunning pnpm install on the merged throwaway \`${state.tmpBranch}\`.\n`);
|
|
161
|
+
const result = await this.processes.passThrough('pnpm', ['install'], repoRoot);
|
|
162
|
+
if (result.ok)
|
|
163
|
+
return;
|
|
164
|
+
throw new rules_config_1.CliExitError(1, '\n' + SEP + `⛔ pnpm install failed on the merge with origin/${state.devBranch}\n` + SEP + '\n'
|
|
165
|
+
+ `\`pnpm install\` exited ${String(result.code)} on the merged tree (its output is above). No build ran and\n`
|
|
166
|
+
+ `nothing was verified; you are back on \`${state.originalBranch}\`. Fix what it reported, then re-run:\n`
|
|
167
|
+
+ ` ${rules_config_1.WP_BUILD_PUSH_DEV}\n`);
|
|
174
168
|
}
|
|
175
169
|
/**
|
|
176
|
-
* Run
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
170
|
+
* Run one step on the throwaway. On a failure, put the checkout back first — the fix belongs on the
|
|
171
|
+
* feature branch, and a developer left parked on a throwaway would make the next `wp-*` command act on
|
|
172
|
+
* the wrong branch — then let the step's own failure (a build's carries its `FullLog :` pointer) reach
|
|
173
|
+
* the top-level handler unchanged.
|
|
180
174
|
*/
|
|
181
|
-
async
|
|
182
|
-
|
|
183
|
-
// webpieces-disable no-unmanaged-exceptions -- chokepoint: the checkout must be restored whether or not the build passed; the build's own CliExitError is re-thrown unchanged
|
|
175
|
+
async onThrowaway(repoRoot, state, step) {
|
|
176
|
+
// webpieces-disable no-unmanaged-exceptions -- chokepoint: the checkout must be restored whether or not the step passed; the step's own error is re-thrown unchanged
|
|
184
177
|
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
185
178
|
try {
|
|
186
|
-
await
|
|
179
|
+
await step();
|
|
187
180
|
}
|
|
188
181
|
catch (err) {
|
|
189
182
|
const error = (0, to_error_1.toError)(err);
|
|
@@ -192,14 +185,14 @@ let DevResolveRunner = class DevResolveRunner {
|
|
|
192
185
|
}
|
|
193
186
|
}
|
|
194
187
|
/**
|
|
195
|
-
* Turn the throwaway into
|
|
196
|
-
*
|
|
188
|
+
* Turn the throwaway into the copy: the base sha plus, when anything conflicted, ONE commit that sets
|
|
189
|
+
* each resolved file to its resolved content.
|
|
197
190
|
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
191
|
+
* The merge is used for the conflict check and the build only, and is never published. Publishing it
|
|
192
|
+
* would make every other copy an ancestor of this one, so a later `--remove` of that copy would leave
|
|
193
|
+
* its commits on dev through ours. The resolution commit has exactly one parent, the base, so the only
|
|
194
|
+
* thing it can carry of anybody else's work is the text of the hunks that were resolved — content,
|
|
195
|
+
* never history.
|
|
203
196
|
*/
|
|
204
197
|
async recordResolution(repoRoot, state) {
|
|
205
198
|
const merged = await this.refs.headSha(repoRoot, state.tmpBranch);
|
|
@@ -221,60 +214,49 @@ let DevResolveRunner = class DevResolveRunner {
|
|
|
221
214
|
+ 'This commit carries only the files that conflicted and were resolved:\n'
|
|
222
215
|
+ state.resolvedPaths.map((f) => ` ${f}`).join('\n') + '\n'], `Failed to commit the recorded resolution for ${state.targetRef}`);
|
|
223
216
|
}
|
|
224
|
-
/** Back to the original branch; the throwaway and the state file are gone. */
|
|
217
|
+
/** Back to the original branch; any halted merge, the throwaway and the state file are gone. */
|
|
225
218
|
async restore(repoRoot, state) {
|
|
219
|
+
// Only ever on the throwaway: a reset anywhere else could destroy somebody's uncommitted work.
|
|
220
|
+
// Both allowed to fail: there is no merge to abort once it completed, and nothing to reset on a
|
|
221
|
+
// clean tree. Neither is an error — the rest of the teardown must still run.
|
|
222
|
+
if (await this.gitExec.currentBranch(repoRoot) === state.tmpBranch) {
|
|
223
|
+
await this.gitExec.tryGit(['-C', repoRoot, 'merge', '--abort'], repoRoot);
|
|
224
|
+
await this.gitExec.tryGit(['-C', repoRoot, 'reset', '--hard', 'HEAD'], repoRoot);
|
|
225
|
+
}
|
|
226
226
|
await this.gitExec.runGitChecked(['-C', repoRoot, 'checkout', state.originalBranch], `Failed to return to ${state.originalBranch}`);
|
|
227
227
|
await this.gitExec.tryGit(['-C', repoRoot, 'branch', '-D', state.tmpBranch], repoRoot);
|
|
228
228
|
this.store.clear(repoRoot);
|
|
229
229
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
// The halt message names the build only where the finish will actually run one.
|
|
242
|
-
buildStep(state) {
|
|
243
|
-
return state.mode === push_dev_state_1.DevResolveMode.PREBUILD ? 'run the dev build, ' : '';
|
|
244
|
-
}
|
|
245
|
-
publishedBanner(state) {
|
|
246
|
-
const what = state.mode === push_dev_state_1.DevResolveMode.REPLAY
|
|
247
|
-
? 'your new commits merged with the copy\'s earlier resolution'
|
|
248
|
-
: state.resolvedPaths.length === 0
|
|
249
|
-
? 'your branch exactly as it is'
|
|
250
|
-
: `your branch plus ONE commit recording the resolution of ${String(state.resolvedPaths.length)} file(s) — no merge, so no other copy became part of its history`;
|
|
251
|
-
return '\n' + SEP + `✅ Published ${state.targetRef}\n` + SEP + '\n'
|
|
252
|
-
+ `The copy is ${what}.\n`
|
|
253
|
-
+ `You are back on \`${state.originalBranch}\`, which was never modified — verify with:\n`
|
|
254
|
-
+ ` git log --oneline ${state.originalBranch}\n`
|
|
255
|
-
+ 'Your CI will pick the copy up on its next composition run.\n'
|
|
256
|
-
+ ` ${rules_config_1.WP_PUSH_DEV} --list ← what else is in the pool\n`
|
|
257
|
-
+ ` ${rules_config_1.WP_PUSH_DEV} --remove ← take this branch back out\n`;
|
|
230
|
+
verifiedBanner(state, devSha) {
|
|
231
|
+
const what = state.resolvedPaths.length === 0
|
|
232
|
+
? 'your branch exactly as it is'
|
|
233
|
+
: `your branch plus ONE commit recording the resolution of ${String(state.resolvedPaths.length)} file(s) — no merge, so no other copy becomes part of its history`;
|
|
234
|
+
return '\n' + SEP + `✅ ${state.targetRef} is verified against origin/${state.devBranch}\n` + SEP + '\n'
|
|
235
|
+
+ `It merges with origin/${state.devBranch} (${devSha.slice(0, 8)}), pnpm install ran on the merged tree, and the dev\n`
|
|
236
|
+
+ `build is green. The copy to publish is ${what}.\n`
|
|
237
|
+
+ `You are back on \`${state.originalBranch}\`, which this check never modified.\n\n`
|
|
238
|
+
+ `▶ NEXT run: ${rules_config_1.WP_FINISH_PUSH_DEV}\n`
|
|
239
|
+
+ ` It publishes the verified copy as \`${state.targetRef}\`. It refuses if \`${state.originalBranch}\`\n`
|
|
240
|
+
+ ' moves before then — a new commit means a new check.\n';
|
|
258
241
|
}
|
|
259
242
|
/** Conflicted (unmerged-in-index) paths. Empty once every one has been resolved and `git add`ed. */
|
|
260
243
|
async unmergedPaths(repoRoot) {
|
|
261
244
|
const out = await this.gitExec.gitQuery(['-C', repoRoot, 'diff', '--name-only', '--diff-filter=U'], repoRoot, 'Failed to list the conflicted files (git diff --name-only --diff-filter=U).');
|
|
262
245
|
return out.split('\n').filter((l) => l.trim() !== '');
|
|
263
246
|
}
|
|
264
|
-
// The gate on
|
|
265
|
-
async assertNoUnmergedPaths(repoRoot
|
|
247
|
+
// The gate on resuming: refuse (and re-print the list) while anything is still unmerged.
|
|
248
|
+
async assertNoUnmergedPaths(repoRoot) {
|
|
266
249
|
const conflicted = await this.unmergedPaths(repoRoot);
|
|
267
250
|
if (conflicted.length === 0)
|
|
268
251
|
return;
|
|
269
252
|
throw new rules_config_1.CliExitError(2, '\n' + SEP + '⛔ Conflicts are NOT resolved yet\n' + SEP + '\n'
|
|
270
|
-
+ `${rules_config_1.
|
|
253
|
+
+ `${rules_config_1.WP_BUILD_PUSH_DEV} commits the resolution — it cannot write one for you. These files are still\n`
|
|
271
254
|
+ 'unmerged (edit until no conflict markers remain, then `git add` each one):\n'
|
|
272
255
|
+ conflicted.map((f) => ` ${f}`).join('\n') + '\n\n'
|
|
273
|
-
+ `
|
|
274
|
-
+ `Give up instead with: ${rules_config_1.WP_FINISH_PUSH_DEV} --abort\n`);
|
|
256
|
+
+ `Give up instead with: ${rules_config_1.WP_BUILD_PUSH_DEV} --abort\n`);
|
|
275
257
|
}
|
|
276
258
|
/**
|
|
277
|
-
* The name of the throwaway branch for a
|
|
259
|
+
* The name of the throwaway branch for a check of `branch`.
|
|
278
260
|
*
|
|
279
261
|
* Suffixed rather than prefixed, matching the existing `<feature>Squash` / `<feature>PreMerge<n>`
|
|
280
262
|
* convention — and deliberately NOT inside the dev namespace, which holds REMOTE copies only.
|
|
@@ -282,25 +264,15 @@ let DevResolveRunner = class DevResolveRunner {
|
|
|
282
264
|
tmpBranchFor(branch) {
|
|
283
265
|
return `${branch}DevResolve`;
|
|
284
266
|
}
|
|
285
|
-
/** The banner
|
|
267
|
+
/** The banner `wp-build-push-dev` prints before its check against dev. */
|
|
286
268
|
announce(cfg, state) {
|
|
287
|
-
return '\n' + SEP +
|
|
288
|
-
+ `Merging
|
|
289
|
-
+
|
|
290
|
-
+
|
|
291
|
-
+
|
|
292
|
-
+ `
|
|
293
|
-
+ '
|
|
294
|
-
+ 'plus ONE commit holding the resolved files — never a merge, so no other copy enters its history.\n'
|
|
295
|
-
+ `${rules_config_1.WP_FINISH_PUSH_DEV} is only needed if a merge stops.\n\n`;
|
|
296
|
-
}
|
|
297
|
-
/** The banner plain `wp-push-dev` prints before its check against dev (#1397). */
|
|
298
|
-
announcePrebuild(cfg, state) {
|
|
299
|
-
return '\n' + SEP + `🔎 Checking ${state.targetRef} against origin/${cfg.devBranch} before publishing\n` + SEP + '\n'
|
|
300
|
-
+ `Merging origin/${cfg.devBranch} into the throwaway branch \`${state.tmpBranch}\`, then running\n`
|
|
301
|
-
+ '`commands.push-dev.buildCommand` on the merged tree. Only if both pass is the copy published — as\n'
|
|
302
|
-
+ 'your branch, plus ONE commit holding any resolved files. The merge itself is never published, so a\n'
|
|
303
|
-
+ `later \`${rules_config_1.WP_PUSH_DEV} --remove\` of somebody else's copy cannot leave it on dev through yours.\n`
|
|
269
|
+
return '\n' + SEP + `🔎 Checking ${state.targetRef} against origin/${cfg.devBranch}\n` + SEP + '\n'
|
|
270
|
+
+ `Merging origin/${cfg.devBranch} into the throwaway branch \`${state.tmpBranch}\`, then running \`pnpm install\`\n`
|
|
271
|
+
+ 'and `commands.push-dev.buildCommand` (compile + tests only — the code rules already judged your branch\n'
|
|
272
|
+
+ 'against main, and must never judge the other copies on dev) on the merged tree. A conflict whose dev\n'
|
|
273
|
+
+ 'side comes only from copies already on origin/main takes your side automatically.\n'
|
|
274
|
+
+ `Nothing is published here — when both pass, ${rules_config_1.WP_FINISH_PUSH_DEV} publishes your branch, plus ONE\n`
|
|
275
|
+
+ 'commit holding any resolved files. The merge itself is never published.\n'
|
|
304
276
|
+ `Your feature branch \`${state.originalBranch}\` is not touched by any of this.\n\n`;
|
|
305
277
|
}
|
|
306
278
|
};
|
|
@@ -310,7 +282,9 @@ exports.DevResolveRunner = DevResolveRunner = tslib_1.__decorate([
|
|
|
310
282
|
tslib_1.__metadata("design:paramtypes", [git_exec_1.GitExec,
|
|
311
283
|
dev_deploy_refs_1.DevDeployRefs,
|
|
312
284
|
push_dev_state_1.PushDevStateStore,
|
|
313
|
-
|
|
314
|
-
dev_build_1.DevBuild
|
|
285
|
+
verified_dev_copy_1.VerifiedDevCopyStore,
|
|
286
|
+
dev_build_1.DevBuild,
|
|
287
|
+
tooling_common_1.NativeProcessApi,
|
|
288
|
+
landed_copy_resolver_1.LandedCopyResolver])
|
|
315
289
|
], DevResolveRunner);
|
|
316
290
|
//# sourceMappingURL=dev-resolve-runner.js.map
|