@webpieces/pr-gate 0.4.983 → 0.4.985
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 +61 -0
- package/src/scripts/commands/build-push-dev-command.js +159 -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.js +2 -2
- package/src/scripts/workflow/build-gate-log.js.map +1 -1
- package/src/scripts/workflow/dev-build.js +2 -2
- package/src/scripts/workflow/dev-build.js.map +1 -1
- package/src/scripts/workflow/dev-copy-on-main.d.ts +49 -0
- package/src/scripts/workflow/dev-copy-on-main.js +99 -0
- package/src/scripts/workflow/dev-copy-on-main.js.map +1 -0
- 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 +43 -73
- package/src/scripts/workflow/dev-resolve-runner.js +117 -181
- package/src/scripts/workflow/dev-resolve-runner.js.map +1 -1
- 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 -124
- package/src/scripts/commands/push-dev-command.js +0 -318
- 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,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/tooling/pr-gate/src/scripts/commands/build-dev-command.ts"],"names":[],"mappings":"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","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"]}
|
|
@@ -1,124 +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 { PushDevStateStore } from '../workflow/push-dev-state';
|
|
5
|
-
import { DevResolveRunner } from '../workflow/dev-resolve-runner';
|
|
6
|
-
import { DevDeployWatchHints } from '../workflow/dev-deploy-watch-hints';
|
|
7
|
-
import { DevBuild } from '../workflow/dev-build';
|
|
8
|
-
/**
|
|
9
|
-
* Which of `wp-push-dev`'s modes was asked for. Data-only (per CLAUDE.md) with plain assigned fields
|
|
10
|
-
* rather than a seven-argument constructor — the bin sets what argv carried and nothing else.
|
|
11
|
-
*/
|
|
12
|
-
export declare class PushDevOptions {
|
|
13
|
-
/** Delete the remote copy — the rollback. */
|
|
14
|
-
remove: boolean;
|
|
15
|
-
/** List the live copies and stop. The one mode that needs no branch preconditions. */
|
|
16
|
-
list: boolean;
|
|
17
|
-
/** Discard a conflict resolution already published on the copy, and overwrite it. */
|
|
18
|
-
force: boolean;
|
|
19
|
-
/** Replay that resolution on top of the new local commits instead of discarding it. */
|
|
20
|
-
rebaseResolution: boolean;
|
|
21
|
-
/** Compose the other copies onto this one so the shared environment can build them together. */
|
|
22
|
-
resolve: boolean;
|
|
23
|
-
/** With `--resolve`: merge ONLY this developer's branch. Empty ⇒ every other copy. */
|
|
24
|
-
resolveTarget: string;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* `wp-push-dev` — publish a DISPOSABLE copy of this branch so a shared dev environment can build it,
|
|
28
|
-
* without landing anything on `main` and without opening a PR.
|
|
29
|
-
*
|
|
30
|
-
* WHY THIS COMMAND HAS TO EXIST AT ALL: `pr-creation-or-push-guard` blocks every `git push`, no
|
|
31
|
-
* exceptions, by design. Its own fix-hint offers "ask a human to run the push" for out-of-band cases —
|
|
32
|
-
* which is the right answer for a genuine exception and the wrong one for a routine daily action. Without
|
|
33
|
-
* a gated command there is simply no legal way for an AI to get a branch onto a dev server, so the
|
|
34
|
-
* feature was undoable rather than merely awkward.
|
|
35
|
-
*
|
|
36
|
-
* WHY IT CHECKS AGAINST `dev` FIRST (#1397): 61 of 73 failed dev publishes on one consumer failed on a git
|
|
37
|
-
* conflict, which the developer only learned about after the server-side composition failed. So a plain
|
|
38
|
-
* publish now does locally what CI is about to do: merge `origin/<devBranch>` into a THROWAWAY branch,
|
|
39
|
-
* resolve any conflict there (the same halt / `wp-finish-push-dev` state machine `--resolve` uses), and run
|
|
40
|
-
* `commands.push-dev.buildCommand` on the merged tree. A build against `main` alone would prove the wrong
|
|
41
|
-
* thing; a build of only what differs from `dev` proves the right one, quickly.
|
|
42
|
-
*
|
|
43
|
-
* WHAT IS PUBLISHED IS NEVER THAT MERGE: the copy is the feature head plus, when something conflicted, one
|
|
44
|
-
* commit recording the resolved files (DevResolveRunner.recordResolution). A copy that contained `dev`
|
|
45
|
-
* would carry every other copy's history, and a later `--remove` of one of them would leave it on dev
|
|
46
|
-
* through this one.
|
|
47
|
-
*
|
|
48
|
-
* WHAT IT NEVER DOES: touch the feature branch. See DevDeployRefs for the invariant and why the copy
|
|
49
|
-
* exists to hold conflict resolutions that must not reach the PR.
|
|
50
|
-
*/
|
|
51
|
-
export declare class PushDevCommand {
|
|
52
|
-
private readonly repoRootFinder;
|
|
53
|
-
private readonly gitExec;
|
|
54
|
-
private readonly refs;
|
|
55
|
-
private readonly store;
|
|
56
|
-
private readonly runner;
|
|
57
|
-
private readonly watchHints;
|
|
58
|
-
private readonly devBuild;
|
|
59
|
-
constructor(repoRootFinder: RepoRootFinder, gitExec: GitExec, refs: DevDeployRefs, store: PushDevStateStore, runner: DevResolveRunner, watchHints: DevDeployWatchHints, devBuild: DevBuild);
|
|
60
|
-
run(opts: PushDevOptions): Promise<void>;
|
|
61
|
-
/** `--list`: exactly the live copies, straight from the remote — never a cached local view. */
|
|
62
|
-
private list;
|
|
63
|
-
/**
|
|
64
|
-
* `--remove`: delete the remote copy, then push the `<removeNamespace>/<branch>` marker (#1395). This
|
|
65
|
-
* IS the rollback — nothing else has to be undone.
|
|
66
|
-
*
|
|
67
|
-
* WHY A MARKER AS WELL AS THE DELETION: a deletion can only be heard by a workflow's `on: delete:`,
|
|
68
|
-
* which GitHub cannot filter by branch, so every branch deletion in the repo started a dev-deploy run.
|
|
69
|
-
* A PUSH to `<removeNamespace>/**` is filterable. The deletion stays, unchanged, so a consumer whose
|
|
70
|
-
* workflow still listens on `delete:` keeps working through the rollout window; the marker is purely
|
|
71
|
-
* additive at the transport level.
|
|
72
|
-
*
|
|
73
|
-
* ORDER: `origin/main` is fetched BEFORE anything is deleted, so a network failure there leaves the
|
|
74
|
-
* pool exactly as it was. The marker push is the last step, and the only one that can fail with the
|
|
75
|
-
* copy already gone — that is the state {@link markerPushFailed} names.
|
|
76
|
-
*/
|
|
77
|
-
private remove;
|
|
78
|
-
/**
|
|
79
|
-
* The one half-done state `--remove` can leave: the copy is deleted, the rebuild signal is not sent.
|
|
80
|
-
* Said out loud because it is invisible otherwise — `--list` already looks right, while the deployed
|
|
81
|
-
* `dev` still runs the removed branch until something else triggers a composition.
|
|
82
|
-
*/
|
|
83
|
-
private markerPushFailed;
|
|
84
|
-
/**
|
|
85
|
-
* The ordinary path: check the copy against `origin/<devBranch>`, build it, then publish it as
|
|
86
|
-
* `<namespace>/<branch>` (#1397). The merge, the conflict halt and the build all happen on a throwaway
|
|
87
|
-
* branch through DevResolveRunner, in DevResolveMode.PREBUILD — so a conflict stops in exactly the
|
|
88
|
-
* same `wp-finish-push-dev` state machine `--resolve` uses, rather than inventing a second way to be
|
|
89
|
-
* stuck.
|
|
90
|
-
*
|
|
91
|
-
* THE CLOBBER GUARD runs first. If the remote copy holds commits the local branch does not, somebody
|
|
92
|
-
* (quite possibly this developer, days ago) put real work there, and a silent force-push destroys it,
|
|
93
|
-
* so the default is refusal with two named ways forward — never a "use --force" one-liner, which is how
|
|
94
|
-
* a warning becomes a reflex. The one exception is a commit this flow wrote itself
|
|
95
|
-
* ({@link RESOLUTION_SUBJECT}): the check below re-derives it against today's dev, so replacing it
|
|
96
|
-
* loses nothing.
|
|
97
|
-
*/
|
|
98
|
-
private publish;
|
|
99
|
-
/**
|
|
100
|
-
* `origin/<devBranch>` does not exist yet — the very first publish in a repo whose CI has never
|
|
101
|
-
* composed. There is nothing to conflict with and no base for a dev-scoped build, so the copy is
|
|
102
|
-
* published as it is; refusing here would make the first dev composition impossible to start.
|
|
103
|
-
*/
|
|
104
|
-
private publishWithoutDev;
|
|
105
|
-
/**
|
|
106
|
-
* `--rebase-resolution`: keep the published resolution, replay it on top of the new commits.
|
|
107
|
-
*
|
|
108
|
-
* Implemented as a resolve whose BASE is the local HEAD and whose queue is the copy itself, so a
|
|
109
|
-
* replay that conflicts again lands in exactly the same halt/`wp-finish-push-dev` state machine as
|
|
110
|
-
* any other conflict, rather than inventing a second way to be stuck.
|
|
111
|
-
*/
|
|
112
|
-
private rebaseResolution;
|
|
113
|
-
/**
|
|
114
|
-
* `--resolve`: compose the other copies onto this one, so what is published is what CI will build.
|
|
115
|
-
*
|
|
116
|
-
* With no argument the queue is EVERY other copy, in the same sorted order CI composes them — the
|
|
117
|
-
* local resolution is then a rehearsal of the real composition, not a guess at it. With an argument
|
|
118
|
-
* (the branch a CI conflict message names) it is just that one.
|
|
119
|
-
*/
|
|
120
|
-
private startResolve;
|
|
121
|
-
private resolveQueue;
|
|
122
|
-
private refuseClobber;
|
|
123
|
-
private assertNoResolveInProgress;
|
|
124
|
-
}
|
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PushDevCommand = exports.PushDevOptions = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const rules_config_1 = require("@webpieces/rules-config");
|
|
6
|
-
const inversify_1 = require("inversify");
|
|
7
|
-
const git_exec_1 = require("../workflow/git-exec");
|
|
8
|
-
const dev_deploy_refs_1 = require("../workflow/dev-deploy-refs");
|
|
9
|
-
const push_dev_state_1 = require("../workflow/push-dev-state");
|
|
10
|
-
const dev_resolve_runner_1 = require("../workflow/dev-resolve-runner");
|
|
11
|
-
const dev_deploy_watch_hints_1 = require("../workflow/dev-deploy-watch-hints");
|
|
12
|
-
const dev_build_1 = require("../workflow/dev-build");
|
|
13
|
-
const SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n';
|
|
14
|
-
/**
|
|
15
|
-
* Which of `wp-push-dev`'s modes was asked for. Data-only (per CLAUDE.md) with plain assigned fields
|
|
16
|
-
* rather than a seven-argument constructor — the bin sets what argv carried and nothing else.
|
|
17
|
-
*/
|
|
18
|
-
class PushDevOptions {
|
|
19
|
-
/** Delete the remote copy — the rollback. */
|
|
20
|
-
remove = false;
|
|
21
|
-
/** List the live copies and stop. The one mode that needs no branch preconditions. */
|
|
22
|
-
list = false;
|
|
23
|
-
/** Discard a conflict resolution already published on the copy, and overwrite it. */
|
|
24
|
-
force = false;
|
|
25
|
-
/** Replay that resolution on top of the new local commits instead of discarding it. */
|
|
26
|
-
rebaseResolution = false;
|
|
27
|
-
/** Compose the other copies onto this one so the shared environment can build them together. */
|
|
28
|
-
resolve = false;
|
|
29
|
-
/** With `--resolve`: merge ONLY this developer's branch. Empty ⇒ every other copy. */
|
|
30
|
-
resolveTarget = '';
|
|
31
|
-
}
|
|
32
|
-
exports.PushDevOptions = PushDevOptions;
|
|
33
|
-
/**
|
|
34
|
-
* `wp-push-dev` — publish a DISPOSABLE copy of this branch so a shared dev environment can build it,
|
|
35
|
-
* without landing anything on `main` and without opening a PR.
|
|
36
|
-
*
|
|
37
|
-
* WHY THIS COMMAND HAS TO EXIST AT ALL: `pr-creation-or-push-guard` blocks every `git push`, no
|
|
38
|
-
* exceptions, by design. Its own fix-hint offers "ask a human to run the push" for out-of-band cases —
|
|
39
|
-
* which is the right answer for a genuine exception and the wrong one for a routine daily action. Without
|
|
40
|
-
* a gated command there is simply no legal way for an AI to get a branch onto a dev server, so the
|
|
41
|
-
* feature was undoable rather than merely awkward.
|
|
42
|
-
*
|
|
43
|
-
* WHY IT CHECKS AGAINST `dev` FIRST (#1397): 61 of 73 failed dev publishes on one consumer failed on a git
|
|
44
|
-
* conflict, which the developer only learned about after the server-side composition failed. So a plain
|
|
45
|
-
* publish now does locally what CI is about to do: merge `origin/<devBranch>` into a THROWAWAY branch,
|
|
46
|
-
* resolve any conflict there (the same halt / `wp-finish-push-dev` state machine `--resolve` uses), and run
|
|
47
|
-
* `commands.push-dev.buildCommand` on the merged tree. A build against `main` alone would prove the wrong
|
|
48
|
-
* thing; a build of only what differs from `dev` proves the right one, quickly.
|
|
49
|
-
*
|
|
50
|
-
* WHAT IS PUBLISHED IS NEVER THAT MERGE: the copy is the feature head plus, when something conflicted, one
|
|
51
|
-
* commit recording the resolved files (DevResolveRunner.recordResolution). A copy that contained `dev`
|
|
52
|
-
* would carry every other copy's history, and a later `--remove` of one of them would leave it on dev
|
|
53
|
-
* through this one.
|
|
54
|
-
*
|
|
55
|
-
* WHAT IT NEVER DOES: touch the feature branch. See DevDeployRefs for the invariant and why the copy
|
|
56
|
-
* exists to hold conflict resolutions that must not reach the PR.
|
|
57
|
-
*/
|
|
58
|
-
let PushDevCommand = class PushDevCommand {
|
|
59
|
-
repoRootFinder;
|
|
60
|
-
gitExec;
|
|
61
|
-
refs;
|
|
62
|
-
store;
|
|
63
|
-
runner;
|
|
64
|
-
watchHints;
|
|
65
|
-
devBuild;
|
|
66
|
-
constructor(repoRootFinder, gitExec, refs, store, runner, watchHints, devBuild) {
|
|
67
|
-
this.repoRootFinder = repoRootFinder;
|
|
68
|
-
this.gitExec = gitExec;
|
|
69
|
-
this.refs = refs;
|
|
70
|
-
this.store = store;
|
|
71
|
-
this.runner = runner;
|
|
72
|
-
this.watchHints = watchHints;
|
|
73
|
-
this.devBuild = devBuild;
|
|
74
|
-
}
|
|
75
|
-
async run(opts) {
|
|
76
|
-
const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());
|
|
77
|
-
// Refresh the AI-facing workflow doc so it is present + current for any failure message to cite —
|
|
78
|
-
// same reason every other wp-* command opens this way.
|
|
79
|
-
(0, rules_config_1.writeTemplate)(repoRoot, 'webpieces.git-workflow.md');
|
|
80
|
-
const cfg = this.refs.config(repoRoot);
|
|
81
|
-
// A resolve already in flight owns the checkout; starting a second one would strand the first.
|
|
82
|
-
this.assertNoResolveInProgress(repoRoot);
|
|
83
|
-
if (opts.list) {
|
|
84
|
-
await this.list(repoRoot, cfg);
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
const branch = this.refs.currentBranch(repoRoot);
|
|
88
|
-
this.refs.assertPushable(cfg, branch);
|
|
89
|
-
const targetRef = cfg.copyRefFor(branch);
|
|
90
|
-
if (opts.remove) {
|
|
91
|
-
await this.remove(repoRoot, cfg, branch, targetRef);
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
// Every remaining mode commits or merges, so the tree must be the AI's committed work and nothing
|
|
95
|
-
// else. The tooling never commits for you.
|
|
96
|
-
await this.gitExec.assertCleanTree(repoRoot);
|
|
97
|
-
if (opts.resolve) {
|
|
98
|
-
await this.startResolve(repoRoot, cfg, branch, targetRef, opts.resolveTarget);
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
await this.publish(repoRoot, cfg, branch, targetRef, opts);
|
|
102
|
-
}
|
|
103
|
-
/** `--list`: exactly the live copies, straight from the remote — never a cached local view. */
|
|
104
|
-
async list(repoRoot, cfg) {
|
|
105
|
-
const copies = await this.refs.liveCopies(repoRoot, cfg);
|
|
106
|
-
if (copies.length === 0) {
|
|
107
|
-
process.stdout.write(`\nNo dev copies published — nothing matches \`${cfg.copyRefGlob()}\` on origin.\n`
|
|
108
|
-
+ `Publish this branch's with: ${rules_config_1.WP_PUSH_DEV}\n`);
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
let out = '\n' + SEP + `📋 ${String(copies.length)} dev cop${copies.length === 1 ? 'y' : 'ies'} on origin\n` + SEP + '\n';
|
|
112
|
-
for (const copy of copies)
|
|
113
|
-
out += ` ${copy.sha.slice(0, 8)} ${copy.ref}\n`;
|
|
114
|
-
out += `\nYour CI composes \`${cfg.devBranch}\` from origin/main plus every ref above, on every run.\n`
|
|
115
|
-
+ `Remove yours with: ${rules_config_1.WP_PUSH_DEV} --remove (deletes your copy, then pushes the content-free\n`
|
|
116
|
-
+ `\`${cfg.removeMarkerRefFor('<your-branch>')}\` marker your dev workflow triggers on and deletes)\n`;
|
|
117
|
-
process.stdout.write(out);
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* `--remove`: delete the remote copy, then push the `<removeNamespace>/<branch>` marker (#1395). This
|
|
121
|
-
* IS the rollback — nothing else has to be undone.
|
|
122
|
-
*
|
|
123
|
-
* WHY A MARKER AS WELL AS THE DELETION: a deletion can only be heard by a workflow's `on: delete:`,
|
|
124
|
-
* which GitHub cannot filter by branch, so every branch deletion in the repo started a dev-deploy run.
|
|
125
|
-
* A PUSH to `<removeNamespace>/**` is filterable. The deletion stays, unchanged, so a consumer whose
|
|
126
|
-
* workflow still listens on `delete:` keeps working through the rollout window; the marker is purely
|
|
127
|
-
* additive at the transport level.
|
|
128
|
-
*
|
|
129
|
-
* ORDER: `origin/main` is fetched BEFORE anything is deleted, so a network failure there leaves the
|
|
130
|
-
* pool exactly as it was. The marker push is the last step, and the only one that can fail with the
|
|
131
|
-
* copy already gone — that is the state {@link markerPushFailed} names.
|
|
132
|
-
*/
|
|
133
|
-
async remove(repoRoot, cfg, branch, targetRef) {
|
|
134
|
-
if (await this.refs.remoteSha(repoRoot, targetRef) === '') {
|
|
135
|
-
process.stdout.write(`\nNothing to remove — \`${targetRef}\` is not published.\n`
|
|
136
|
-
+ `List what IS published with: ${rules_config_1.WP_PUSH_DEV} --list\n`);
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
const markerRef = cfg.removeMarkerRefFor(branch);
|
|
140
|
-
const mainTip = await this.refs.freshMainTip(repoRoot);
|
|
141
|
-
await this.gitExec.runGitChecked(['-C', repoRoot, 'push', 'origin', '--delete', `refs/heads/${targetRef}`], `Failed to delete the dev copy ${targetRef}`);
|
|
142
|
-
// --force: the marker carries no content, so whatever an earlier, never-deleted marker pointed at
|
|
143
|
-
// is worthless — and refusing a non-fast-forward here would strand the rollback half-done.
|
|
144
|
-
const pushed = await this.gitExec.tryGit(['-C', repoRoot, 'push', '--force', 'origin', `${mainTip}:refs/heads/${markerRef}`], repoRoot);
|
|
145
|
-
if (!pushed.ok)
|
|
146
|
-
this.markerPushFailed(cfg, branch, targetRef, markerRef, pushed.stderr);
|
|
147
|
-
process.stdout.write('\n' + SEP + `🗑️ Removed ${targetRef}\n` + SEP + '\n'
|
|
148
|
-
+ `Pushed the marker \`${markerRef}\` (at origin/main ${mainTip.slice(0, 8)}) — your dev workflow triggers\n`
|
|
149
|
-
+ `on it, deletes it, and rebuilds \`${cfg.devBranch}\` without \`${branch}\`. Your branch and any PR on it\n`
|
|
150
|
-
+ 'are untouched.\n');
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* The one half-done state `--remove` can leave: the copy is deleted, the rebuild signal is not sent.
|
|
154
|
-
* Said out loud because it is invisible otherwise — `--list` already looks right, while the deployed
|
|
155
|
-
* `dev` still runs the removed branch until something else triggers a composition.
|
|
156
|
-
*/
|
|
157
|
-
markerPushFailed(cfg, branch, targetRef, markerRef, stderr) {
|
|
158
|
-
throw new rules_config_1.CliExitError(1, '\n' + SEP + `⛔ Removed \`${targetRef}\`, but pushing the rebuild marker \`${markerRef}\` FAILED\n` + SEP + '\n'
|
|
159
|
-
+ `Your copy is already GONE from origin, but \`${cfg.devBranch}\` was NOT rebuilt: the deployed dev server\n`
|
|
160
|
-
+ `still runs \`${branch}\` until the next composition run.\n\n`
|
|
161
|
-
+ 'git said:\n' + (stderr === '' ? ' (no output)' : stderr.split('\n').map((l) => ` ${l}`).join('\n')) + '\n\n'
|
|
162
|
-
+ 'Any later composition run drops your branch on its own, because the copy no longer exists — the next\n'
|
|
163
|
-
+ `\`${rules_config_1.WP_PUSH_DEV}\` by anyone, or a push to main if your workflow composes on that. To force one now,\n`
|
|
164
|
-
+ 'once the cause above is fixed (network, auth, a branch-protection rule on the marker namespace),\n'
|
|
165
|
-
+ 're-publish and remove again; the second remove pushes the marker:\n\n'
|
|
166
|
-
+ ` ${rules_config_1.WP_PUSH_DEV}\n ${rules_config_1.WP_PUSH_DEV} --remove\n`);
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* The ordinary path: check the copy against `origin/<devBranch>`, build it, then publish it as
|
|
170
|
-
* `<namespace>/<branch>` (#1397). The merge, the conflict halt and the build all happen on a throwaway
|
|
171
|
-
* branch through DevResolveRunner, in DevResolveMode.PREBUILD — so a conflict stops in exactly the
|
|
172
|
-
* same `wp-finish-push-dev` state machine `--resolve` uses, rather than inventing a second way to be
|
|
173
|
-
* stuck.
|
|
174
|
-
*
|
|
175
|
-
* THE CLOBBER GUARD runs first. If the remote copy holds commits the local branch does not, somebody
|
|
176
|
-
* (quite possibly this developer, days ago) put real work there, and a silent force-push destroys it,
|
|
177
|
-
* so the default is refusal with two named ways forward — never a "use --force" one-liner, which is how
|
|
178
|
-
* a warning becomes a reflex. The one exception is a commit this flow wrote itself
|
|
179
|
-
* ({@link RESOLUTION_SUBJECT}): the check below re-derives it against today's dev, so replacing it
|
|
180
|
-
* loses nothing.
|
|
181
|
-
*/
|
|
182
|
-
async publish(repoRoot, cfg, branch, targetRef, opts) {
|
|
183
|
-
const remoteSha = await this.refs.remoteSha(repoRoot, targetRef);
|
|
184
|
-
if (remoteSha !== '') {
|
|
185
|
-
await this.refs.fetchCopies(repoRoot, [targetRef]);
|
|
186
|
-
const subjects = await this.refs.subjectsOnlyOnRemote(repoRoot, targetRef);
|
|
187
|
-
const ahead = subjects.filter((s) => !s.startsWith(dev_resolve_runner_1.RESOLUTION_SUBJECT)).length;
|
|
188
|
-
if (ahead > 0 && opts.rebaseResolution) {
|
|
189
|
-
await this.rebaseResolution(repoRoot, branch, targetRef);
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
if (ahead > 0 && !opts.force)
|
|
193
|
-
this.refuseClobber(cfg, branch, targetRef, ahead);
|
|
194
|
-
}
|
|
195
|
-
// Before any git write: an unconfigured dev build refuses here, with nothing merged or published.
|
|
196
|
-
this.devBuild.command(repoRoot);
|
|
197
|
-
if (await this.refs.remoteSha(repoRoot, cfg.devBranch) === '') {
|
|
198
|
-
await this.publishWithoutDev(repoRoot, cfg, branch, targetRef, remoteSha, opts.force);
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
const state = new push_dev_state_1.PushDevState(branch, this.runner.tmpBranchFor(branch), targetRef, [cfg.devBranch]);
|
|
202
|
-
state.mode = push_dev_state_1.DevResolveMode.PREBUILD;
|
|
203
|
-
state.leaseSha = remoteSha;
|
|
204
|
-
state.force = opts.force;
|
|
205
|
-
process.stdout.write(this.runner.announcePrebuild(cfg, state));
|
|
206
|
-
await this.runner.start(repoRoot, state, 'HEAD', [cfg.devBranch]);
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* `origin/<devBranch>` does not exist yet — the very first publish in a repo whose CI has never
|
|
210
|
-
* composed. There is nothing to conflict with and no base for a dev-scoped build, so the copy is
|
|
211
|
-
* published as it is; refusing here would make the first dev composition impossible to start.
|
|
212
|
-
*/
|
|
213
|
-
async publishWithoutDev(repoRoot, cfg, branch, targetRef, remoteSha, force) {
|
|
214
|
-
const lease = remoteSha === '' ? [] : force ? ['--force'] : [`--force-with-lease=refs/heads/${targetRef}:${remoteSha}`];
|
|
215
|
-
await this.gitExec.runGitChecked(['-C', repoRoot, 'push', ...lease, 'origin', `HEAD:refs/heads/${targetRef}`], `Failed to publish the dev copy ${targetRef}`);
|
|
216
|
-
const published = await this.refs.headSha(repoRoot);
|
|
217
|
-
process.stdout.write('\n' + SEP + `✅ Published ${targetRef}\n` + SEP + '\n'
|
|
218
|
-
+ `\`origin/${cfg.devBranch}\` does not exist yet, so there was nothing to check the copy against and no\n`
|
|
219
|
-
+ `dev build ran. \`${branch}\` is now in the pool your CI composes \`${cfg.devBranch}\` from.\n\n`
|
|
220
|
-
+ ` ${rules_config_1.WP_PUSH_DEV} --list ← what else is in the pool\n`
|
|
221
|
-
+ ` ${rules_config_1.WP_PUSH_DEV} --remove ← take this branch back out\n`
|
|
222
|
-
+ this.watchHints.render(cfg, targetRef, published));
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* `--rebase-resolution`: keep the published resolution, replay it on top of the new commits.
|
|
226
|
-
*
|
|
227
|
-
* Implemented as a resolve whose BASE is the local HEAD and whose queue is the copy itself, so a
|
|
228
|
-
* replay that conflicts again lands in exactly the same halt/`wp-finish-push-dev` state machine as
|
|
229
|
-
* any other conflict, rather than inventing a second way to be stuck.
|
|
230
|
-
*/
|
|
231
|
-
async rebaseResolution(repoRoot, branch, targetRef) {
|
|
232
|
-
const state = new push_dev_state_1.PushDevState(branch, this.runner.tmpBranchFor(branch), targetRef, [targetRef]);
|
|
233
|
-
state.mode = push_dev_state_1.DevResolveMode.REPLAY;
|
|
234
|
-
process.stdout.write('\n' + SEP + `♻️ Replaying the published resolution onto \`${branch}\`\n` + SEP + '\n'
|
|
235
|
-
+ `Merging \`${targetRef}\` (which holds the resolution) into your new commits on a throwaway branch.\n`
|
|
236
|
-
+ `Your feature branch \`${branch}\` is not touched.\n\n`);
|
|
237
|
-
await this.runner.start(repoRoot, state, 'HEAD', [targetRef]);
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* `--resolve`: compose the other copies onto this one, so what is published is what CI will build.
|
|
241
|
-
*
|
|
242
|
-
* With no argument the queue is EVERY other copy, in the same sorted order CI composes them — the
|
|
243
|
-
* local resolution is then a rehearsal of the real composition, not a guess at it. With an argument
|
|
244
|
-
* (the branch a CI conflict message names) it is just that one.
|
|
245
|
-
*/
|
|
246
|
-
async startResolve(repoRoot, cfg, branch, targetRef, only) {
|
|
247
|
-
if (await this.refs.remoteSha(repoRoot, targetRef) === '') {
|
|
248
|
-
throw new rules_config_1.CliExitError(2, '\n' + SEP + `⛔ \`${targetRef}\` is not published yet\n` + SEP + '\n'
|
|
249
|
-
+ 'There is nothing to compose against. Publish your copy first, then resolve:\n'
|
|
250
|
-
+ ` ${rules_config_1.WP_PUSH_DEV}\n ${rules_config_1.WP_PUSH_DEV} --resolve\n`);
|
|
251
|
-
}
|
|
252
|
-
const queue = await this.resolveQueue(repoRoot, cfg, targetRef, only);
|
|
253
|
-
if (queue.length === 0) {
|
|
254
|
-
process.stdout.write(`\nNothing to compose — \`${targetRef}\` is the only copy in \`${cfg.copyRefGlob()}\`.\n`
|
|
255
|
-
+ `Your CI will merge it onto origin/main by itself; there is no other branch to conflict with.\n`);
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
const state = new push_dev_state_1.PushDevState(branch, this.runner.tmpBranchFor(branch), targetRef, queue);
|
|
259
|
-
state.mode = push_dev_state_1.DevResolveMode.COMPOSE;
|
|
260
|
-
process.stdout.write(this.runner.announce(cfg, state));
|
|
261
|
-
await this.runner.start(repoRoot, state, `refs/remotes/origin/${targetRef}`, [targetRef, ...queue]);
|
|
262
|
-
}
|
|
263
|
-
// The refs to merge: one named copy, or every copy that is not mine. A named branch is accepted with
|
|
264
|
-
// or without the namespace prefix, because the CI message that names it may print either.
|
|
265
|
-
async resolveQueue(repoRoot, cfg, targetRef, only) {
|
|
266
|
-
const copies = await this.refs.liveCopies(repoRoot, cfg);
|
|
267
|
-
if (only === '') {
|
|
268
|
-
return copies.filter((c) => c.ref !== targetRef).map((c) => c.ref);
|
|
269
|
-
}
|
|
270
|
-
const wanted = only.startsWith(`${cfg.branchNamespace}/`) ? only : cfg.copyRefFor(only);
|
|
271
|
-
if (wanted === targetRef) {
|
|
272
|
-
throw new rules_config_1.CliExitError(2, `\n⛔ \`${only}\` is your own copy — there is nothing to compose it with.\n`);
|
|
273
|
-
}
|
|
274
|
-
if (!copies.some((c) => c.ref === wanted)) {
|
|
275
|
-
throw new rules_config_1.CliExitError(2, '\n' + SEP + `⛔ No published copy \`${wanted}\`\n` + SEP + '\n'
|
|
276
|
-
+ `Live copies (${rules_config_1.WP_PUSH_DEV} --list):\n`
|
|
277
|
-
+ copies.map((c) => ` ${c.ref}`).join('\n') + '\n');
|
|
278
|
-
}
|
|
279
|
-
return [wanted];
|
|
280
|
-
}
|
|
281
|
-
refuseClobber(cfg, branch, targetRef, ahead) {
|
|
282
|
-
throw new rules_config_1.CliExitError(2, '\n' + SEP + `⛔ \`${targetRef}\` holds ${String(ahead)} commit(s) your branch does not\n` + SEP + '\n'
|
|
283
|
-
+ 'That is what a CONFLICT RESOLUTION looks like: somebody composed this copy against another\n'
|
|
284
|
-
+ `developer's branch so \`${cfg.devBranch}\` could build, and that work exists ONLY on the copy —\n`
|
|
285
|
-
+ 'by design, because it must never reach your feature branch or your PR.\n\n'
|
|
286
|
-
+ 'Publishing now would force-push over it and destroy it, so this command refuses. Pick one:\n\n'
|
|
287
|
-
+ ` ${rules_config_1.WP_PUSH_DEV} --rebase-resolution\n`
|
|
288
|
-
+ ' Replay that resolution on top of your new commits. Keeps the work; may ask you to\n'
|
|
289
|
-
+ ' re-resolve the parts your new commits actually changed.\n\n'
|
|
290
|
-
+ ` ${rules_config_1.WP_PUSH_DEV} --force\n`
|
|
291
|
-
+ ' Discard it and publish your branch as-is. The composition breaks again until someone\n'
|
|
292
|
-
+ ` re-resolves it with \`${rules_config_1.WP_PUSH_DEV} --resolve\`.\n\n`
|
|
293
|
-
+ `See what is on the copy: git log --oneline ${branch}..refs/remotes/origin/${targetRef}\n`);
|
|
294
|
-
}
|
|
295
|
-
// A half-finished resolve owns the checkout — it is parked on a throwaway branch, so "the current
|
|
296
|
-
// branch" is not the feature branch this command would otherwise act on.
|
|
297
|
-
assertNoResolveInProgress(repoRoot) {
|
|
298
|
-
const state = this.store.read(repoRoot);
|
|
299
|
-
if (state === null)
|
|
300
|
-
return;
|
|
301
|
-
throw new rules_config_1.CliExitError(2, '\n' + SEP + '⛔ A dev-deploy resolve is already in progress\n' + SEP + '\n'
|
|
302
|
-
+ `You are on the throwaway branch \`${state.tmpBranch}\`, mid-composition. Finish it or bail out:\n`
|
|
303
|
-
+ ` ${rules_config_1.WP_FINISH_PUSH_DEV} ← commit the resolution, resume the queue, publish\n`
|
|
304
|
-
+ ` ${rules_config_1.WP_FINISH_PUSH_DEV} --abort ← throw it away and go back to \`${state.originalBranch}\`\n`);
|
|
305
|
-
}
|
|
306
|
-
};
|
|
307
|
-
exports.PushDevCommand = PushDevCommand;
|
|
308
|
-
exports.PushDevCommand = PushDevCommand = tslib_1.__decorate([
|
|
309
|
-
(0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
|
|
310
|
-
tslib_1.__metadata("design:paramtypes", [rules_config_1.RepoRootFinder,
|
|
311
|
-
git_exec_1.GitExec,
|
|
312
|
-
dev_deploy_refs_1.DevDeployRefs,
|
|
313
|
-
push_dev_state_1.PushDevStateStore,
|
|
314
|
-
dev_resolve_runner_1.DevResolveRunner,
|
|
315
|
-
dev_deploy_watch_hints_1.DevDeployWatchHints,
|
|
316
|
-
dev_build_1.DevBuild])
|
|
317
|
-
], PushDevCommand);
|
|
318
|
-
//# sourceMappingURL=push-dev-command.js.map
|