@antelopejs/dms-antelope-cloud 0.0.0-stage → 0.1.0

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.
Files changed (224) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +447 -2
  3. package/dist/cloud-status.d.ts +13 -0
  4. package/dist/cloud-status.js +77 -0
  5. package/dist/config.d.ts +84 -0
  6. package/dist/config.js +104 -0
  7. package/dist/configured.d.ts +16 -0
  8. package/dist/configured.js +26 -0
  9. package/dist/connection/actions.d.ts +40 -0
  10. package/dist/connection/actions.js +120 -0
  11. package/dist/connection/announce.d.ts +8 -0
  12. package/dist/connection/announce.js +20 -0
  13. package/dist/connection/cloud.d.ts +60 -0
  14. package/dist/connection/cloud.js +87 -0
  15. package/dist/connection/content.d.ts +70 -0
  16. package/dist/connection/content.js +462 -0
  17. package/dist/connection/current.d.ts +26 -0
  18. package/dist/connection/current.js +28 -0
  19. package/dist/connection/device-flow.d.ts +16 -0
  20. package/dist/connection/device-flow.js +146 -0
  21. package/dist/connection/refusals.d.ts +51 -0
  22. package/dist/connection/refusals.js +85 -0
  23. package/dist/connection/repository.d.ts +28 -0
  24. package/dist/connection/repository.js +69 -0
  25. package/dist/connection/seal.d.ts +22 -0
  26. package/dist/connection/seal.js +47 -0
  27. package/dist/connection/store.d.ts +294 -0
  28. package/dist/connection/store.js +165 -0
  29. package/dist/connection/view.d.ts +39 -0
  30. package/dist/connection/view.js +39 -0
  31. package/dist/dashboard/actions.d.ts +40 -0
  32. package/dist/dashboard/actions.js +115 -0
  33. package/dist/dashboard/dockerfile.d.ts +34 -0
  34. package/dist/dashboard/dockerfile.js +71 -0
  35. package/dist/dashboard/service.d.ts +61 -0
  36. package/dist/dashboard/service.js +137 -0
  37. package/dist/dashboard/variables.d.ts +30 -0
  38. package/dist/dashboard/variables.js +34 -0
  39. package/dist/deployments/build-log.d.ts +39 -0
  40. package/dist/deployments/build-log.js +57 -0
  41. package/dist/deployments/cloud-steps.d.ts +77 -0
  42. package/dist/deployments/cloud-steps.js +132 -0
  43. package/dist/deployments/content.d.ts +61 -0
  44. package/dist/deployments/content.js +268 -0
  45. package/dist/deployments/deployment.d.ts +96 -0
  46. package/dist/deployments/deployment.js +3 -0
  47. package/dist/deployments/follow.d.ts +18 -0
  48. package/dist/deployments/follow.js +112 -0
  49. package/dist/deployments/ledger.d.ts +23 -0
  50. package/dist/deployments/ledger.js +359 -0
  51. package/dist/deployments/lifecycle.d.ts +123 -0
  52. package/dist/deployments/lifecycle.js +146 -0
  53. package/dist/deployments/live.d.ts +28 -0
  54. package/dist/deployments/live.js +54 -0
  55. package/dist/deployments/publish-read.d.ts +20 -0
  56. package/dist/deployments/publish-read.js +24 -0
  57. package/dist/deployments/refusals.d.ts +13 -0
  58. package/dist/deployments/refusals.js +35 -0
  59. package/dist/environments/actions.d.ts +86 -0
  60. package/dist/environments/actions.js +210 -0
  61. package/dist/environments/address.d.ts +60 -0
  62. package/dist/environments/address.js +149 -0
  63. package/dist/environments/content.d.ts +97 -0
  64. package/dist/environments/content.js +275 -0
  65. package/dist/environments/follower.d.ts +32 -0
  66. package/dist/environments/follower.js +114 -0
  67. package/dist/environments/pipeline.d.ts +58 -0
  68. package/dist/environments/pipeline.js +76 -0
  69. package/dist/environments/publish-targets.d.ts +18 -0
  70. package/dist/environments/publish-targets.js +55 -0
  71. package/dist/environments/roles.d.ts +73 -0
  72. package/dist/environments/roles.js +97 -0
  73. package/dist/frontend-module.d.ts +12 -0
  74. package/dist/frontend-module.js +25 -0
  75. package/dist/git/changed-files.d.ts +30 -0
  76. package/dist/git/changed-files.js +107 -0
  77. package/dist/git/changes.d.ts +89 -0
  78. package/dist/git/changes.js +162 -0
  79. package/dist/git/command.d.ts +51 -0
  80. package/dist/git/command.js +231 -0
  81. package/dist/git/promotion.d.ts +23 -0
  82. package/dist/git/promotion.js +46 -0
  83. package/dist/git/publish-input.d.ts +42 -0
  84. package/dist/git/publish-input.js +62 -0
  85. package/dist/git/publish-job.d.ts +82 -0
  86. package/dist/git/publish-job.js +99 -0
  87. package/dist/git/publish-steps.d.ts +90 -0
  88. package/dist/git/publish-steps.js +205 -0
  89. package/dist/git/publisher.d.ts +23 -0
  90. package/dist/git/publisher.js +206 -0
  91. package/dist/git/refs.d.ts +99 -0
  92. package/dist/git/refs.js +178 -0
  93. package/dist/git/refusal.d.ts +49 -0
  94. package/dist/git/refusal.js +70 -0
  95. package/dist/git/repository.d.ts +101 -0
  96. package/dist/git/repository.js +273 -0
  97. package/dist/git/versions.d.ts +99 -0
  98. package/dist/git/versions.js +174 -0
  99. package/dist/git/write-lock.d.ts +19 -0
  100. package/dist/git/write-lock.js +49 -0
  101. package/dist/index.d.ts +5 -0
  102. package/dist/index.js +59 -0
  103. package/dist/lifecycle.d.ts +8 -0
  104. package/dist/lifecycle.js +78 -0
  105. package/dist/logs/relay.d.ts +25 -0
  106. package/dist/logs/relay.js +138 -0
  107. package/dist/null-prototype.d.ts +7 -0
  108. package/dist/null-prototype.js +3 -0
  109. package/dist/overview/content.d.ts +40 -0
  110. package/dist/overview/content.js +172 -0
  111. package/dist/pages/changes.d.ts +32 -0
  112. package/dist/pages/changes.js +141 -0
  113. package/dist/pages/connection.d.ts +43 -0
  114. package/dist/pages/connection.js +295 -0
  115. package/dist/pages/deployment.d.ts +67 -0
  116. package/dist/pages/deployment.js +261 -0
  117. package/dist/pages/deployments.d.ts +46 -0
  118. package/dist/pages/deployments.js +266 -0
  119. package/dist/pages/environments.d.ts +34 -0
  120. package/dist/pages/environments.js +368 -0
  121. package/dist/pages/logs.d.ts +46 -0
  122. package/dist/pages/logs.js +140 -0
  123. package/dist/pages/navigation.d.ts +61 -0
  124. package/dist/pages/navigation.js +107 -0
  125. package/dist/pages/overview.d.ts +35 -0
  126. package/dist/pages/overview.js +201 -0
  127. package/dist/pages/project-guard.d.ts +32 -0
  128. package/dist/pages/project-guard.js +99 -0
  129. package/dist/pages/query.d.ts +6 -0
  130. package/dist/pages/query.js +14 -0
  131. package/dist/pages/resources.d.ts +37 -0
  132. package/dist/pages/resources.js +211 -0
  133. package/dist/pages/setup.d.ts +40 -0
  134. package/dist/pages/setup.js +271 -0
  135. package/dist/pages/slugs.d.ts +15 -0
  136. package/dist/pages/slugs.js +28 -0
  137. package/dist/pages/variables.d.ts +43 -0
  138. package/dist/pages/variables.js +327 -0
  139. package/dist/pages/version.d.ts +26 -0
  140. package/dist/pages/version.js +214 -0
  141. package/dist/pages/versions.d.ts +20 -0
  142. package/dist/pages/versions.js +115 -0
  143. package/dist/resources/apply.d.ts +15 -0
  144. package/dist/resources/apply.js +127 -0
  145. package/dist/resources/cards.d.ts +41 -0
  146. package/dist/resources/cards.js +211 -0
  147. package/dist/resources/connect.d.ts +66 -0
  148. package/dist/resources/connect.js +78 -0
  149. package/dist/resources/content.d.ts +26 -0
  150. package/dist/resources/content.js +158 -0
  151. package/dist/resources/format.d.ts +10 -0
  152. package/dist/resources/format.js +30 -0
  153. package/dist/resources/guard.d.ts +23 -0
  154. package/dist/resources/guard.js +60 -0
  155. package/dist/resources/modules.d.ts +23 -0
  156. package/dist/resources/modules.js +39 -0
  157. package/dist/resources/plan.d.ts +8 -0
  158. package/dist/resources/plan.js +93 -0
  159. package/dist/resources/read.d.ts +54 -0
  160. package/dist/resources/read.js +69 -0
  161. package/dist/resources/refusals.d.ts +15 -0
  162. package/dist/resources/refusals.js +33 -0
  163. package/dist/resources/routes.d.ts +32 -0
  164. package/dist/resources/routes.js +53 -0
  165. package/dist/setup/actions.d.ts +79 -0
  166. package/dist/setup/actions.js +188 -0
  167. package/dist/setup/apply.d.ts +37 -0
  168. package/dist/setup/apply.js +172 -0
  169. package/dist/setup/content.d.ts +50 -0
  170. package/dist/setup/content.js +440 -0
  171. package/dist/setup/rollout.d.ts +119 -0
  172. package/dist/setup/rollout.js +227 -0
  173. package/dist/setup/steps.d.ts +93 -0
  174. package/dist/setup/steps.js +95 -0
  175. package/dist/setup/storage.d.ts +29 -0
  176. package/dist/setup/storage.js +78 -0
  177. package/dist/setup/store.d.ts +214 -0
  178. package/dist/setup/store.js +174 -0
  179. package/dist/setup/volume.d.ts +31 -0
  180. package/dist/setup/volume.js +52 -0
  181. package/dist/slug.d.ts +7 -0
  182. package/dist/slug.js +26 -0
  183. package/dist/variables/actions.d.ts +76 -0
  184. package/dist/variables/actions.js +185 -0
  185. package/dist/variables/content.d.ts +69 -0
  186. package/dist/variables/content.js +310 -0
  187. package/dist/variables/decide.d.ts +27 -0
  188. package/dist/variables/decide.js +155 -0
  189. package/dist/variables/decided-dialog.d.ts +11 -0
  190. package/dist/variables/decided-dialog.js +129 -0
  191. package/dist/variables/decided.d.ts +80 -0
  192. package/dist/variables/decided.js +240 -0
  193. package/dist/variables/dialogs.d.ts +8 -0
  194. package/dist/variables/dialogs.js +219 -0
  195. package/dist/variables/model.d.ts +106 -0
  196. package/dist/variables/model.js +156 -0
  197. package/dist/variables/project-config.d.ts +117 -0
  198. package/dist/variables/project-config.js +248 -0
  199. package/dist/variables/read.d.ts +33 -0
  200. package/dist/variables/read.js +118 -0
  201. package/dist/web-url.d.ts +9 -0
  202. package/dist/web-url.js +19 -0
  203. package/frontend-vue/app/components/BuildLog.vue +99 -0
  204. package/frontend-vue/app/components/ChangedFiles.vue +165 -0
  205. package/frontend-vue/app/components/DashboardEnvironments.vue +102 -0
  206. package/frontend-vue/app/components/LogLine.vue +33 -0
  207. package/frontend-vue/app/components/LogViewer.vue +314 -0
  208. package/frontend-vue/app/components/PublishChipIcon.vue +39 -0
  209. package/frontend-vue/app/components/PublishForm.vue +505 -0
  210. package/frontend-vue/app/components/PublishPopover.vue +90 -0
  211. package/frontend-vue/app/components/PublishRoute.vue +222 -0
  212. package/frontend-vue/app/composables/usePublishSummary.ts +80 -0
  213. package/frontend-vue/app/plugins/publish-chip.client.ts +44 -0
  214. package/frontend-vue/app/types/publishing.ts +154 -0
  215. package/frontend-vue/app/utils/build-log.ts +96 -0
  216. package/frontend-vue/app/utils/changed-files.ts +142 -0
  217. package/frontend-vue/app/utils/log-line.ts +15 -0
  218. package/frontend-vue/app/utils/log-stream.ts +361 -0
  219. package/frontend-vue/app/utils/publish-state.ts +299 -0
  220. package/frontend-vue/dms.frontend.ts +27 -0
  221. package/frontend-vue/i18n/locales/antelope-cloud-en-GB.json +110 -0
  222. package/frontend-vue/package.json +38 -0
  223. package/frontend-vue/pnpm-lock.yaml +2697 -0
  224. package/package.json +115 -3
@@ -0,0 +1,90 @@
1
+ import { type GitOptions, type GitOutput } from "./command";
2
+ import type { OriginRef, StepId } from "./publish-job";
3
+ import type { GitIdentity } from "./publish-input";
4
+ import { type EnvironmentName, type ReleaseTag, type WorkBranch } from "./refs";
5
+ import type { VersionRef } from "./versions";
6
+ /**
7
+ * What a publish writes in the repository before it pushes: a commit of the
8
+ * working copy's changed files with its message, and its tag; a tag on HEAD
9
+ * as it is when the working copy is clean; or nothing when HEAD is already
10
+ * the version's tagged commit and only origin lacks it.
11
+ */
12
+ export type LocalWrites = {
13
+ readonly kind: "commit";
14
+ readonly files: number;
15
+ readonly message: string;
16
+ } | {
17
+ readonly kind: "tag";
18
+ readonly commit: string;
19
+ } | {
20
+ readonly kind: "none";
21
+ readonly commit: string;
22
+ };
23
+ /** Everything a publish needs, read and checked before it writes anything. */
24
+ export type PublishPlan = {
25
+ readonly path: string;
26
+ readonly branch: WorkBranch;
27
+ readonly writes: LocalWrites;
28
+ readonly version: VersionRef;
29
+ readonly tag: ReleaseTag;
30
+ readonly notes: string;
31
+ readonly environment: EnvironmentName;
32
+ /** The commit origin held for the environment branch at the check, `null` for none. */
33
+ readonly lease: string | null;
34
+ /** Who the commit and the tag are written as; the repository's configuration when `null`. */
35
+ readonly identity: GitIdentity | null;
36
+ };
37
+ /** How a step ended, and what the steps after it need from it. */
38
+ export type StepOutcome<T> = {
39
+ readonly state: "done" | "skipped";
40
+ readonly detail: string;
41
+ readonly value: T;
42
+ };
43
+ /** The detail of a commit step with nothing to commit. */
44
+ export declare const NOTHING_TO_COMMIT = "nothing to commit";
45
+ /** The detail of a tag step whose tag this repository holds already. */
46
+ export declare function tagAlreadyMade(tag: ReleaseTag): string;
47
+ /** The detail of the push step: one tag and two branches. */
48
+ export declare const PUSH_DETAIL = "tag + 2 branches";
49
+ /** The sentence a failed step reports: `The commit failed: <git's first error line>`. */
50
+ export declare function stepFailure(step: StepId, output: GitOutput): string;
51
+ /** The git commands a step ran and what they printed, for the publish log. */
52
+ export declare class StepLog {
53
+ private readonly path;
54
+ private readonly lines;
55
+ constructor(path: string);
56
+ /** Runs git, records the command and its output, and resolves whatever the exit code. */
57
+ run(args: readonly string[], options?: GitOptions): Promise<GitOutput>;
58
+ /**
59
+ * Runs git and records it, resolving with its standard output.
60
+ *
61
+ * @throws {GitError} When git exits with a non-zero code.
62
+ */
63
+ ok(args: readonly string[], options?: GitOptions): Promise<string>;
64
+ /** Every command and output recorded so far, one per line. */
65
+ text(): string;
66
+ }
67
+ /** A push origin refused, with what each pushed ref holds on origin afterwards. */
68
+ export declare class PushRefused extends Error {
69
+ readonly origin: readonly OriginRef[];
70
+ constructor(message: string, origin: readonly OriginRef[]);
71
+ }
72
+ /** Commits the working copy, or reuses HEAD when there is nothing to commit. */
73
+ export declare function commitChanges(plan: PublishPlan, log: StepLog): Promise<StepOutcome<string>>;
74
+ /**
75
+ * Tags the commit with the version's annotated tag, or keeps the tag a
76
+ * refused push left when the publish pushes that version again. Never
77
+ * replaces a tag: fails when origin holds the tag already, and git itself
78
+ * refuses one that exists locally.
79
+ */
80
+ export declare function createTag(plan: PublishPlan, commit: string, log: StepLog): Promise<StepOutcome<undefined>>;
81
+ /** Points the local environment branch at the commit. */
82
+ export declare function moveEnvironment(plan: PublishPlan, commit: string, log: StepLog): Promise<StepOutcome<undefined>>;
83
+ /**
84
+ * Pushes the branch, the tag and the environment branch to origin in one
85
+ * atomic push. After a refusal, reads origin again to say which refs hold
86
+ * what the publish pushed.
87
+ *
88
+ * @throws {PushRefused} When origin refuses the push.
89
+ */
90
+ export declare function pushVersion(plan: PublishPlan, commit: string, log: StepLog): Promise<StepOutcome<undefined>>;
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PushRefused = exports.StepLog = exports.PUSH_DETAIL = exports.NOTHING_TO_COMMIT = void 0;
4
+ exports.tagAlreadyMade = tagAlreadyMade;
5
+ exports.stepFailure = stepFailure;
6
+ exports.commitChanges = commitChanges;
7
+ exports.createTag = createTag;
8
+ exports.moveEnvironment = moveEnvironment;
9
+ exports.pushVersion = pushVersion;
10
+ const command_1 = require("./command");
11
+ const refs_1 = require("./refs");
12
+ const repository_1 = require("./repository");
13
+ /** The detail of a commit step with nothing to commit. */
14
+ exports.NOTHING_TO_COMMIT = "nothing to commit";
15
+ /** The detail of a tag step whose tag this repository holds already. */
16
+ function tagAlreadyMade(tag) {
17
+ return `${tag} already made`;
18
+ }
19
+ /** The detail of the push step: one tag and two branches. */
20
+ exports.PUSH_DETAIL = "tag + 2 branches";
21
+ /** How long the push may run: a large first push over a slow link takes minutes. */
22
+ const PUSH_TIMEOUT_MS = 15 * 60_000;
23
+ const ATOMIC_FAILURE = "atomic push failed";
24
+ const REFUSED_MARK = "!";
25
+ const REFUSAL_REASON = /\(([^)]*)\)\s*$/u;
26
+ /** Why git refuses to push a branch whose tip origin has moved past. */
27
+ const BEHIND_ORIGIN = new Set(["fetch first", "non-fast-forward"]);
28
+ /** How a failure message names each step. */
29
+ const STEP_NAMES = {
30
+ __proto__: null,
31
+ commit: "The commit",
32
+ tag: "The tag",
33
+ move: "Moving the environment branch",
34
+ push: "The push",
35
+ };
36
+ /** The sentence a failed step reports: `The commit failed: <git's first error line>`. */
37
+ function stepFailure(step, output) {
38
+ const line = (0, command_1.firstErrorLine)(output.stderr) || `git exited with code ${output.exitCode}`;
39
+ return (0, command_1.redactCredentials)(`${STEP_NAMES[step]} failed: ${line}`);
40
+ }
41
+ function identityOptions(identity) {
42
+ if (!identity)
43
+ return {};
44
+ return {
45
+ env: {
46
+ GIT_AUTHOR_NAME: identity.name,
47
+ GIT_AUTHOR_EMAIL: identity.email,
48
+ GIT_COMMITTER_NAME: identity.name,
49
+ GIT_COMMITTER_EMAIL: identity.email,
50
+ },
51
+ };
52
+ }
53
+ /** The git commands a step ran and what they printed, for the publish log. */
54
+ class StepLog {
55
+ path;
56
+ lines = [];
57
+ constructor(path) {
58
+ this.path = path;
59
+ }
60
+ /** Runs git, records the command and its output, and resolves whatever the exit code. */
61
+ async run(args, options) {
62
+ const output = await (0, command_1.runGit)(this.path, args, options);
63
+ this.lines.push(`$ ${(0, command_1.commandLine)(args)}`);
64
+ for (const text of [output.stdout, output.stderr]) {
65
+ if (text.trim() !== "")
66
+ this.lines.push((0, command_1.redactCredentials)(text.trim()));
67
+ }
68
+ return output;
69
+ }
70
+ /**
71
+ * Runs git and records it, resolving with its standard output.
72
+ *
73
+ * @throws {GitError} When git exits with a non-zero code.
74
+ */
75
+ async ok(args, options) {
76
+ const output = await this.run(args, options);
77
+ if (output.exitCode !== 0)
78
+ throw new command_1.GitError(args, output);
79
+ return output.stdout;
80
+ }
81
+ /** Every command and output recorded so far, one per line. */
82
+ text() {
83
+ return this.lines.join("\n");
84
+ }
85
+ }
86
+ exports.StepLog = StepLog;
87
+ /** A push origin refused, with what each pushed ref holds on origin afterwards. */
88
+ class PushRefused extends Error {
89
+ origin;
90
+ constructor(message, origin) {
91
+ super(message);
92
+ this.origin = origin;
93
+ this.name = "PushRefused";
94
+ }
95
+ }
96
+ exports.PushRefused = PushRefused;
97
+ /** Commits the working copy, or reuses HEAD when there is nothing to commit. */
98
+ async function commitChanges(plan, log) {
99
+ if (plan.writes.kind !== "commit") {
100
+ return {
101
+ state: "skipped",
102
+ detail: exports.NOTHING_TO_COMMIT,
103
+ value: plan.writes.commit,
104
+ };
105
+ }
106
+ await log.ok(["add", "--all"]);
107
+ await log.ok(["commit", "-m", plan.writes.message], identityOptions(plan.identity));
108
+ const commit = (await (0, command_1.git)(plan.path, ["rev-parse", "HEAD"])).trim();
109
+ return { state: "done", detail: `on ${plan.branch}`, value: commit };
110
+ }
111
+ /**
112
+ * Tags the commit with the version's annotated tag, or keeps the tag a
113
+ * refused push left when the publish pushes that version again. Never
114
+ * replaces a tag: fails when origin holds the tag already, and git itself
115
+ * refuses one that exists locally.
116
+ */
117
+ async function createTag(plan, commit, log) {
118
+ if (plan.writes.kind === "none") {
119
+ return {
120
+ state: "skipped",
121
+ detail: tagAlreadyMade(plan.tag),
122
+ value: undefined,
123
+ };
124
+ }
125
+ const onOrigin = await log.ok(["ls-remote", "origin", (0, refs_1.tagRef)(plan.tag)]);
126
+ if (onOrigin.trim() !== "") {
127
+ throw new Error(`${plan.tag} already exists on origin and is left as it is. Publish again to make the next version.`);
128
+ }
129
+ const message = plan.notes
130
+ ? `${plan.version.name}\n\n${plan.notes}`
131
+ : plan.version.name;
132
+ await log.ok(["tag", "-a", "--cleanup=whitespace", "-m", message, plan.tag, commit], identityOptions(plan.identity));
133
+ return {
134
+ state: "done",
135
+ detail: `annotated · ${plan.version.name}`,
136
+ value: undefined,
137
+ };
138
+ }
139
+ /** Points the local environment branch at the commit. */
140
+ async function moveEnvironment(plan, commit, log) {
141
+ await log.ok(["branch", "-f", (0, refs_1.environmentBranch)(plan.environment), commit]);
142
+ return { state: "done", detail: `to ${(0, refs_1.shortSha)(commit)}`, value: undefined };
143
+ }
144
+ function refusedRefs(stdout) {
145
+ return stdout
146
+ .split("\n")
147
+ .filter((line) => line.startsWith(REFUSED_MARK))
148
+ .map((line) => {
149
+ const [, refspec = "", summary = ""] = line.split("\t");
150
+ return {
151
+ ref: refspec.split(":").pop() ?? refspec,
152
+ summary,
153
+ reason: REFUSAL_REASON.exec(summary)?.[1] ?? summary,
154
+ };
155
+ });
156
+ }
157
+ /**
158
+ * Says why origin refused the push. Origin's work branch ahead of this copy
159
+ * gets a sentence of its own, since pulling is the way out; any other
160
+ * refusal names the first ref origin refused for a reason of its own.
161
+ */
162
+ function pushFailureMessage(plan, output) {
163
+ const causes = refusedRefs(output.stdout).filter(({ reason }) => reason !== ATOMIC_FAILURE);
164
+ const branch = (0, refs_1.branchRef)(plan.branch);
165
+ if (causes.some(({ ref, reason }) => ref === branch && BEHIND_ORIGIN.has(reason))) {
166
+ return `origin has commits on ${plan.branch} that this copy does not have. Pull them, then publish again.`;
167
+ }
168
+ const [cause] = causes;
169
+ if (!cause)
170
+ return stepFailure("push", output);
171
+ return (0, command_1.redactCredentials)(`${STEP_NAMES.push} failed: ${cause.ref} ${cause.summary}`);
172
+ }
173
+ async function originReached(plan, targets, commit) {
174
+ const [origin, tagObject] = await Promise.all([
175
+ (0, repository_1.readOrigin)(plan.path, targets.map(refs_1.targetRef)),
176
+ (0, command_1.git)(plan.path, ["rev-parse", (0, refs_1.tagRef)(plan.tag)]),
177
+ ]);
178
+ return targets.map((target) => {
179
+ const ref = (0, refs_1.targetRef)(target);
180
+ const pushed = target.kind === "tag" ? tagObject.trim() : commit;
181
+ return { ref, reached: (0, repository_1.originObject)(origin, ref) === pushed };
182
+ });
183
+ }
184
+ /**
185
+ * Pushes the branch, the tag and the environment branch to origin in one
186
+ * atomic push. After a refusal, reads origin again to say which refs hold
187
+ * what the publish pushed.
188
+ *
189
+ * @throws {PushRefused} When origin refuses the push.
190
+ */
191
+ async function pushVersion(plan, commit, log) {
192
+ const targets = [
193
+ (0, refs_1.branchTarget)(plan.branch),
194
+ (0, refs_1.tagTarget)(plan.tag),
195
+ (0, refs_1.environmentTarget)(plan.environment, plan.lease),
196
+ ];
197
+ const output = await log.run((0, refs_1.pushArguments)(targets), {
198
+ timeoutMs: PUSH_TIMEOUT_MS,
199
+ });
200
+ if (output.exitCode !== 0) {
201
+ throw new PushRefused(pushFailureMessage(plan, output), await originReached(plan, targets, commit));
202
+ }
203
+ return { state: "done", detail: exports.PUSH_DETAIL, value: undefined };
204
+ }
205
+ //# sourceMappingURL=publish-steps.js.map
@@ -0,0 +1,23 @@
1
+ import { type PublishJob } from "./publish-job";
2
+ import { type GitIdentity, type PublishInput } from "./publish-input";
3
+ import { type Refusal } from "./refusal";
4
+ /**
5
+ * How the publish route answers: the started publish, or why none started,
6
+ * 400 for a request that lacks what the publish needs and 409 otherwise.
7
+ */
8
+ export type PublishAnswer = {
9
+ readonly status: 202;
10
+ readonly job: PublishJob;
11
+ } | {
12
+ readonly status: 400 | 409;
13
+ readonly refusal: Refusal;
14
+ };
15
+ /** The latest publish of this process, running or ended. */
16
+ export declare function currentJob(): PublishJob | null;
17
+ /**
18
+ * Starts publishing the working copy at `path` as the next version: checks
19
+ * the repository, then runs the four steps in the background. One publish
20
+ * runs at a time in the process, and none while a promotion moves an
21
+ * environment branch.
22
+ */
23
+ export declare function startPublish(path: string, input: PublishInput, identity: GitIdentity | null): Promise<PublishAnswer>;
@@ -0,0 +1,206 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.currentJob = currentJob;
4
+ exports.startPublish = startPublish;
5
+ const node_crypto_1 = require("node:crypto");
6
+ const changes_1 = require("./changes");
7
+ const command_1 = require("./command");
8
+ const publish_job_1 = require("./publish-job");
9
+ const publish_input_1 = require("./publish-input");
10
+ const publish_steps_1 = require("./publish-steps");
11
+ const refs_1 = require("./refs");
12
+ const refusal_1 = require("./refusal");
13
+ const repository_1 = require("./repository");
14
+ const versions_1 = require("./versions");
15
+ const write_lock_1 = require("./write-lock");
16
+ let latestJob = null;
17
+ /** The latest publish of this process, running or ended. */
18
+ function currentJob() {
19
+ return latestJob;
20
+ }
21
+ function plural(count, word) {
22
+ return `${count} ${word}${count === 1 ? "" : "s"}`;
23
+ }
24
+ /**
25
+ * Plans the version the publish pushes: the pending one again, which needs
26
+ * nothing of the request but its environment, or a new one, which needs a
27
+ * commit message.
28
+ */
29
+ async function planRelease(snapshot, unpublished, input) {
30
+ const next = await (0, changes_1.readNextVersion)(snapshot, unpublished);
31
+ if (next.kind === "retry") {
32
+ const { release } = next;
33
+ return {
34
+ kind: "planned",
35
+ plan: {
36
+ writes: { kind: "none", commit: release.commit },
37
+ version: (0, versions_1.versionRef)(release),
38
+ tag: (0, refs_1.releaseTagOf)(release.number),
39
+ },
40
+ };
41
+ }
42
+ const { message } = input;
43
+ if (!message)
44
+ return { kind: "refused", refusal: (0, publish_input_1.missingMessage)() };
45
+ const { number } = next;
46
+ const { head } = snapshot;
47
+ const tag = (0, refs_1.releaseTagOf)(number);
48
+ const uncommitted = await (0, changes_1.readUncommitted)(snapshot, unpublished);
49
+ return {
50
+ kind: "planned",
51
+ plan: {
52
+ writes: uncommitted.length === 0 && head !== null
53
+ ? { kind: "tag", commit: head }
54
+ : { kind: "commit", files: uncommitted.length, message },
55
+ version: { number, tag, name: input.versionName || `Version ${number}` },
56
+ tag,
57
+ },
58
+ };
59
+ }
60
+ async function preflight(path, input, identity) {
61
+ const read = await (0, repository_1.readRepository)(path, "fresh");
62
+ if (read.kind === "refused")
63
+ return read;
64
+ const { snapshot } = read;
65
+ const check = (0, changes_1.checkRepository)(snapshot);
66
+ if (check.kind === "refused")
67
+ return check;
68
+ const unpublished = await (0, changes_1.readUnpublished)(snapshot);
69
+ if ((0, changes_1.isPublished)(snapshot, unpublished)) {
70
+ return { kind: "refused", refusal: (0, refusal_1.nothingToPublish)() };
71
+ }
72
+ const release = await planRelease(snapshot, unpublished, input);
73
+ if (release.kind === "refused")
74
+ return release;
75
+ const environment = (0, refs_1.environmentName)(input.environment);
76
+ const lease = (0, repository_1.originObject)(snapshot.origin, (0, refs_1.branchRef)((0, refs_1.environmentBranch)(environment)));
77
+ return {
78
+ kind: "ready",
79
+ plan: {
80
+ path,
81
+ branch: check.branch,
82
+ ...release.plan,
83
+ notes: input.releaseNotes ?? "",
84
+ environment,
85
+ lease: lease ?? null,
86
+ identity,
87
+ },
88
+ };
89
+ }
90
+ function stepLabels(plan) {
91
+ const { writes } = plan;
92
+ return {
93
+ commit: writes.kind === "commit"
94
+ ? {
95
+ title: `Commit ${plural(writes.files, "file")}`,
96
+ detail: `on ${plan.branch}`,
97
+ }
98
+ : { title: "Commit", detail: publish_steps_1.NOTHING_TO_COMMIT },
99
+ tag: {
100
+ title: `Tag ${plan.tag}`,
101
+ detail: writes.kind === "none"
102
+ ? (0, publish_steps_1.tagAlreadyMade)(plan.tag)
103
+ : `annotated · ${plan.version.name}`,
104
+ },
105
+ move: {
106
+ title: `Move ${(0, refs_1.environmentBranch)(plan.environment)}`,
107
+ detail: writes.kind === "commit"
108
+ ? "to the new commit"
109
+ : `to ${(0, refs_1.shortSha)(writes.commit)}`,
110
+ },
111
+ push: { title: "Push to origin", detail: publish_steps_1.PUSH_DETAIL },
112
+ };
113
+ }
114
+ /** Stops a publish after a step failed and its failure was recorded. */
115
+ class PublishHalted extends Error {
116
+ }
117
+ async function runPublish(plan, update) {
118
+ const step = async (id, body) => {
119
+ update({ type: "started", step: id });
120
+ const log = new publish_steps_1.StepLog(plan.path);
121
+ try {
122
+ const outcome = await body(log);
123
+ update({
124
+ type: "finished",
125
+ step: id,
126
+ state: outcome.state,
127
+ detail: outcome.detail,
128
+ log: log.text(),
129
+ at: new Date().toISOString(),
130
+ });
131
+ return outcome.value;
132
+ }
133
+ catch (error) {
134
+ update({
135
+ type: "failed",
136
+ step: id,
137
+ message: error instanceof command_1.GitError
138
+ ? (0, publish_steps_1.stepFailure)(id, error.output)
139
+ : (0, command_1.redactCredentials)(error instanceof Error ? error.message : String(error)),
140
+ log: log.text(),
141
+ origin: error instanceof publish_steps_1.PushRefused ? error.origin : [],
142
+ at: new Date().toISOString(),
143
+ });
144
+ throw new PublishHalted();
145
+ }
146
+ };
147
+ try {
148
+ const commit = await step("commit", (log) => (0, publish_steps_1.commitChanges)(plan, log));
149
+ update({ type: "committed", commit });
150
+ await step("tag", (log) => (0, publish_steps_1.createTag)(plan, commit, log));
151
+ await step("move", (log) => (0, publish_steps_1.moveEnvironment)(plan, commit, log));
152
+ await step("push", (log) => (0, publish_steps_1.pushVersion)(plan, commit, log));
153
+ }
154
+ catch (error) {
155
+ if (!(error instanceof PublishHalted))
156
+ throw error;
157
+ }
158
+ }
159
+ /** Runs a checked publish in the background and answers its job as it starts. */
160
+ function launch(plan) {
161
+ const started = (0, publish_job_1.startJob)((0, node_crypto_1.randomUUID)(), plan.version, plan.environment, stepLabels(plan), new Date().toISOString());
162
+ latestJob = started;
163
+ let job = started;
164
+ void runPublish(plan, (event) => {
165
+ job = (0, publish_job_1.reduceJob)(job, event);
166
+ latestJob = job;
167
+ }).finally(() => {
168
+ (0, repository_1.forgetOrigin)(plan.path);
169
+ (0, write_lock_1.endPublish)();
170
+ });
171
+ return started;
172
+ }
173
+ /**
174
+ * Starts publishing the working copy at `path` as the next version: checks
175
+ * the repository, then runs the four steps in the background. One publish
176
+ * runs at a time in the process, and none while a promotion moves an
177
+ * environment branch.
178
+ */
179
+ async function startPublish(path, input, identity) {
180
+ const holder = (0, write_lock_1.beginPublish)();
181
+ if (holder !== null) {
182
+ return {
183
+ status: 409,
184
+ refusal: holder === "publish" ? (0, refusal_1.publishRunning)() : (0, refusal_1.promotionRunning)(),
185
+ };
186
+ }
187
+ let launched = false;
188
+ try {
189
+ const checked = await preflight(path, input, identity);
190
+ if (checked.kind === "refused") {
191
+ const { refusal } = checked;
192
+ return {
193
+ status: refusal.code === "invalid_input" ? 400 : 409,
194
+ refusal,
195
+ };
196
+ }
197
+ const job = launch(checked.plan);
198
+ launched = true;
199
+ return { status: 202, job };
200
+ }
201
+ finally {
202
+ if (!launched)
203
+ (0, write_lock_1.endPublish)();
204
+ }
205
+ }
206
+ //# sourceMappingURL=publisher.js.map
@@ -0,0 +1,99 @@
1
+ declare const workBranchBrand: unique symbol;
2
+ declare const releaseTagBrand: unique symbol;
3
+ declare const environmentNameBrand: unique symbol;
4
+ declare const commitIdBrand: unique symbol;
5
+ /** A branch the publish commits on: any branch but an `env/*` one. */
6
+ export type WorkBranch = string & {
7
+ readonly [workBranchBrand]: true;
8
+ };
9
+ /** A version tag, `release/v<N>` with N a whole number from 1. */
10
+ export type ReleaseTag = string & {
11
+ readonly [releaseTagBrand]: true;
12
+ };
13
+ /** The name of an environment, `preview` for the branch `env/preview`. */
14
+ export type EnvironmentName = string & {
15
+ readonly [environmentNameBrand]: true;
16
+ };
17
+ /** A full commit id, as {@link commitId} reads it. */
18
+ export type CommitId = string & {
19
+ readonly [commitIdBrand]: true;
20
+ };
21
+ /**
22
+ * A ref the publish pushes to origin. A branch or a tag is pushed only as a
23
+ * fast-forward or a creation. An environment branch alone may move to an
24
+ * unrelated commit, and only while origin still holds `lease`, the commit
25
+ * read before the publish started (`null`: origin had no such branch). It
26
+ * gets `commit`, a full commit id, or the local branch of the same name when
27
+ * `commit` is `null`.
28
+ */
29
+ export type PushTarget = {
30
+ readonly kind: "branch";
31
+ readonly branch: WorkBranch;
32
+ } | {
33
+ readonly kind: "tag";
34
+ readonly tag: ReleaseTag;
35
+ } | {
36
+ readonly kind: "environment";
37
+ readonly environment: EnvironmentName;
38
+ readonly lease: string | null;
39
+ readonly commit: string | null;
40
+ };
41
+ /**
42
+ * Checks a branch name the publish may commit on.
43
+ *
44
+ * @throws When the name is empty or an `env/*` branch.
45
+ */
46
+ export declare function workBranch(name: string): WorkBranch;
47
+ /** The tag of version `number`, `release/v16` for 16. */
48
+ export declare function releaseTagOf(number: number): ReleaseTag;
49
+ /** The version number a tag name carries, or `null` for any other name. */
50
+ export declare function releaseNumber(name: string): number | null;
51
+ /** Whether a name is a valid environment name, `preview` but not `Preview`. */
52
+ export declare function isValidEnvironmentName(name: string): boolean;
53
+ /**
54
+ * Checks an environment name.
55
+ *
56
+ * @throws When the name is not lowercase letters, digits and dashes.
57
+ */
58
+ export declare function environmentName(name: string): EnvironmentName;
59
+ /** The branch of an environment, `env/preview` for `preview`. */
60
+ export declare function environmentBranch(name: string): string;
61
+ /** The environment a branch serves, `preview` for `env/preview`, else `null`. */
62
+ export declare function environmentOfBranch(branch: string): string | null;
63
+ /** Whether HEAD on this branch would let the publish move it as an environment. */
64
+ export declare function isEnvironmentBranch(branch: string): boolean;
65
+ /**
66
+ * Reads a full commit id, 40 or 64 lowercase hexadecimal digits.
67
+ *
68
+ * @returns The id, or `undefined` for anything else, such as a short id or a
69
+ * ref name.
70
+ */
71
+ export declare function commitId(raw: string | null | undefined): CommitId | undefined;
72
+ /** The first characters of a commit id, as git shows it: `4be81a2`. */
73
+ export declare function shortSha(commit: string): string;
74
+ /** The full ref of a branch, `refs/heads/develop`. */
75
+ export declare function branchRef(branch: string): string;
76
+ /** The branch a full ref names, `develop` for `refs/heads/develop`, else `null`. */
77
+ export declare function branchOfRef(ref: string): string | null;
78
+ /** The full ref of a tag, `refs/tags/release/v16`. */
79
+ export declare function tagRef(tag: string): string;
80
+ /** A branch pushed to origin as a fast-forward. */
81
+ export declare function branchTarget(name: string): PushTarget;
82
+ /** A version tag pushed to origin as a new tag. */
83
+ export declare function tagTarget(name: string): PushTarget;
84
+ /**
85
+ * An environment branch pushed to origin while origin still holds `lease`:
86
+ * to `commit`, or to the local branch of the same name.
87
+ *
88
+ * @throws When `commit` is not a full commit id.
89
+ */
90
+ export declare function environmentTarget(name: string, lease: string | null, commit?: string | null): PushTarget;
91
+ /** The full ref a target writes on origin, `refs/heads/env/preview`. */
92
+ export declare function targetRef(target: PushTarget): string;
93
+ /**
94
+ * The arguments of one atomic push of the targets to origin. No refspec
95
+ * carries `+`: an environment branch moves past a non-fast-forward through
96
+ * its `--force-with-lease`, which git honours only without `+`.
97
+ */
98
+ export declare function pushArguments(targets: readonly PushTarget[]): string[];
99
+ export {};