@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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PushDevStateStore = exports.PushDevState =
|
|
3
|
+
exports.PushDevStateStore = exports.PushDevState = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fs = tslib_1.__importStar(require("fs"));
|
|
6
6
|
const rules_config_1 = require("@webpieces/rules-config");
|
|
@@ -9,75 +9,50 @@ const to_error_1 = require("@webpieces/tooling-common/to-error");
|
|
|
9
9
|
const inversify_1 = require("inversify");
|
|
10
10
|
const SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n';
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* The persisted half of `wp-build-push-dev`'s conflict halt (#1403).
|
|
13
13
|
*
|
|
14
|
-
* -
|
|
15
|
-
* on the merged tree, and what is published is the feature head PLUS one commit recording the resolved
|
|
16
|
-
* files. The merge itself is never published.
|
|
17
|
-
* - `COMPOSE` — `wp-push-dev --resolve`: the other copies are merged into a throwaway, and what is
|
|
18
|
-
* published is the existing copy PLUS one commit recording the resolved files — never a merge parent,
|
|
19
|
-
* so no other copy becomes an ancestor of this one and a later `--remove` of it really takes it off dev.
|
|
20
|
-
* - `REPLAY` — `wp-push-dev --rebase-resolution`: the published copy is merged into the new local head
|
|
21
|
-
* and that merge IS what is published, so the copy's own resolution survives the new commits.
|
|
22
|
-
*/
|
|
23
|
-
var DevResolveMode;
|
|
24
|
-
(function (DevResolveMode) {
|
|
25
|
-
DevResolveMode["PREBUILD"] = "prebuild";
|
|
26
|
-
DevResolveMode["COMPOSE"] = "compose";
|
|
27
|
-
DevResolveMode["REPLAY"] = "replay";
|
|
28
|
-
})(DevResolveMode || (exports.DevResolveMode = DevResolveMode = {}));
|
|
29
|
-
/**
|
|
30
|
-
* The persisted half of the `wp-push-dev --resolve` state machine.
|
|
31
|
-
*
|
|
32
|
-
* A single-shot wrapper is IMPOSSIBLE here and that is why this file exists: `git merge` halts on
|
|
14
|
+
* A single-shot command is IMPOSSIBLE here and that is why this file exists: `git merge` halts on
|
|
33
15
|
* conflict with markers in the working tree and a non-zero exit, and a human or an AI has to edit files
|
|
34
16
|
* before anything can be committed. So the command must be able to stop, hand the tree over, and be
|
|
35
|
-
* resumed by a
|
|
17
|
+
* resumed — by a re-run of itself — knowing exactly where it left off.
|
|
36
18
|
*
|
|
37
19
|
* Data-only (per CLAUDE.md) — the behaviour lives in {@link PushDevStateStore}.
|
|
38
20
|
*/
|
|
39
21
|
class PushDevState {
|
|
40
|
-
/** The branch to return to when the
|
|
22
|
+
/** The branch to return to when the check finishes or aborts. NEVER written to by this flow. */
|
|
41
23
|
originalBranch;
|
|
42
|
-
/** The local throwaway branch the
|
|
24
|
+
/** The local throwaway branch the dev merge happens on. Deleted on finish and on abort. */
|
|
43
25
|
tmpBranch;
|
|
44
|
-
/** `<namespace>/<originalBranch>` — the remote copy
|
|
26
|
+
/** `<namespace>/<originalBranch>` — the remote copy `wp-finish-push-dev` will publish. */
|
|
45
27
|
targetRef;
|
|
46
|
-
/** The
|
|
47
|
-
|
|
48
|
-
/** The
|
|
49
|
-
current;
|
|
50
|
-
/** What the finish publishes — see DevResolveMode. */
|
|
51
|
-
mode = DevResolveMode.COMPOSE;
|
|
52
|
-
/** The sha the published copy is built ON: the feature head (PREBUILD) or the published copy (COMPOSE). */
|
|
28
|
+
/** The composed dev branch merged into the throwaway, e.g. `dev`. */
|
|
29
|
+
devBranch;
|
|
30
|
+
/** The feature head the copy is built ON, pinned when the check started. */
|
|
53
31
|
baseSha = '';
|
|
54
32
|
/** Every path that conflicted and was resolved; the recorded resolution carries exactly these. */
|
|
55
33
|
resolvedPaths = [];
|
|
56
|
-
/** The remote copy's sha when the
|
|
34
|
+
/** The remote copy's sha when the check started ('' = not published yet) — the publish's lease. */
|
|
57
35
|
leaseSha = '';
|
|
58
|
-
|
|
59
|
-
force = false;
|
|
60
|
-
// eslint-disable-next-line @typescript-eslint/max-params
|
|
61
|
-
constructor(originalBranch, tmpBranch, targetRef, queue, current = '') {
|
|
36
|
+
constructor(originalBranch, tmpBranch, targetRef, devBranch) {
|
|
62
37
|
this.originalBranch = originalBranch;
|
|
63
38
|
this.tmpBranch = tmpBranch;
|
|
64
39
|
this.targetRef = targetRef;
|
|
65
|
-
this.
|
|
66
|
-
this.current = current;
|
|
40
|
+
this.devBranch = devBranch;
|
|
67
41
|
}
|
|
68
42
|
}
|
|
69
43
|
exports.PushDevState = PushDevState;
|
|
70
|
-
// The wp-* commands that must REFUSE while a
|
|
71
|
-
// written. The blocked-list sentence below RENDERS ITSELF from this array — the same lesson
|
|
44
|
+
// The wp-* commands that must REFUSE while a dev conflict is half-resolved, and the ONE place that list
|
|
45
|
+
// is written. The blocked-list sentence below RENDERS ITSELF from this array — the same lesson
|
|
72
46
|
// merge-in-progress-guard already learned the hard way: a hand-written "don't run other commands"
|
|
73
47
|
// survives every edit to the actual enforcement and ends up forbidding things the flow requires.
|
|
74
48
|
//
|
|
75
|
-
// Why these and not everything: each one either rewrites the current branch (the
|
|
76
|
-
// (the finishes), deletes branches (cleanup)
|
|
77
|
-
//
|
|
78
|
-
//
|
|
49
|
+
// Why these and not everything: each one either rewrites the current branch (the starts), pushes it or a
|
|
50
|
+
// copy of it (the finishes), or deletes branches (cleanup) — and during a resolve the checkout is a
|
|
51
|
+
// throwaway branch, not the feature branch any of them think they are acting on. `wp-build-push-dev`
|
|
52
|
+
// itself is NOT here: re-running it is how the resolve continues.
|
|
79
53
|
const BLOCKED_DURING_RESOLVE = [
|
|
80
|
-
'wp-
|
|
54
|
+
'wp-start-push-dev',
|
|
55
|
+
'wp-finish-push-dev',
|
|
81
56
|
'wp-start-update',
|
|
82
57
|
'wp-finish-update',
|
|
83
58
|
'wp-start-upsert-pr',
|
|
@@ -112,25 +87,21 @@ let PushDevStateStore = class PushDevStateStore {
|
|
|
112
87
|
const file = this.path(repoRoot);
|
|
113
88
|
if (!fs.existsSync(file))
|
|
114
89
|
return null;
|
|
115
|
-
// webpieces-disable no-unmanaged-exceptions -- a truncated/hand-edited state file must degrade to "no resolve in progress"
|
|
90
|
+
// webpieces-disable no-unmanaged-exceptions -- a truncated/hand-edited state file must degrade to "no resolve in progress", never crash every wp-* command in the tree
|
|
116
91
|
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
117
92
|
try {
|
|
118
93
|
// webpieces-disable no-any-unknown -- JSON.parse is untyped until narrowed on the next line
|
|
119
94
|
const raw = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
120
95
|
if (typeof raw.originalBranch !== 'string' || typeof raw.tmpBranch !== 'string')
|
|
121
96
|
return null;
|
|
122
|
-
const state = new PushDevState(raw.originalBranch, raw.tmpBranch, raw.targetRef
|
|
123
|
-
state.mode = Object.values(DevResolveMode).includes(raw.mode)
|
|
124
|
-
? raw.mode
|
|
125
|
-
: DevResolveMode.COMPOSE;
|
|
97
|
+
const state = new PushDevState(raw.originalBranch, raw.tmpBranch, typeof raw.targetRef === 'string' ? raw.targetRef : '', typeof raw.devBranch === 'string' ? raw.devBranch : '');
|
|
126
98
|
state.baseSha = typeof raw.baseSha === 'string' ? raw.baseSha : '';
|
|
127
99
|
state.resolvedPaths = Array.isArray(raw.resolvedPaths) ? raw.resolvedPaths : [];
|
|
128
100
|
state.leaseSha = typeof raw.leaseSha === 'string' ? raw.leaseSha : '';
|
|
129
|
-
state.force = raw.force === true;
|
|
130
101
|
return state;
|
|
131
102
|
// The parse error carries nothing a caller could act on: the ONLY meaningful reading of an
|
|
132
|
-
// unparseable state file is "no resolve in progress"
|
|
133
|
-
//
|
|
103
|
+
// unparseable state file is "no resolve in progress".
|
|
104
|
+
// webpieces-disable catch-must-propagate -- an unparseable state file means no resolve is in progress; the parse error carries nothing a caller could act on
|
|
134
105
|
}
|
|
135
106
|
catch (err) {
|
|
136
107
|
const error = (0, to_error_1.toError)(err);
|
|
@@ -147,7 +118,7 @@ let PushDevStateStore = class PushDevStateStore {
|
|
|
147
118
|
if (fs.existsSync(file))
|
|
148
119
|
fs.rmSync(file);
|
|
149
120
|
}
|
|
150
|
-
/** The read that MUST find a resolve — used by `wp-
|
|
121
|
+
/** The read that MUST find a resolve — used by `wp-build-push-dev --abort`, whose whole job is ending one. */
|
|
151
122
|
require(repoRoot) {
|
|
152
123
|
const state = this.read(repoRoot);
|
|
153
124
|
if (state !== null)
|
|
@@ -157,10 +128,8 @@ let PushDevStateStore = class PushDevStateStore {
|
|
|
157
128
|
'⛔ No dev-deploy resolve is in progress\n' +
|
|
158
129
|
SEP +
|
|
159
130
|
'\n' +
|
|
160
|
-
|
|
161
|
-
`state file at:\n ${this.path(repoRoot)}\n\n`
|
|
162
|
-
'If you meant to publish your branch to the shared dev server, that is the one-command form:\n' +
|
|
163
|
-
` ${rules_config_1.WP_PUSH_DEV}\n`);
|
|
131
|
+
`\`${rules_config_1.WP_BUILD_PUSH_DEV} --abort\` throws away a conflict resolution that \`${rules_config_1.WP_BUILD_PUSH_DEV}\` stopped on,\n` +
|
|
132
|
+
`and there is no state file at:\n ${this.path(repoRoot)}\n\nThere is nothing to abort.\n`);
|
|
164
133
|
}
|
|
165
134
|
/**
|
|
166
135
|
* Refuse `attempted` while a resolve is half-finished. Called from the app root for every command in
|
|
@@ -179,9 +148,9 @@ let PushDevStateStore = class PushDevStateStore {
|
|
|
179
148
|
`so ${this.blockedCommandList()} would all act on the wrong branch.\n` +
|
|
180
149
|
'That is the whole list; nothing else is blocked.\n\n' +
|
|
181
150
|
'EXPECTED of you right now, and NOT blocked: read the conflicted files and edit them until every\n' +
|
|
182
|
-
'conflict marker is gone. Then
|
|
183
|
-
` ${rules_config_1.
|
|
184
|
-
` ${rules_config_1.
|
|
151
|
+
'conflict marker is gone, and `git add` each one. Then continue or bail out:\n' +
|
|
152
|
+
` ${rules_config_1.WP_BUILD_PUSH_DEV} ← commit the resolution, pnpm install, run the dev build\n` +
|
|
153
|
+
` ${rules_config_1.WP_BUILD_PUSH_DEV} --abort ← throw the resolution away and go back to \`${state.originalBranch}\`\n\n` +
|
|
185
154
|
`State file: ${this.path(repoRoot)}\n`);
|
|
186
155
|
}
|
|
187
156
|
// Rendered from BLOCKED_DURING_RESOLVE, never hand-written — see that constant.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"push-dev-state.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/push-dev-state.ts"],"names":[],"mappings":";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CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAC7C,CAAC;IACN,CAAC;IAED,gFAAgF;IACxE,kBAAkB;QACtB,OAAO,sBAAsB,CAAC,GAAG,CAAC,CAAC,CAAS,EAAU,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACzF,CAAC;IAED,uFAAuF;IACvF,sBAAsB,CAAC,OAAe;QAClC,OAAO,sBAAsB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACpD,CAAC;CACJ,CAAA;AA7GY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAEM,6BAAY;GAD9C,iBAAiB,CA6G7B","sourcesContent":["import * as fs from 'fs';\n\nimport { CliExitError, PUSH_DEV_STATE_FILE, WP_FINISH_PUSH_DEV, WP_PUSH_DEV } from '@webpieces/rules-config';\nimport { DotWebpieces } from '@webpieces/tooling-common';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * WHICH flow a resolve is part of — it decides what the finish publishes (#1397).\n *\n * - `PREBUILD` — plain `wp-push-dev`: `origin/<devBranch>` is merged into a throwaway, the dev build runs\n * on the merged tree, and what is published is the feature head PLUS one commit recording the resolved\n * files. The merge itself is never published.\n * - `COMPOSE` — `wp-push-dev --resolve`: the other copies are merged into a throwaway, and what is\n * published is the existing copy PLUS one commit recording the resolved files — never a merge parent,\n * so no other copy becomes an ancestor of this one and a later `--remove` of it really takes it off dev.\n * - `REPLAY` — `wp-push-dev --rebase-resolution`: the published copy is merged into the new local head\n * and that merge IS what is published, so the copy's own resolution survives the new commits.\n */\nexport enum DevResolveMode {\n PREBUILD = 'prebuild',\n COMPOSE = 'compose',\n REPLAY = 'replay',\n}\n\n/**\n * The persisted half of the `wp-push-dev --resolve` state machine.\n *\n * A single-shot wrapper is IMPOSSIBLE here and that is why this file exists: `git merge` halts on\n * conflict with markers in the working tree and a non-zero exit, and a human or an AI has to edit files\n * before anything can be committed. So the command must be able to stop, hand the tree over, and be\n * resumed by a second command that knows exactly where it left off.\n *\n * Data-only (per CLAUDE.md) — the behaviour lives in {@link PushDevStateStore}.\n */\nexport class PushDevState {\n /** The branch to return to when the resolve finishes or aborts. NEVER written to by this flow. */\n originalBranch: string;\n /** The local throwaway branch the merges happen on. Deleted on finish and on abort. */\n tmpBranch: string;\n /** `<namespace>/<originalBranch>` — the remote copy this resolve republishes. */\n targetRef: string;\n /** The copy refs still to merge, in the order CI composes them. */\n queue: string[];\n /** The ref currently mid-merge (conflicted), or '' when nothing is halted. */\n current: string;\n /** What the finish publishes — see DevResolveMode. */\n mode: DevResolveMode = DevResolveMode.COMPOSE;\n /** The sha the published copy is built ON: the feature head (PREBUILD) or the published copy (COMPOSE). */\n baseSha = '';\n /** Every path that conflicted and was resolved; the recorded resolution carries exactly these. */\n resolvedPaths: string[] = [];\n /** The remote copy's sha when the flow started ('' = not published yet) — the push's lease. */\n leaseSha = '';\n /** `--force` was given: overwrite the copy without a lease. */\n force = false;\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n originalBranch: string,\n tmpBranch: string,\n targetRef: string,\n queue: string[],\n current = '',\n ) {\n this.originalBranch = originalBranch;\n this.tmpBranch = tmpBranch;\n this.targetRef = targetRef;\n this.queue = queue;\n this.current = current;\n }\n}\n\n// The wp-* commands that must REFUSE while a resolve is half-finished, and the ONE place that list is\n// written. The blocked-list sentence below RENDERS ITSELF from this array — the same lesson\n// merge-in-progress-guard already learned the hard way: a hand-written \"don't run other commands\"\n// survives every edit to the actual enforcement and ends up forbidding things the flow requires.\n//\n// Why these and not everything: each one either rewrites the current branch (the two starts), pushes it\n// (the finishes), deletes branches (cleanup), or parks the checkout on a throwaway of its own\n// (wp-build-dev) — and during a resolve the checkout is a throwaway\n// branch, not the feature branch any of them think they are acting on.\nconst BLOCKED_DURING_RESOLVE: readonly string[] = [\n 'wp-build-dev',\n 'wp-start-update',\n 'wp-finish-update',\n 'wp-start-upsert-pr',\n 'wp-review-upsert-pr',\n 'wp-finish-upsert-pr',\n 'wp-human-post-pr',\n 'wp-upsert-hotfix-pr',\n 'wp-land-pr',\n 'wp-cleanup',\n];\n\n/**\n * Reads, writes and clears the resolve state file, and refuses the other `wp-*` commands while it\n * exists.\n *\n * LOCAL scope, deliberately: a resolve halts one worktree's checkout on a throwaway branch, and another\n * worktree has no reason to care. Sharing it would block a colleague's PR flow on state that says\n * nothing about their tree.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class PushDevStateStore {\n constructor(private readonly dotWebpieces: DotWebpieces) {}\n\n path(repoRoot: string): string {\n return this.dotWebpieces.localFile(repoRoot, PUSH_DEV_STATE_FILE);\n }\n\n exists(repoRoot: string): boolean {\n return fs.existsSync(this.path(repoRoot));\n }\n\n /** The in-flight resolve, or null when none is. A corrupt file reads as null rather than crashing. */\n read(repoRoot: string): PushDevState | null {\n const file = this.path(repoRoot);\n if (!fs.existsSync(file)) return null;\n // webpieces-disable no-unmanaged-exceptions -- a truncated/hand-edited state file must degrade to \"no resolve in progress\" (recoverable via --abort or a fresh --resolve), never crash every wp-* command in the tree\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // webpieces-disable no-any-unknown -- JSON.parse is untyped until narrowed on the next line\n const raw = JSON.parse(fs.readFileSync(file, 'utf8')) as Partial<PushDevState>;\n if (typeof raw.originalBranch !== 'string' || typeof raw.tmpBranch !== 'string')\n return null;\n const state = new PushDevState(\n raw.originalBranch,\n raw.tmpBranch,\n raw.targetRef ?? '',\n Array.isArray(raw.queue) ? raw.queue : [],\n raw.current ?? '',\n );\n state.mode = Object.values(DevResolveMode).includes(raw.mode as DevResolveMode)\n ? (raw.mode as DevResolveMode)\n : DevResolveMode.COMPOSE;\n state.baseSha = typeof raw.baseSha === 'string' ? raw.baseSha : '';\n state.resolvedPaths = Array.isArray(raw.resolvedPaths) ? raw.resolvedPaths : [];\n state.leaseSha = typeof raw.leaseSha === 'string' ? raw.leaseSha : '';\n state.force = raw.force === true;\n return state;\n // The parse error carries nothing a caller could act on: the ONLY meaningful reading of an\n // unparseable state file is \"no resolve in progress\", which --abort and a fresh --resolve both\n // recover from.\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return null;\n }\n }\n\n write(repoRoot: string, state: PushDevState): void {\n fs.mkdirSync(this.dotWebpieces.local(repoRoot), { recursive: true });\n fs.writeFileSync(this.path(repoRoot), JSON.stringify(state, null, 2) + '\\n', 'utf8');\n }\n\n clear(repoRoot: string): void {\n const file = this.path(repoRoot);\n if (fs.existsSync(file)) fs.rmSync(file);\n }\n\n /** The read that MUST find a resolve — used by `wp-finish-push-dev`, whose whole job is resuming one. */\n require(repoRoot: string): PushDevState {\n const state = this.read(repoRoot);\n if (state !== null) return state;\n throw new CliExitError(\n 2,\n '\\n' +\n SEP +\n '⛔ No dev-deploy resolve is in progress\\n' +\n SEP +\n '\\n' +\n `${WP_FINISH_PUSH_DEV} resumes a resolve that \\`${WP_PUSH_DEV} --resolve\\` started, and there is no\\n` +\n `state file at:\\n ${this.path(repoRoot)}\\n\\n` +\n 'If you meant to publish your branch to the shared dev server, that is the one-command form:\\n' +\n ` ${WP_PUSH_DEV}\\n`,\n );\n }\n\n /**\n * Refuse `attempted` while a resolve is half-finished. Called from the app root for every command in\n * {@link BLOCKED_DURING_RESOLVE}, so no individual command has to remember to ask.\n */\n assertIdle(repoRoot: string, attempted: string): void {\n const state = this.read(repoRoot);\n if (state === null) return;\n throw new CliExitError(\n 2,\n '\\n' +\n SEP +\n `⛔ A dev-deploy resolve is in progress — \\`pnpm ${attempted}\\` is blocked\\n` +\n SEP +\n '\\n' +\n `You are standing on the throwaway branch \\`${state.tmpBranch}\\`, not on \\`${state.originalBranch}\\`,\\n` +\n `so ${this.blockedCommandList()} would all act on the wrong branch.\\n` +\n 'That is the whole list; nothing else is blocked.\\n\\n' +\n 'EXPECTED of you right now, and NOT blocked: read the conflicted files and edit them until every\\n' +\n 'conflict marker is gone. Then finish or bail out:\\n' +\n ` ${WP_FINISH_PUSH_DEV} ← commit the resolution, resume the queue, publish the copy\\n` +\n ` ${WP_FINISH_PUSH_DEV} --abort ← throw the resolution away and go back to \\`${state.originalBranch}\\`\\n\\n` +\n `State file: ${this.path(repoRoot)}\\n`,\n );\n }\n\n // Rendered from BLOCKED_DURING_RESOLVE, never hand-written — see that constant.\n private blockedCommandList(): string {\n return BLOCKED_DURING_RESOLVE.map((c: string): string => `\\`pnpm ${c}\\``).join(', ');\n }\n\n /** Is `command` one of the ones that must refuse mid-resolve? Used by the app root. */\n isBlockedDuringResolve(command: string): boolean {\n return BLOCKED_DURING_RESOLVE.includes(command);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"push-dev-state.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/push-dev-state.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AAEzB,0DAA+F;AAC/F,8DAAyD;AACzD,iEAA6D;AAC7D,yCAA2D;AAE3D,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE;;;;;;;;;GASG;AACH,MAAa,YAAY;IACrB,gGAAgG;IAChG,cAAc,CAAS;IACvB,2FAA2F;IAC3F,SAAS,CAAS;IAClB,0FAA0F;IAC1F,SAAS,CAAS;IAClB,qEAAqE;IACrE,SAAS,CAAS;IAClB,4EAA4E;IAC5E,OAAO,GAAG,EAAE,CAAC;IACb,kGAAkG;IAClG,aAAa,GAAa,EAAE,CAAC;IAC7B,mGAAmG;IACnG,QAAQ,GAAG,EAAE,CAAC;IAEd,YAAY,cAAsB,EAAE,SAAiB,EAAE,SAAiB,EAAE,SAAiB;QACvF,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IA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G,eAAe,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAC7C,CAAC;IACN,CAAC;IAED,gFAAgF;IACxE,kBAAkB;QACtB,OAAO,sBAAsB,CAAC,GAAG,CAAC,CAAC,CAAS,EAAU,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACzF,CAAC;IAED,uFAAuF;IACvF,sBAAsB,CAAC,OAAe;QAClC,OAAO,sBAAsB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACpD,CAAC;CACJ,CAAA;AAtGY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAEM,6BAAY;GAD9C,iBAAiB,CAsG7B","sourcesContent":["import * as fs from 'fs';\n\nimport { CliExitError, PUSH_DEV_STATE_FILE, WP_BUILD_PUSH_DEV } from '@webpieces/rules-config';\nimport { DotWebpieces } from '@webpieces/tooling-common';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * The persisted half of `wp-build-push-dev`'s conflict halt (#1403).\n *\n * A single-shot command is IMPOSSIBLE here and that is why this file exists: `git merge` halts on\n * conflict with markers in the working tree and a non-zero exit, and a human or an AI has to edit files\n * before anything can be committed. So the command must be able to stop, hand the tree over, and be\n * resumed — by a re-run of itself — knowing exactly where it left off.\n *\n * Data-only (per CLAUDE.md) — the behaviour lives in {@link PushDevStateStore}.\n */\nexport class PushDevState {\n /** The branch to return to when the check finishes or aborts. NEVER written to by this flow. */\n originalBranch: string;\n /** The local throwaway branch the dev merge happens on. Deleted on finish and on abort. */\n tmpBranch: string;\n /** `<namespace>/<originalBranch>` — the remote copy `wp-finish-push-dev` will publish. */\n targetRef: string;\n /** The composed dev branch merged into the throwaway, e.g. `dev`. */\n devBranch: string;\n /** The feature head the copy is built ON, pinned when the check started. */\n baseSha = '';\n /** Every path that conflicted and was resolved; the recorded resolution carries exactly these. */\n resolvedPaths: string[] = [];\n /** The remote copy's sha when the check started ('' = not published yet) — the publish's lease. */\n leaseSha = '';\n\n constructor(originalBranch: string, tmpBranch: string, targetRef: string, devBranch: string) {\n this.originalBranch = originalBranch;\n this.tmpBranch = tmpBranch;\n this.targetRef = targetRef;\n this.devBranch = devBranch;\n }\n}\n\n// The wp-* commands that must REFUSE while a dev conflict is half-resolved, and the ONE place that list\n// is written. The blocked-list sentence below RENDERS ITSELF from this array — the same lesson\n// merge-in-progress-guard already learned the hard way: a hand-written \"don't run other commands\"\n// survives every edit to the actual enforcement and ends up forbidding things the flow requires.\n//\n// Why these and not everything: each one either rewrites the current branch (the starts), pushes it or a\n// copy of it (the finishes), or deletes branches (cleanup) — and during a resolve the checkout is a\n// throwaway branch, not the feature branch any of them think they are acting on. `wp-build-push-dev`\n// itself is NOT here: re-running it is how the resolve continues.\nconst BLOCKED_DURING_RESOLVE: readonly string[] = [\n 'wp-start-push-dev',\n 'wp-finish-push-dev',\n 'wp-start-update',\n 'wp-finish-update',\n 'wp-start-upsert-pr',\n 'wp-review-upsert-pr',\n 'wp-finish-upsert-pr',\n 'wp-human-post-pr',\n 'wp-upsert-hotfix-pr',\n 'wp-land-pr',\n 'wp-cleanup',\n];\n\n/**\n * Reads, writes and clears the resolve state file, and refuses the other `wp-*` commands while it\n * exists.\n *\n * LOCAL scope, deliberately: a resolve halts one worktree's checkout on a throwaway branch, and another\n * worktree has no reason to care. Sharing it would block a colleague's PR flow on state that says\n * nothing about their tree.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class PushDevStateStore {\n constructor(private readonly dotWebpieces: DotWebpieces) {}\n\n path(repoRoot: string): string {\n return this.dotWebpieces.localFile(repoRoot, PUSH_DEV_STATE_FILE);\n }\n\n exists(repoRoot: string): boolean {\n return fs.existsSync(this.path(repoRoot));\n }\n\n /** The in-flight resolve, or null when none is. A corrupt file reads as null rather than crashing. */\n read(repoRoot: string): PushDevState | null {\n const file = this.path(repoRoot);\n if (!fs.existsSync(file)) return null;\n // webpieces-disable no-unmanaged-exceptions -- a truncated/hand-edited state file must degrade to \"no resolve in progress\", never crash every wp-* command in the tree\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // webpieces-disable no-any-unknown -- JSON.parse is untyped until narrowed on the next line\n const raw = JSON.parse(fs.readFileSync(file, 'utf8')) as Partial<PushDevState>;\n if (typeof raw.originalBranch !== 'string' || typeof raw.tmpBranch !== 'string')\n return null;\n const state = new PushDevState(\n raw.originalBranch,\n raw.tmpBranch,\n typeof raw.targetRef === 'string' ? raw.targetRef : '',\n typeof raw.devBranch === 'string' ? raw.devBranch : '',\n );\n state.baseSha = typeof raw.baseSha === 'string' ? raw.baseSha : '';\n state.resolvedPaths = Array.isArray(raw.resolvedPaths) ? raw.resolvedPaths : [];\n state.leaseSha = typeof raw.leaseSha === 'string' ? raw.leaseSha : '';\n return state;\n // The parse error carries nothing a caller could act on: the ONLY meaningful reading of an\n // unparseable state file is \"no resolve in progress\".\n // webpieces-disable catch-must-propagate -- an unparseable state file means no resolve is in progress; the parse error carries nothing a caller could act on\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return null;\n }\n }\n\n write(repoRoot: string, state: PushDevState): void {\n fs.mkdirSync(this.dotWebpieces.local(repoRoot), { recursive: true });\n fs.writeFileSync(this.path(repoRoot), JSON.stringify(state, null, 2) + '\\n', 'utf8');\n }\n\n clear(repoRoot: string): void {\n const file = this.path(repoRoot);\n if (fs.existsSync(file)) fs.rmSync(file);\n }\n\n /** The read that MUST find a resolve — used by `wp-build-push-dev --abort`, whose whole job is ending one. */\n require(repoRoot: string): PushDevState {\n const state = this.read(repoRoot);\n if (state !== null) return state;\n throw new CliExitError(\n 2,\n '\\n' +\n SEP +\n '⛔ No dev-deploy resolve is in progress\\n' +\n SEP +\n '\\n' +\n `\\`${WP_BUILD_PUSH_DEV} --abort\\` throws away a conflict resolution that \\`${WP_BUILD_PUSH_DEV}\\` stopped on,\\n` +\n `and there is no state file at:\\n ${this.path(repoRoot)}\\n\\nThere is nothing to abort.\\n`,\n );\n }\n\n /**\n * Refuse `attempted` while a resolve is half-finished. Called from the app root for every command in\n * {@link BLOCKED_DURING_RESOLVE}, so no individual command has to remember to ask.\n */\n assertIdle(repoRoot: string, attempted: string): void {\n const state = this.read(repoRoot);\n if (state === null) return;\n throw new CliExitError(\n 2,\n '\\n' +\n SEP +\n `⛔ A dev-deploy resolve is in progress — \\`pnpm ${attempted}\\` is blocked\\n` +\n SEP +\n '\\n' +\n `You are standing on the throwaway branch \\`${state.tmpBranch}\\`, not on \\`${state.originalBranch}\\`,\\n` +\n `so ${this.blockedCommandList()} would all act on the wrong branch.\\n` +\n 'That is the whole list; nothing else is blocked.\\n\\n' +\n 'EXPECTED of you right now, and NOT blocked: read the conflicted files and edit them until every\\n' +\n 'conflict marker is gone, and `git add` each one. Then continue or bail out:\\n' +\n ` ${WP_BUILD_PUSH_DEV} ← commit the resolution, pnpm install, run the dev build\\n` +\n ` ${WP_BUILD_PUSH_DEV} --abort ← throw the resolution away and go back to \\`${state.originalBranch}\\`\\n\\n` +\n `State file: ${this.path(repoRoot)}\\n`,\n );\n }\n\n // Rendered from BLOCKED_DURING_RESOLVE, never hand-written — see that constant.\n private blockedCommandList(): string {\n return BLOCKED_DURING_RESOLVE.map((c: string): string => `\\`pnpm ${c}\\``).join(', ');\n }\n\n /** Is `command` one of the ones that must refuse mid-resolve? Used by the app root. */\n isBlockedDuringResolve(command: string): boolean {\n return BLOCKED_DURING_RESOLVE.includes(command);\n }\n}\n"]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { DotWebpieces } from '@webpieces/tooling-common';
|
|
2
|
+
/** The local state file stage ② writes and stage ③ consumes. LOCAL scope: one worktree's verification. */
|
|
3
|
+
export declare const PUSH_DEV_VERIFIED_FILE = "push-dev-verified.json";
|
|
4
|
+
/**
|
|
5
|
+
* What `wp-build-push-dev` (stage ②) verified, for `wp-finish-push-dev` (stage ③) to publish (#1403).
|
|
6
|
+
*
|
|
7
|
+
* The same hand-off the PR flow makes between `wp-review-upsert-pr` and `wp-finish-upsert-pr`: stage ②
|
|
8
|
+
* records the sha it built, and stage ③ refuses when HEAD moved since — so what is published is exactly
|
|
9
|
+
* what was checked against dev and built, never a later commit nobody built.
|
|
10
|
+
*
|
|
11
|
+
* Data-only (per CLAUDE.md) — the behaviour lives in {@link VerifiedDevCopyStore}.
|
|
12
|
+
*/
|
|
13
|
+
export declare class VerifiedDevCopy {
|
|
14
|
+
/** The feature branch that was verified. */
|
|
15
|
+
branch: string;
|
|
16
|
+
/** The feature head the copy is built on. Stage ③ refuses when HEAD is no longer this. */
|
|
17
|
+
headSha: string;
|
|
18
|
+
/** What stage ③ publishes: `headSha`, or `headSha` plus ONE commit recording the resolved files. */
|
|
19
|
+
copySha: string;
|
|
20
|
+
/** `<namespace>/<branch>` — where stage ③ publishes. */
|
|
21
|
+
targetRef: string;
|
|
22
|
+
/** The remote copy's sha when stage ② ran ('' = not published yet) — stage ③'s push lease. */
|
|
23
|
+
leaseSha: string;
|
|
24
|
+
/** The `origin/<devBranch>` sha the copy was merged with and built against; '' when dev did not exist. */
|
|
25
|
+
devSha: string;
|
|
26
|
+
constructor(branch: string, headSha: string, copySha: string, targetRef: string, leaseSha: string, devSha: string);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Reads, writes and clears the stage-② record. A missing or unreadable record reads as null, which stage ③
|
|
30
|
+
* turns into "run `pnpm wp-build-push-dev` first".
|
|
31
|
+
*/
|
|
32
|
+
export declare class VerifiedDevCopyStore {
|
|
33
|
+
private readonly dotWebpieces;
|
|
34
|
+
constructor(dotWebpieces: DotWebpieces);
|
|
35
|
+
path(repoRoot: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* The local ref that keeps the verified copy reachable between stage ② and stage ③. When something
|
|
38
|
+
* conflicted, the copy is a commit on top of the feature head that no branch points at; without a ref
|
|
39
|
+
* holding it, `git gc` could collect it before it is published. Outside `refs/heads/`, so it is never
|
|
40
|
+
* mistaken for a branch (and never counts toward the branch cap or reaches `wp-cleanup`).
|
|
41
|
+
*/
|
|
42
|
+
keepRef(branch: string): string;
|
|
43
|
+
read(repoRoot: string): VerifiedDevCopy | null;
|
|
44
|
+
write(repoRoot: string, record: VerifiedDevCopy): void;
|
|
45
|
+
clear(repoRoot: string): void;
|
|
46
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VerifiedDevCopyStore = exports.VerifiedDevCopy = exports.PUSH_DEV_VERIFIED_FILE = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fs = tslib_1.__importStar(require("fs"));
|
|
6
|
+
const tooling_common_1 = require("@webpieces/tooling-common");
|
|
7
|
+
const inversify_1 = require("inversify");
|
|
8
|
+
/** The local state file stage ② writes and stage ③ consumes. LOCAL scope: one worktree's verification. */
|
|
9
|
+
exports.PUSH_DEV_VERIFIED_FILE = 'push-dev-verified.json';
|
|
10
|
+
/**
|
|
11
|
+
* What `wp-build-push-dev` (stage ②) verified, for `wp-finish-push-dev` (stage ③) to publish (#1403).
|
|
12
|
+
*
|
|
13
|
+
* The same hand-off the PR flow makes between `wp-review-upsert-pr` and `wp-finish-upsert-pr`: stage ②
|
|
14
|
+
* records the sha it built, and stage ③ refuses when HEAD moved since — so what is published is exactly
|
|
15
|
+
* what was checked against dev and built, never a later commit nobody built.
|
|
16
|
+
*
|
|
17
|
+
* Data-only (per CLAUDE.md) — the behaviour lives in {@link VerifiedDevCopyStore}.
|
|
18
|
+
*/
|
|
19
|
+
class VerifiedDevCopy {
|
|
20
|
+
/** The feature branch that was verified. */
|
|
21
|
+
branch;
|
|
22
|
+
/** The feature head the copy is built on. Stage ③ refuses when HEAD is no longer this. */
|
|
23
|
+
headSha;
|
|
24
|
+
/** What stage ③ publishes: `headSha`, or `headSha` plus ONE commit recording the resolved files. */
|
|
25
|
+
copySha;
|
|
26
|
+
/** `<namespace>/<branch>` — where stage ③ publishes. */
|
|
27
|
+
targetRef;
|
|
28
|
+
/** The remote copy's sha when stage ② ran ('' = not published yet) — stage ③'s push lease. */
|
|
29
|
+
leaseSha;
|
|
30
|
+
/** The `origin/<devBranch>` sha the copy was merged with and built against; '' when dev did not exist. */
|
|
31
|
+
devSha;
|
|
32
|
+
constructor(branch, headSha, copySha, targetRef, leaseSha, devSha) {
|
|
33
|
+
this.branch = branch;
|
|
34
|
+
this.headSha = headSha;
|
|
35
|
+
this.copySha = copySha;
|
|
36
|
+
this.targetRef = targetRef;
|
|
37
|
+
this.leaseSha = leaseSha;
|
|
38
|
+
this.devSha = devSha;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.VerifiedDevCopy = VerifiedDevCopy;
|
|
42
|
+
/**
|
|
43
|
+
* Reads, writes and clears the stage-② record. A missing or unreadable record reads as null, which stage ③
|
|
44
|
+
* turns into "run `pnpm wp-build-push-dev` first".
|
|
45
|
+
*/
|
|
46
|
+
let VerifiedDevCopyStore = class VerifiedDevCopyStore {
|
|
47
|
+
dotWebpieces;
|
|
48
|
+
constructor(dotWebpieces) {
|
|
49
|
+
this.dotWebpieces = dotWebpieces;
|
|
50
|
+
}
|
|
51
|
+
path(repoRoot) {
|
|
52
|
+
return this.dotWebpieces.localFile(repoRoot, exports.PUSH_DEV_VERIFIED_FILE);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The local ref that keeps the verified copy reachable between stage ② and stage ③. When something
|
|
56
|
+
* conflicted, the copy is a commit on top of the feature head that no branch points at; without a ref
|
|
57
|
+
* holding it, `git gc` could collect it before it is published. Outside `refs/heads/`, so it is never
|
|
58
|
+
* mistaken for a branch (and never counts toward the branch cap or reaches `wp-cleanup`).
|
|
59
|
+
*/
|
|
60
|
+
keepRef(branch) {
|
|
61
|
+
return `refs/webpieces/push-dev/${branch}`;
|
|
62
|
+
}
|
|
63
|
+
read(repoRoot) {
|
|
64
|
+
const file = this.path(repoRoot);
|
|
65
|
+
if (!fs.existsSync(file))
|
|
66
|
+
return null;
|
|
67
|
+
// webpieces-disable no-any-unknown -- JSON.parse is untyped until narrowed on the next line
|
|
68
|
+
const raw = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
69
|
+
const fields = [raw.branch, raw.headSha, raw.copySha, raw.targetRef, raw.leaseSha, raw.devSha];
|
|
70
|
+
if (!fields.every((f) => typeof f === 'string'))
|
|
71
|
+
return null;
|
|
72
|
+
return new VerifiedDevCopy(raw.branch, raw.headSha, raw.copySha, raw.targetRef, raw.leaseSha, raw.devSha);
|
|
73
|
+
}
|
|
74
|
+
write(repoRoot, record) {
|
|
75
|
+
fs.mkdirSync(this.dotWebpieces.local(repoRoot), { recursive: true });
|
|
76
|
+
fs.writeFileSync(this.path(repoRoot), JSON.stringify(record, null, 2) + '\n', 'utf8');
|
|
77
|
+
}
|
|
78
|
+
clear(repoRoot) {
|
|
79
|
+
const file = this.path(repoRoot);
|
|
80
|
+
if (fs.existsSync(file))
|
|
81
|
+
fs.rmSync(file);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
exports.VerifiedDevCopyStore = VerifiedDevCopyStore;
|
|
85
|
+
exports.VerifiedDevCopyStore = VerifiedDevCopyStore = tslib_1.__decorate([
|
|
86
|
+
(0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
|
|
87
|
+
tslib_1.__metadata("design:paramtypes", [tooling_common_1.DotWebpieces])
|
|
88
|
+
], VerifiedDevCopyStore);
|
|
89
|
+
//# sourceMappingURL=verified-dev-copy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verified-dev-copy.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/verified-dev-copy.ts"],"names":[],"mappings":";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,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAEM,6BAAY;GAD9C,oBAAoB,CAuChC","sourcesContent":["import * as fs from 'fs';\n\nimport { DotWebpieces } from '@webpieces/tooling-common';\nimport { injectable, bindingScopeValues } from 'inversify';\n\n/** The local state file stage ② writes and stage ③ consumes. LOCAL scope: one worktree's verification. */\nexport const PUSH_DEV_VERIFIED_FILE = 'push-dev-verified.json';\n\n/**\n * What `wp-build-push-dev` (stage ②) verified, for `wp-finish-push-dev` (stage ③) to publish (#1403).\n *\n * The same hand-off the PR flow makes between `wp-review-upsert-pr` and `wp-finish-upsert-pr`: stage ②\n * records the sha it built, and stage ③ refuses when HEAD moved since — so what is published is exactly\n * what was checked against dev and built, never a later commit nobody built.\n *\n * Data-only (per CLAUDE.md) — the behaviour lives in {@link VerifiedDevCopyStore}.\n */\nexport class VerifiedDevCopy {\n /** The feature branch that was verified. */\n branch: string;\n /** The feature head the copy is built on. Stage ③ refuses when HEAD is no longer this. */\n headSha: string;\n /** What stage ③ publishes: `headSha`, or `headSha` plus ONE commit recording the resolved files. */\n copySha: string;\n /** `<namespace>/<branch>` — where stage ③ publishes. */\n targetRef: string;\n /** The remote copy's sha when stage ② ran ('' = not published yet) — stage ③'s push lease. */\n leaseSha: string;\n /** The `origin/<devBranch>` sha the copy was merged with and built against; '' when dev did not exist. */\n devSha: string;\n\n constructor(branch: string, headSha: string, copySha: string, targetRef: string, leaseSha: string, devSha: string) {\n this.branch = branch;\n this.headSha = headSha;\n this.copySha = copySha;\n this.targetRef = targetRef;\n this.leaseSha = leaseSha;\n this.devSha = devSha;\n }\n}\n\n/**\n * Reads, writes and clears the stage-② record. A missing or unreadable record reads as null, which stage ③\n * turns into \"run `pnpm wp-build-push-dev` first\".\n */\n@injectable(bindingScopeValues.Singleton)\nexport class VerifiedDevCopyStore {\n constructor(private readonly dotWebpieces: DotWebpieces) {}\n\n path(repoRoot: string): string {\n return this.dotWebpieces.localFile(repoRoot, PUSH_DEV_VERIFIED_FILE);\n }\n\n /**\n * The local ref that keeps the verified copy reachable between stage ② and stage ③. When something\n * conflicted, the copy is a commit on top of the feature head that no branch points at; without a ref\n * holding it, `git gc` could collect it before it is published. Outside `refs/heads/`, so it is never\n * mistaken for a branch (and never counts toward the branch cap or reaches `wp-cleanup`).\n */\n keepRef(branch: string): string {\n return `refs/webpieces/push-dev/${branch}`;\n }\n\n read(repoRoot: string): VerifiedDevCopy | null {\n const file = this.path(repoRoot);\n if (!fs.existsSync(file)) return null;\n // webpieces-disable no-any-unknown -- JSON.parse is untyped until narrowed on the next line\n const raw = JSON.parse(fs.readFileSync(file, 'utf8')) as Partial<VerifiedDevCopy>;\n const fields = [raw.branch, raw.headSha, raw.copySha, raw.targetRef, raw.leaseSha, raw.devSha];\n if (!fields.every((f: string | undefined): boolean => typeof f === 'string')) return null;\n return new VerifiedDevCopy(\n raw.branch as string, raw.headSha as string, raw.copySha as string,\n raw.targetRef as string, raw.leaseSha as string, raw.devSha as string,\n );\n }\n\n write(repoRoot: string, record: VerifiedDevCopy): void {\n fs.mkdirSync(this.dotWebpieces.local(repoRoot), { recursive: true });\n fs.writeFileSync(this.path(repoRoot), JSON.stringify(record, null, 2) + '\\n', 'utf8');\n }\n\n clear(repoRoot: string): void {\n const file = this.path(repoRoot);\n if (fs.existsSync(file)) fs.rmSync(file);\n }\n}\n"]}
|
|
@@ -9,5 +9,5 @@ const pr_gate_cli_invocation_1 = require("./pr-gate-cli-invocation");
|
|
|
9
9
|
const container = new pr_gate_container_1.PrGateContainer().create();
|
|
10
10
|
(0, rules_config_1.runMain)(() => container
|
|
11
11
|
.get(pr_gate_cli_app_1.PrGateCliApp)
|
|
12
|
-
.run(container.get(pr_gate_cli_invocation_1.PrGateCliInvocationFactory).fromProcess('wp-build-dev')));
|
|
13
|
-
//# sourceMappingURL=wp-build-dev.js.map
|
|
12
|
+
.run(container.get(pr_gate_cli_invocation_1.PrGateCliInvocationFactory).fromProcess('wp-build-push-dev')));
|
|
13
|
+
//# sourceMappingURL=wp-build-push-dev.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wp-build-push-dev.js","sourceRoot":"","sources":["../../../../../../packages/tooling/pr-gate/src/scripts/wp-build-push-dev.ts"],"names":[],"mappings":";;;AACA,4BAA0B;AAC1B,0DAAkD;AAClD,2DAAsD;AACtD,uDAAiD;AACjD,qEAAsE;AAEtE,MAAM,SAAS,GAAG,IAAI,mCAAe,EAAE,CAAC,MAAM,EAAE,CAAC;AACjD,IAAA,sBAAO,EACH,GAAkB,EAAE,CAChB,SAAS;KACJ,GAAG,CAAC,8BAAY,CAAC;KACjB,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,mDAA0B,CAAC,CAAC,WAAW,CAAC,mBAAmB,CAAC,CAAC,CAC3F,CAAC","sourcesContent":["#!/usr/bin/env node\nimport 'reflect-metadata';\nimport { runMain } from '@webpieces/rules-config';\nimport { PrGateContainer } from './pr-gate-container';\nimport { PrGateCliApp } from './pr-gate-cli-app';\nimport { PrGateCliInvocationFactory } from './pr-gate-cli-invocation';\n\nconst container = new PrGateContainer().create();\nrunMain(\n (): Promise<void> =>\n container\n .get(PrGateCliApp)\n .run(container.get(PrGateCliInvocationFactory).fromProcess('wp-build-push-dev')),\n);\n"]}
|
|
@@ -9,5 +9,5 @@ const pr_gate_cli_invocation_1 = require("./pr-gate-cli-invocation");
|
|
|
9
9
|
const container = new pr_gate_container_1.PrGateContainer().create();
|
|
10
10
|
(0, rules_config_1.runMain)(() => container
|
|
11
11
|
.get(pr_gate_cli_app_1.PrGateCliApp)
|
|
12
|
-
.run(container.get(pr_gate_cli_invocation_1.PrGateCliInvocationFactory).fromProcess('wp-push-dev')));
|
|
13
|
-
//# sourceMappingURL=wp-push-dev.js.map
|
|
12
|
+
.run(container.get(pr_gate_cli_invocation_1.PrGateCliInvocationFactory).fromProcess('wp-start-push-dev')));
|
|
13
|
+
//# sourceMappingURL=wp-start-push-dev.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wp-start-push-dev.js","sourceRoot":"","sources":["../../../../../../packages/tooling/pr-gate/src/scripts/wp-start-push-dev.ts"],"names":[],"mappings":";;;AACA,4BAA0B;AAC1B,0DAAkD;AAClD,2DAAsD;AACtD,uDAAiD;AACjD,qEAAsE;AAEtE,MAAM,SAAS,GAAG,IAAI,mCAAe,EAAE,CAAC,MAAM,EAAE,CAAC;AACjD,IAAA,sBAAO,EACH,GAAkB,EAAE,CAChB,SAAS;KACJ,GAAG,CAAC,8BAAY,CAAC;KACjB,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,mDAA0B,CAAC,CAAC,WAAW,CAAC,mBAAmB,CAAC,CAAC,CAC3F,CAAC","sourcesContent":["#!/usr/bin/env node\nimport 'reflect-metadata';\nimport { runMain } from '@webpieces/rules-config';\nimport { PrGateContainer } from './pr-gate-container';\nimport { PrGateCliApp } from './pr-gate-cli-app';\nimport { PrGateCliInvocationFactory } from './pr-gate-cli-invocation';\n\nconst container = new PrGateContainer().create();\nrunMain(\n (): Promise<void> =>\n container\n .get(PrGateCliApp)\n .run(container.get(PrGateCliInvocationFactory).fromProcess('wp-start-push-dev')),\n);\n"]}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { RepoRootFinder } from '@webpieces/rules-config';
|
|
2
|
-
import { GitExec } from '../workflow/git-exec';
|
|
3
|
-
import { DevDeployRefs } from '../workflow/dev-deploy-refs';
|
|
4
|
-
import { DevBuild } from '../workflow/dev-build';
|
|
5
|
-
/**
|
|
6
|
-
* `wp-build-dev` — the check `wp-push-dev` runs before it publishes, WITHOUT the publish (#1397).
|
|
7
|
-
*
|
|
8
|
-
* It merges `origin/<devBranch>` into a throwaway branch and runs `commands.push-dev.buildCommand` on the
|
|
9
|
-
* merged tree, then puts the checkout back. That is the cheap, honest form of the question a developer
|
|
10
|
-
* wants answered before publishing: does this branch build once it meets what is already on dev? Built on
|
|
11
|
-
* the feature branch itself, a `--base=origin/dev` build would also rebuild every project the OTHER copies
|
|
12
|
-
* on dev touched, because they differ from the feature branch too.
|
|
13
|
-
*
|
|
14
|
-
* It RESOLVES NOTHING. A conflict aborts the throwaway merge and names the files; resolving them is
|
|
15
|
-
* `wp-push-dev`'s job, because a resolution is only worth anything once it is recorded on the published
|
|
16
|
-
* copy. The feature branch is never written to, by the same rule as every other dev-deploy command.
|
|
17
|
-
*/
|
|
18
|
-
export declare class BuildDevCommand {
|
|
19
|
-
private readonly repoRootFinder;
|
|
20
|
-
private readonly gitExec;
|
|
21
|
-
private readonly refs;
|
|
22
|
-
private readonly devBuild;
|
|
23
|
-
constructor(repoRootFinder: RepoRootFinder, gitExec: GitExec, refs: DevDeployRefs, devBuild: DevBuild);
|
|
24
|
-
run(): Promise<void>;
|
|
25
|
-
private refuseConflict;
|
|
26
|
-
private restore;
|
|
27
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BuildDevCommand = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const rules_config_1 = require("@webpieces/rules-config");
|
|
6
|
-
const to_error_1 = require("@webpieces/tooling-common/to-error");
|
|
7
|
-
const inversify_1 = require("inversify");
|
|
8
|
-
const git_exec_1 = require("../workflow/git-exec");
|
|
9
|
-
const dev_deploy_refs_1 = require("../workflow/dev-deploy-refs");
|
|
10
|
-
const dev_build_1 = require("../workflow/dev-build");
|
|
11
|
-
const SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n';
|
|
12
|
-
/**
|
|
13
|
-
* `wp-build-dev` — the check `wp-push-dev` runs before it publishes, WITHOUT the publish (#1397).
|
|
14
|
-
*
|
|
15
|
-
* It merges `origin/<devBranch>` into a throwaway branch and runs `commands.push-dev.buildCommand` on the
|
|
16
|
-
* merged tree, then puts the checkout back. That is the cheap, honest form of the question a developer
|
|
17
|
-
* wants answered before publishing: does this branch build once it meets what is already on dev? Built on
|
|
18
|
-
* the feature branch itself, a `--base=origin/dev` build would also rebuild every project the OTHER copies
|
|
19
|
-
* on dev touched, because they differ from the feature branch too.
|
|
20
|
-
*
|
|
21
|
-
* It RESOLVES NOTHING. A conflict aborts the throwaway merge and names the files; resolving them is
|
|
22
|
-
* `wp-push-dev`'s job, because a resolution is only worth anything once it is recorded on the published
|
|
23
|
-
* copy. The feature branch is never written to, by the same rule as every other dev-deploy command.
|
|
24
|
-
*/
|
|
25
|
-
let BuildDevCommand = class BuildDevCommand {
|
|
26
|
-
repoRootFinder;
|
|
27
|
-
gitExec;
|
|
28
|
-
refs;
|
|
29
|
-
devBuild;
|
|
30
|
-
constructor(repoRootFinder, gitExec, refs, devBuild) {
|
|
31
|
-
this.repoRootFinder = repoRootFinder;
|
|
32
|
-
this.gitExec = gitExec;
|
|
33
|
-
this.refs = refs;
|
|
34
|
-
this.devBuild = devBuild;
|
|
35
|
-
}
|
|
36
|
-
async run() {
|
|
37
|
-
const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());
|
|
38
|
-
(0, rules_config_1.writeTemplate)(repoRoot, 'webpieces.git-workflow.md');
|
|
39
|
-
const cfg = this.refs.config(repoRoot);
|
|
40
|
-
const branch = this.refs.currentBranch(repoRoot);
|
|
41
|
-
this.refs.assertPushable(cfg, branch);
|
|
42
|
-
// Before any git write: an unconfigured dev build refuses here.
|
|
43
|
-
this.devBuild.command(repoRoot);
|
|
44
|
-
// The merge below must be of committed work only, and must not sweep uncommitted edits along.
|
|
45
|
-
await this.gitExec.assertCleanTree(repoRoot);
|
|
46
|
-
if (await this.refs.remoteSha(repoRoot, cfg.devBranch) === '') {
|
|
47
|
-
throw new rules_config_1.CliExitError(2, '\n' + SEP + `⛔ \`origin/${cfg.devBranch}\` does not exist yet\n` + SEP + '\n'
|
|
48
|
-
+ `There is nothing to build against. ${rules_config_1.WP_PUSH_DEV} publishes your copy without this check while\n`
|
|
49
|
-
+ `\`${cfg.devBranch}\` does not exist, and your CI creates it on its first composition run.\n`);
|
|
50
|
-
}
|
|
51
|
-
await this.refs.fetchCopies(repoRoot, [cfg.devBranch]);
|
|
52
|
-
const tmp = `${branch}DevCheck`;
|
|
53
|
-
await this.gitExec.runGitChecked(['-C', repoRoot, 'checkout', '-B', tmp, 'HEAD'], `Failed to create the throwaway check branch ${tmp}`);
|
|
54
|
-
const merged = await this.gitExec.tryGit(['-C', repoRoot, 'merge', '--no-ff', '--no-edit', '-m',
|
|
55
|
-
`Dev-check: merge ${cfg.devBranch} into ${tmp}`, `refs/remotes/origin/${cfg.devBranch}`], repoRoot);
|
|
56
|
-
if (!merged.ok)
|
|
57
|
-
await this.refuseConflict(repoRoot, branch, tmp, cfg.devBranch);
|
|
58
|
-
// webpieces-disable no-unmanaged-exceptions -- chokepoint: the checkout must go back to the feature branch whether or not the build passed; the build's own CliExitError is re-thrown unchanged
|
|
59
|
-
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
60
|
-
try {
|
|
61
|
-
await this.devBuild.run(repoRoot, rules_config_1.WP_BUILD_DEV);
|
|
62
|
-
}
|
|
63
|
-
catch (err) {
|
|
64
|
-
const error = (0, to_error_1.toError)(err);
|
|
65
|
-
await this.restore(repoRoot, branch, tmp);
|
|
66
|
-
throw error;
|
|
67
|
-
}
|
|
68
|
-
await this.restore(repoRoot, branch, tmp);
|
|
69
|
-
process.stdout.write(`\n\`${branch}\` merges cleanly with origin/${cfg.devBranch} and the dev build is green.\n`
|
|
70
|
-
+ `Nothing was published — ${rules_config_1.WP_PUSH_DEV} runs this same check and then publishes.\n`);
|
|
71
|
-
}
|
|
72
|
-
// A conflict: list the files, undo the merge, go back — and say which command resolves it.
|
|
73
|
-
async refuseConflict(repoRoot, branch, tmp, devBranch) {
|
|
74
|
-
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).');
|
|
75
|
-
const conflicted = out.split('\n').filter((l) => l.trim() !== '');
|
|
76
|
-
await this.gitExec.tryGit(['-C', repoRoot, 'merge', '--abort'], repoRoot);
|
|
77
|
-
await this.restore(repoRoot, branch, tmp);
|
|
78
|
-
throw new rules_config_1.CliExitError(2, '\n' + SEP + `⚠️ \`${branch}\` CONFLICTS with origin/${devBranch}\n` + SEP + '\n'
|
|
79
|
-
+ (conflicted.length === 0
|
|
80
|
-
? 'git could not merge it (no conflicted file was reported).\n'
|
|
81
|
-
: 'These files conflict:\n' + conflicted.map((f) => ` ${f}`).join('\n') + '\n')
|
|
82
|
-
+ '\nNo build ran and nothing was published; the throwaway merge is undone and you are back on\n'
|
|
83
|
-
+ `\`${branch}\`, which was never modified. ${rules_config_1.WP_PUSH_DEV} stops on these same files on a throwaway\n`
|
|
84
|
-
+ 'branch, lets you resolve them there, builds, and publishes the copy with the resolution recorded.\n');
|
|
85
|
-
}
|
|
86
|
-
async restore(repoRoot, branch, tmp) {
|
|
87
|
-
await this.gitExec.runGitChecked(['-C', repoRoot, 'checkout', branch], `Failed to return to ${branch}`);
|
|
88
|
-
await this.gitExec.tryGit(['-C', repoRoot, 'branch', '-D', tmp], repoRoot);
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
exports.BuildDevCommand = BuildDevCommand;
|
|
92
|
-
exports.BuildDevCommand = BuildDevCommand = tslib_1.__decorate([
|
|
93
|
-
(0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
|
|
94
|
-
tslib_1.__metadata("design:paramtypes", [rules_config_1.RepoRootFinder,
|
|
95
|
-
git_exec_1.GitExec,
|
|
96
|
-
dev_deploy_refs_1.DevDeployRefs,
|
|
97
|
-
dev_build_1.DevBuild])
|
|
98
|
-
], BuildDevCommand);
|
|
99
|
-
//# sourceMappingURL=build-dev-command.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"build-dev-command.js","sourceRoot":"","sources":["../../../../../../../packages/too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,0BAAW,6CAA6C;cACpG,qGAAqG,CAAC,CAAC;IACjH,CAAC;IAEO,KAAK,CAAC,OAAO,CAAC,QAAgB,EAAE,MAAc,EAAE,GAAW;QAC/D,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,uBAAuB,MAAM,EAAE,CAAC,CAAC;QACxG,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,CAAC,EAAE,QAAQ,CAAC,CAAC;IAC/E,CAAC;CACJ,CAAA;AArEY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QACrB,kBAAO;QACV,+BAAa;QACT,oBAAQ;GAL9B,eAAe,CAqE3B","sourcesContent":["import { CliExitError, RepoRootFinder, WP_BUILD_DEV, WP_PUSH_DEV, writeTemplate } from '@webpieces/rules-config';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { GitExec } from '../workflow/git-exec';\nimport { DevDeployRefs } from '../workflow/dev-deploy-refs';\nimport { DevBuild } from '../workflow/dev-build';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * `wp-build-dev` — the check `wp-push-dev` runs before it publishes, WITHOUT the publish (#1397).\n *\n * It merges `origin/<devBranch>` into a throwaway branch and runs `commands.push-dev.buildCommand` on the\n * merged tree, then puts the checkout back. That is the cheap, honest form of the question a developer\n * wants answered before publishing: does this branch build once it meets what is already on dev? Built on\n * the feature branch itself, a `--base=origin/dev` build would also rebuild every project the OTHER copies\n * on dev touched, because they differ from the feature branch too.\n *\n * It RESOLVES NOTHING. A conflict aborts the throwaway merge and names the files; resolving them is\n * `wp-push-dev`'s job, because a resolution is only worth anything once it is recorded on the published\n * copy. The feature branch is never written to, by the same rule as every other dev-deploy command.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class BuildDevCommand {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly gitExec: GitExec,\n private readonly refs: DevDeployRefs,\n private readonly devBuild: DevBuild,\n ) {}\n\n async run(): Promise<void> {\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n writeTemplate(repoRoot, 'webpieces.git-workflow.md');\n const cfg = this.refs.config(repoRoot);\n const branch = this.refs.currentBranch(repoRoot);\n this.refs.assertPushable(cfg, branch);\n // Before any git write: an unconfigured dev build refuses here.\n this.devBuild.command(repoRoot);\n // The merge below must be of committed work only, and must not sweep uncommitted edits along.\n await this.gitExec.assertCleanTree(repoRoot);\n if (await this.refs.remoteSha(repoRoot, cfg.devBranch) === '') {\n throw new CliExitError(2,\n '\\n' + SEP + `⛔ \\`origin/${cfg.devBranch}\\` does not exist yet\\n` + SEP + '\\n'\n + `There is nothing to build against. ${WP_PUSH_DEV} publishes your copy without this check while\\n`\n + `\\`${cfg.devBranch}\\` does not exist, and your CI creates it on its first composition run.\\n`);\n }\n await this.refs.fetchCopies(repoRoot, [cfg.devBranch]);\n const tmp = `${branch}DevCheck`;\n await this.gitExec.runGitChecked(['-C', repoRoot, 'checkout', '-B', tmp, 'HEAD'],\n `Failed to create the throwaway check branch ${tmp}`);\n const merged = await this.gitExec.tryGit(\n ['-C', repoRoot, 'merge', '--no-ff', '--no-edit', '-m',\n `Dev-check: merge ${cfg.devBranch} into ${tmp}`, `refs/remotes/origin/${cfg.devBranch}`],\n repoRoot);\n if (!merged.ok) await this.refuseConflict(repoRoot, branch, tmp, cfg.devBranch);\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: the checkout must go back to the feature branch whether or not the build passed; the build's own CliExitError is re-thrown unchanged\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n await this.devBuild.run(repoRoot, WP_BUILD_DEV);\n } catch (err: unknown) {\n const error = toError(err);\n await this.restore(repoRoot, branch, tmp);\n throw error;\n }\n await this.restore(repoRoot, branch, tmp);\n process.stdout.write(\n `\\n\\`${branch}\\` merges cleanly with origin/${cfg.devBranch} and the dev build is green.\\n`\n + `Nothing was published — ${WP_PUSH_DEV} runs this same check and then publishes.\\n`);\n }\n\n // A conflict: list the files, undo the merge, go back — and say which command resolves it.\n private async refuseConflict(repoRoot: string, branch: string, tmp: string, devBranch: string): Promise<never> {\n const out = await this.gitExec.gitQuery(['-C', repoRoot, 'diff', '--name-only', '--diff-filter=U'], repoRoot,\n 'Failed to list the conflicted files (git diff --name-only --diff-filter=U).');\n const conflicted = out.split('\\n').filter((l: string): boolean => l.trim() !== '');\n await this.gitExec.tryGit(['-C', repoRoot, 'merge', '--abort'], repoRoot);\n await this.restore(repoRoot, branch, tmp);\n throw new CliExitError(2,\n '\\n' + SEP + `⚠️ \\`${branch}\\` CONFLICTS with origin/${devBranch}\\n` + SEP + '\\n'\n + (conflicted.length === 0\n ? 'git could not merge it (no conflicted file was reported).\\n'\n : 'These files conflict:\\n' + conflicted.map((f: string): string => ` ${f}`).join('\\n') + '\\n')\n + '\\nNo build ran and nothing was published; the throwaway merge is undone and you are back on\\n'\n + `\\`${branch}\\`, which was never modified. ${WP_PUSH_DEV} stops on these same files on a throwaway\\n`\n + 'branch, lets you resolve them there, builds, and publishes the copy with the resolution recorded.\\n');\n }\n\n private async restore(repoRoot: string, branch: string, tmp: string): Promise<void> {\n await this.gitExec.runGitChecked(['-C', repoRoot, 'checkout', branch], `Failed to return to ${branch}`);\n await this.gitExec.tryGit(['-C', repoRoot, 'branch', '-D', tmp], repoRoot);\n }\n}\n"]}
|