@antelopejs/dms-antelope-cloud 0.0.0 → 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 +448 -0
  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 -4
@@ -0,0 +1,51 @@
1
+ /** What a git process printed and how it ended. */
2
+ export interface GitOutput {
3
+ /** The exit code; `-1` when git could not start, timed out or printed too much. */
4
+ readonly exitCode: number;
5
+ readonly stdout: string;
6
+ readonly stderr: string;
7
+ }
8
+ /** Extra variables, standard input and time limit for one git call. */
9
+ export interface GitOptions {
10
+ readonly env?: Readonly<Record<string, string>>;
11
+ readonly input?: string;
12
+ /** How long git may run before it is stopped; 60 s when left out. */
13
+ readonly timeoutMs?: number;
14
+ }
15
+ /** A git call that ended with a non-zero exit code. */
16
+ export declare class GitError extends Error {
17
+ readonly args: readonly string[];
18
+ readonly output: GitOutput;
19
+ constructor(args: readonly string[], output: GitOutput);
20
+ }
21
+ /** Replaces the user and password a URL carries with `***`, up to the last `@` before the host. */
22
+ export declare function redactCredentials(text: string): string;
23
+ /** The git call as a shell would show it: `git commit -m "Fix the cart"`. */
24
+ export declare function commandLine(args: readonly string[]): string;
25
+ /** The last non-empty line of a text, trimmed. */
26
+ export declare function lastLine(text: string): string;
27
+ /**
28
+ * The first line git printed that is not a hint, without its `error:` or
29
+ * `fatal:` prefix: `tag 'release/v1' already exists`. Empty when there is none.
30
+ */
31
+ export declare function firstErrorLine(text: string): string;
32
+ /**
33
+ * The environment git runs in: `base` without the variables that redirect
34
+ * git, with no terminal prompt, no ssh password dialog unless `base` asks for
35
+ * one, and the C locale, then `extra`.
36
+ */
37
+ export declare function gitEnvironment(base: NodeJS.ProcessEnv, extra?: Readonly<Record<string, string>>): NodeJS.ProcessEnv;
38
+ /**
39
+ * Runs git in a repository, with no shell, no prompt, the C locale and the
40
+ * time limit `options` gives, and resolves with its output whatever its exit
41
+ * code. On Linux and macOS git runs in a session of its own, without the DMS's
42
+ * terminal, so ssh cannot ask for a passphrase or a host key there, whatever
43
+ * ssh the user's configuration names.
44
+ */
45
+ export declare function runGit(repository: string, args: readonly string[], options?: GitOptions): Promise<GitOutput>;
46
+ /**
47
+ * Runs git and resolves with what it printed on standard output.
48
+ *
49
+ * @throws {GitError} When git exits with a non-zero code.
50
+ */
51
+ export declare function git(repository: string, args: readonly string[], options?: GitOptions): Promise<string>;
@@ -0,0 +1,231 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GitError = void 0;
4
+ exports.redactCredentials = redactCredentials;
5
+ exports.commandLine = commandLine;
6
+ exports.lastLine = lastLine;
7
+ exports.firstErrorLine = firstErrorLine;
8
+ exports.gitEnvironment = gitEnvironment;
9
+ exports.runGit = runGit;
10
+ exports.git = git;
11
+ const node_child_process_1 = require("node:child_process");
12
+ const GIT_TIMEOUT_MS = 60_000;
13
+ const MAX_OUTPUT_BYTES = 64 * 1024 * 1024;
14
+ const URL_CREDENTIALS = /\b([a-z][a-z\d+.-]*:\/\/)[^\s/]+@/giu;
15
+ const NEEDS_QUOTES = /[\s"'\\$`]/u;
16
+ const KILL_GRACE_MS = 5_000;
17
+ const OWN_PROCESS_GROUP = process.platform !== "win32";
18
+ /**
19
+ * Variables that would point git at another repository, index or object
20
+ * store than the one the module names, such as those a git hook exports.
21
+ */
22
+ const REDIRECTING_VARIABLES = [
23
+ "GIT_DIR",
24
+ "GIT_WORK_TREE",
25
+ "GIT_INDEX_FILE",
26
+ "GIT_OBJECT_DIRECTORY",
27
+ "GIT_ALTERNATE_OBJECT_DIRECTORIES",
28
+ "GIT_COMMON_DIR",
29
+ "GIT_NAMESPACE",
30
+ ];
31
+ /** A git call that ended with a non-zero exit code. */
32
+ class GitError extends Error {
33
+ args;
34
+ output;
35
+ constructor(args, output) {
36
+ super(redactCredentials(`git ${args[0] ?? ""} failed: ${lastLine(output.stderr) || `exit code ${output.exitCode}`}`));
37
+ this.args = args;
38
+ this.output = output;
39
+ this.name = "GitError";
40
+ }
41
+ }
42
+ exports.GitError = GitError;
43
+ /** Replaces the user and password a URL carries with `***`, up to the last `@` before the host. */
44
+ function redactCredentials(text) {
45
+ return text.replace(URL_CREDENTIALS, "$1***@");
46
+ }
47
+ /** The git call as a shell would show it: `git commit -m "Fix the cart"`. */
48
+ function commandLine(args) {
49
+ const words = args.map((arg) => arg === "" || NEEDS_QUOTES.test(arg) ? JSON.stringify(arg) : arg);
50
+ return redactCredentials(["git", ...words].join(" "));
51
+ }
52
+ /** The last non-empty line of a text, trimmed. */
53
+ function lastLine(text) {
54
+ const lines = text
55
+ .split("\n")
56
+ .map((line) => line.trim())
57
+ .filter((line) => line !== "");
58
+ return lines.pop() ?? "";
59
+ }
60
+ const ERROR_PREFIX = /^(?:error|fatal):\s*/u;
61
+ const HINT_PREFIX = "hint:";
62
+ /**
63
+ * The first line git printed that is not a hint, without its `error:` or
64
+ * `fatal:` prefix: `tag 'release/v1' already exists`. Empty when there is none.
65
+ */
66
+ function firstErrorLine(text) {
67
+ const line = text
68
+ .split("\n")
69
+ .map((entry) => entry.trim())
70
+ .find((entry) => entry !== "" && !entry.startsWith(HINT_PREFIX));
71
+ return line?.replace(ERROR_PREFIX, "") ?? "";
72
+ }
73
+ /**
74
+ * The environment git runs in: `base` without the variables that redirect
75
+ * git, with no terminal prompt, no ssh password dialog unless `base` asks for
76
+ * one, and the C locale, then `extra`.
77
+ */
78
+ function gitEnvironment(base, extra) {
79
+ const env = { ...base };
80
+ for (const name of REDIRECTING_VARIABLES)
81
+ delete env[name];
82
+ return {
83
+ ...env,
84
+ SSH_ASKPASS_REQUIRE: env.SSH_ASKPASS_REQUIRE ?? "never",
85
+ GIT_TERMINAL_PROMPT: "0",
86
+ LC_ALL: "C",
87
+ LANG: "C",
88
+ ...extra,
89
+ };
90
+ }
91
+ /** What one output stream of git printed, kept up to {@link MAX_OUTPUT_BYTES}. */
92
+ function collect(stream, onOverflow) {
93
+ const chunks = [];
94
+ let size = 0;
95
+ stream.on("data", (chunk) => {
96
+ size += chunk.length;
97
+ if (size > MAX_OUTPUT_BYTES) {
98
+ onOverflow();
99
+ return;
100
+ }
101
+ chunks.push(chunk);
102
+ });
103
+ return () => Buffer.concat(chunks).toString("utf8");
104
+ }
105
+ /**
106
+ * The git calls not closed yet, whose process groups are asked to stop when the
107
+ * DMS process exits, git itself ended or not.
108
+ */
109
+ const running = new Set();
110
+ /** Sends a signal to a process or a process group, which may be gone already. */
111
+ function signal(target, name) {
112
+ try {
113
+ process.kill(target, name);
114
+ }
115
+ catch {
116
+ return;
117
+ }
118
+ }
119
+ /**
120
+ * Sends a signal to git and to what it started, such as ssh or a hook, which
121
+ * share its process group. A git that already ended is left alone, so its
122
+ * process id, which the system may reuse, is never signalled.
123
+ */
124
+ function signalGit(child, name) {
125
+ if (child.pid === undefined || child.exitCode !== null)
126
+ return;
127
+ if (child.signalCode !== null)
128
+ return;
129
+ if (OWN_PROCESS_GROUP)
130
+ signal(-child.pid, name);
131
+ else
132
+ child.kill(name);
133
+ }
134
+ /**
135
+ * Kills what is left of git's process group, such as a hook that ignored the
136
+ * request to stop, even after git itself ended. Only a call that has not
137
+ * closed is signalled: some member of the group still holds git's output
138
+ * then, so the group's id still belongs to it.
139
+ */
140
+ function killGitGroup(child) {
141
+ if (child.pid === undefined || !running.has(child))
142
+ return;
143
+ if (OWN_PROCESS_GROUP)
144
+ signal(-child.pid, "SIGKILL");
145
+ else
146
+ signalGit(child, "SIGKILL");
147
+ }
148
+ /**
149
+ * Asks git to stop, which lets it remove its lock files such as
150
+ * `.git/index.lock`, then kills its whole process group after
151
+ * {@link KILL_GRACE_MS}.
152
+ */
153
+ function stopGit(child) {
154
+ signalGit(child, "SIGTERM");
155
+ setTimeout(() => killGitGroup(child), KILL_GRACE_MS).unref();
156
+ }
157
+ process.once("exit", () => {
158
+ for (const child of running) {
159
+ if (child.pid === undefined)
160
+ continue;
161
+ if (OWN_PROCESS_GROUP)
162
+ signal(-child.pid, "SIGTERM");
163
+ else
164
+ signalGit(child, "SIGTERM");
165
+ }
166
+ });
167
+ /**
168
+ * Runs git in a repository, with no shell, no prompt, the C locale and the
169
+ * time limit `options` gives, and resolves with its output whatever its exit
170
+ * code. On Linux and macOS git runs in a session of its own, without the DMS's
171
+ * terminal, so ssh cannot ask for a passphrase or a host key there, whatever
172
+ * ssh the user's configuration names.
173
+ */
174
+ function runGit(repository, args, options = {}) {
175
+ const timeoutMs = options.timeoutMs ?? GIT_TIMEOUT_MS;
176
+ return new Promise((resolve) => {
177
+ const child = (0, node_child_process_1.spawn)("git", ["-C", repository, ...args], {
178
+ env: gitEnvironment(process.env, options.env),
179
+ detached: OWN_PROCESS_GROUP,
180
+ stdio: ["pipe", "pipe", "pipe"],
181
+ });
182
+ running.add(child);
183
+ let failure = null;
184
+ const stop = (reason) => {
185
+ if (failure !== null)
186
+ return;
187
+ failure = reason;
188
+ stopGit(child);
189
+ };
190
+ const timer = setTimeout(() => stop(`git did not finish within ${timeoutMs / 1_000} s`), timeoutMs);
191
+ const overflow = () => stop(`git printed more than ${MAX_OUTPUT_BYTES / 1024 / 1024} MiB`);
192
+ const stdout = collect(child.stdout, overflow);
193
+ const stderr = collect(child.stderr, overflow);
194
+ const finish = (exitCode) => {
195
+ clearTimeout(timer);
196
+ running.delete(child);
197
+ resolve(failure === null && exitCode !== null
198
+ ? { exitCode, stdout: stdout(), stderr: stderr() }
199
+ : {
200
+ exitCode: -1,
201
+ stdout: stdout(),
202
+ stderr: `${stderr()}${failure ?? "git ended without an exit code"}`,
203
+ });
204
+ };
205
+ child.on("error", (error) => {
206
+ failure ??= error.message;
207
+ finish(null);
208
+ });
209
+ child.on("close", finish);
210
+ child.stdin.on("error", ignoreInputClosedByGit);
211
+ child.stdin.end(options.input ?? "");
212
+ });
213
+ }
214
+ /**
215
+ * Git may exit before it reads its standard input, as when it fails early.
216
+ * Writing to it then fails with `EPIPE`, which says nothing the exit code does
217
+ * not, and must not end the process as an unhandled stream error.
218
+ */
219
+ function ignoreInputClosedByGit() { }
220
+ /**
221
+ * Runs git and resolves with what it printed on standard output.
222
+ *
223
+ * @throws {GitError} When git exits with a non-zero code.
224
+ */
225
+ async function git(repository, args, options = {}) {
226
+ const output = await runGit(repository, args, options);
227
+ if (output.exitCode !== 0)
228
+ throw new GitError(args, output);
229
+ return output.stdout;
230
+ }
231
+ //# sourceMappingURL=command.js.map
@@ -0,0 +1,23 @@
1
+ import { type CommitId, type EnvironmentName } from "./refs";
2
+ /** Why a promotion did not move an environment branch on origin. */
3
+ type BranchMoveRefusal = "publish_running" | "not_a_repository" | "no_origin" | "commit_not_local" | "push_refused";
4
+ /**
5
+ * What a promotion did to origin's branch of the environment it goes to: it
6
+ * pushed the commit, found origin holding it already (`held`), or did not
7
+ * move the branch (`refused`).
8
+ */
9
+ export type BranchMove = {
10
+ readonly kind: "pushed" | "held";
11
+ } | {
12
+ readonly kind: "refused";
13
+ readonly refusal: BranchMoveRefusal;
14
+ };
15
+ /**
16
+ * Points origin's branch of `environment` at `commit`, which AntelopeJS Cloud
17
+ * then deploys: pushes the commit while origin still holds what it held when
18
+ * read, and leaves the local branch where it is. A branch origin holds at
19
+ * `commit` already is not pushed again. Nothing moves while a publish runs:
20
+ * call it in a promotion's turn, during which no publish begins.
21
+ */
22
+ export declare function moveEnvironmentBranch(path: string, environment: EnvironmentName, commit: CommitId): Promise<BranchMove>;
23
+ export {};
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.moveEnvironmentBranch = moveEnvironmentBranch;
4
+ const command_1 = require("./command");
5
+ const refs_1 = require("./refs");
6
+ const repository_1 = require("./repository");
7
+ const write_lock_1 = require("./write-lock");
8
+ const PUSHED = { kind: "pushed" };
9
+ const HELD = { kind: "held" };
10
+ function refused(refusal) {
11
+ return { kind: "refused", refusal };
12
+ }
13
+ /**
14
+ * Points origin's branch of `environment` at `commit`, which AntelopeJS Cloud
15
+ * then deploys: pushes the commit while origin still holds what it held when
16
+ * read, and leaves the local branch where it is. A branch origin holds at
17
+ * `commit` already is not pushed again. Nothing moves while a publish runs:
18
+ * call it in a promotion's turn, during which no publish begins.
19
+ */
20
+ async function moveEnvironmentBranch(path, environment, commit) {
21
+ if ((0, write_lock_1.isPublishing)())
22
+ return refused("publish_running");
23
+ if (await (0, repository_1.readWorkTreeRoot)(path))
24
+ return refused("not_a_repository");
25
+ const branch = (0, refs_1.environmentBranch)(environment);
26
+ const ref = (0, refs_1.branchRef)(branch);
27
+ const origin = await (0, repository_1.readOrigin)(path, [ref]);
28
+ if (origin.kind !== "reachable")
29
+ return refused("no_origin");
30
+ const lease = (0, repository_1.originObject)(origin, ref) ?? null;
31
+ if (lease === commit)
32
+ return HELD;
33
+ const local = await (0, command_1.runGit)(path, [
34
+ "rev-parse",
35
+ "--verify",
36
+ "--quiet",
37
+ "--end-of-options",
38
+ `${commit}^{commit}`,
39
+ ]);
40
+ if (local.exitCode !== 0)
41
+ return refused("commit_not_local");
42
+ const push = await (0, command_1.runGit)(path, (0, refs_1.pushArguments)([(0, refs_1.environmentTarget)(environment, lease, local.stdout.trim())]));
43
+ (0, repository_1.forgetOrigin)(path);
44
+ return push.exitCode === 0 ? PUSHED : refused("push_refused");
45
+ }
46
+ //# sourceMappingURL=promotion.js.map
@@ -0,0 +1,42 @@
1
+ import { type ZodError, z } from "zod";
2
+ import { type Refusal } from "./refusal";
3
+ /**
4
+ * The body of a publish request. The commit message may be left out or empty
5
+ * when the publish pushes a pending version again; a new version needs one,
6
+ * which the publish checks once it knows which it makes.
7
+ */
8
+ export declare const publishInputSchema: z.ZodObject<{
9
+ message: z.ZodOptional<z.ZodString>;
10
+ versionName: z.ZodOptional<z.ZodString>;
11
+ releaseNotes: z.ZodOptional<z.ZodString>;
12
+ environment: z.ZodEffects<z.ZodString, string, string>;
13
+ }, "strip", z.ZodTypeAny, {
14
+ environment: string;
15
+ message?: string | undefined;
16
+ releaseNotes?: string | undefined;
17
+ versionName?: string | undefined;
18
+ }, {
19
+ environment: string;
20
+ message?: string | undefined;
21
+ releaseNotes?: string | undefined;
22
+ versionName?: string | undefined;
23
+ }>;
24
+ /** What the owner sends to publish the working copy as a version. */
25
+ export type PublishInput = z.infer<typeof publishInputSchema>;
26
+ /** Who a publish's commit and tag are written as. */
27
+ export type GitIdentity = {
28
+ readonly name: string;
29
+ readonly email: string;
30
+ };
31
+ /** The refusal of a request for a new version that has no commit message. */
32
+ export declare function missingMessage(): Refusal;
33
+ /** The refusal naming the first field a publish request gets wrong. */
34
+ export declare function inputRefusal(error: ZodError<unknown>): Refusal;
35
+ /**
36
+ * The name and email of a DMS user as git accepts them, or `null` when either
37
+ * is empty, so that git falls back to the repository's configuration.
38
+ */
39
+ export declare function gitIdentity(user: {
40
+ readonly name: string;
41
+ readonly email: string;
42
+ }): GitIdentity | null;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.publishInputSchema = void 0;
4
+ exports.missingMessage = missingMessage;
5
+ exports.inputRefusal = inputRefusal;
6
+ exports.gitIdentity = gitIdentity;
7
+ const zod_1 = require("zod");
8
+ const refs_1 = require("./refs");
9
+ const refusal_1 = require("./refusal");
10
+ const MAX_MESSAGE = 500;
11
+ const MAX_VERSION_NAME = 120;
12
+ const MAX_RELEASE_NOTES = 5_000;
13
+ const SINGLE_LINE = /^[^\r\n]*$/u;
14
+ const IDENTITY_UNSAFE = /[<>\n\r]/gu;
15
+ const WHOLE_BODY = "body";
16
+ const MESSAGE_FIELD = "message";
17
+ /**
18
+ * The body of a publish request. The commit message may be left out or empty
19
+ * when the publish pushes a pending version again; a new version needs one,
20
+ * which the publish checks once it knows which it makes.
21
+ */
22
+ exports.publishInputSchema = zod_1.z.object({
23
+ message: zod_1.z
24
+ .string()
25
+ .trim()
26
+ .max(MAX_MESSAGE, `Keep the commit message under ${MAX_MESSAGE} characters.`)
27
+ .optional(),
28
+ versionName: zod_1.z
29
+ .string()
30
+ .trim()
31
+ .max(MAX_VERSION_NAME, `Keep the version name under ${MAX_VERSION_NAME} characters.`)
32
+ .regex(SINGLE_LINE, "Write the version name on one line.")
33
+ .optional(),
34
+ releaseNotes: zod_1.z
35
+ .string()
36
+ .trim()
37
+ .max(MAX_RELEASE_NOTES, `Keep the release notes under ${MAX_RELEASE_NOTES} characters.`)
38
+ .optional(),
39
+ environment: zod_1.z
40
+ .string({ required_error: "Choose an environment." })
41
+ .refine(refs_1.isValidEnvironmentName, "Name the environment in lowercase letters, digits and dashes, such as preview."),
42
+ }, { invalid_type_error: "Send the publish request as a JSON object." });
43
+ /** The refusal of a request for a new version that has no commit message. */
44
+ function missingMessage() {
45
+ return (0, refusal_1.invalidInput)(MESSAGE_FIELD, "Write a commit message.");
46
+ }
47
+ /** The refusal naming the first field a publish request gets wrong. */
48
+ function inputRefusal(error) {
49
+ const [issue] = error.issues;
50
+ const [field = WHOLE_BODY] = issue?.path ?? [];
51
+ return (0, refusal_1.invalidInput)(String(field), issue?.message ?? "Send the publish request as a JSON object.");
52
+ }
53
+ /**
54
+ * The name and email of a DMS user as git accepts them, or `null` when either
55
+ * is empty, so that git falls back to the repository's configuration.
56
+ */
57
+ function gitIdentity(user) {
58
+ const name = user.name.replace(IDENTITY_UNSAFE, "").trim();
59
+ const email = user.email.replace(IDENTITY_UNSAFE, "").trim();
60
+ return name && email ? { name, email } : null;
61
+ }
62
+ //# sourceMappingURL=publish-input.js.map
@@ -0,0 +1,82 @@
1
+ import type { VersionRef } from "./versions";
2
+ /** The four steps of a publish, in the order they run. */
3
+ export declare const STEP_ORDER: readonly ["commit", "tag", "move", "push"];
4
+ /** One step of a publish. */
5
+ export type StepId = (typeof STEP_ORDER)[number];
6
+ /** Where a step stands. */
7
+ type StepState = "todo" | "running" | "done" | "skipped" | "failed";
8
+ /** A step of a publish as the publish dialog shows it. */
9
+ type PublishStep = {
10
+ readonly id: StepId;
11
+ readonly state: StepState;
12
+ /** "Commit 7 files", "Tag release/v16", "Move env/preview", "Push to origin". */
13
+ readonly title: string;
14
+ /** "on develop", "annotated · v2.16", "to 4be81a2", "tag + 2 branches". */
15
+ readonly detail: string;
16
+ /** Each git command the step ran (`$ git …`) and what it printed, credentials hidden. */
17
+ readonly log: string;
18
+ };
19
+ /** Whether origin holds, after a failed push, the object the publish pushed to a ref. */
20
+ export type OriginRef = {
21
+ readonly ref: string;
22
+ readonly reached: boolean;
23
+ };
24
+ /** Where a publish stopped and what it left on origin. */
25
+ type PublishFailure = {
26
+ readonly step: StepId;
27
+ readonly message: string;
28
+ /** Each ref the push step sent; empty when the publish stopped before it. */
29
+ readonly origin: readonly OriginRef[];
30
+ };
31
+ /** A publish of this process: the version it makes and its four steps. */
32
+ export type PublishJob = {
33
+ readonly id: string;
34
+ readonly status: "running" | "succeeded" | "failed";
35
+ readonly version: VersionRef;
36
+ readonly environment: string;
37
+ readonly steps: readonly PublishStep[];
38
+ readonly failure: PublishFailure | null;
39
+ /** The commit the publish pushes, known once the commit step ended; `null` before. */
40
+ readonly commit: string | null;
41
+ readonly startedAt: string;
42
+ readonly finishedAt: string | null;
43
+ };
44
+ /** What happened to a running publish. */
45
+ export type JobEvent = {
46
+ readonly type: "started";
47
+ readonly step: StepId;
48
+ } | {
49
+ readonly type: "finished";
50
+ readonly step: StepId;
51
+ readonly state: "done" | "skipped";
52
+ readonly detail: string;
53
+ readonly log: string;
54
+ readonly at: string;
55
+ } | {
56
+ readonly type: "committed";
57
+ readonly commit: string;
58
+ } | {
59
+ readonly type: "failed";
60
+ readonly step: StepId;
61
+ readonly message: string;
62
+ readonly log: string;
63
+ readonly origin: readonly OriginRef[];
64
+ readonly at: string;
65
+ };
66
+ /** The title and detail of each step before it runs. */
67
+ export type StepLabels = Readonly<Record<StepId, {
68
+ readonly title: string;
69
+ readonly detail: string;
70
+ }>>;
71
+ /** A new running publish whose steps are all still to do. */
72
+ export declare function startJob(id: string, version: VersionRef, environment: string, labels: StepLabels, startedAt: string): PublishJob;
73
+ /**
74
+ * Applies an event to a publish. A step starts only after the ones before it
75
+ * ended; the publish names its commit once the commit step ended; it succeeds
76
+ * when its last step ends, and fails, leaving the steps after it to do, when
77
+ * one step fails.
78
+ *
79
+ * @throws When the event does not follow from the publish's state.
80
+ */
81
+ export declare function reduceJob(job: PublishJob, event: JobEvent): PublishJob;
82
+ export {};
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.STEP_ORDER = void 0;
4
+ exports.startJob = startJob;
5
+ exports.reduceJob = reduceJob;
6
+ /** The four steps of a publish, in the order they run. */
7
+ exports.STEP_ORDER = ["commit", "tag", "move", "push"];
8
+ /** A new running publish whose steps are all still to do. */
9
+ function startJob(id, version, environment, labels, startedAt) {
10
+ return {
11
+ id,
12
+ status: "running",
13
+ version,
14
+ environment,
15
+ steps: exports.STEP_ORDER.map((step) => ({
16
+ id: step,
17
+ state: "todo",
18
+ ...labels[step],
19
+ log: "",
20
+ })),
21
+ failure: null,
22
+ commit: null,
23
+ startedAt,
24
+ finishedAt: null,
25
+ };
26
+ }
27
+ function expectState(job, step, state) {
28
+ const current = job.steps.find(({ id }) => id === step);
29
+ if (job.status !== "running" || current?.state !== state) {
30
+ throw new Error(`The ${step} step of publish ${job.id} is not ${state}: ${current?.state ?? "missing"}`);
31
+ }
32
+ return current;
33
+ }
34
+ function replaceStep(job, step) {
35
+ return job.steps.map((current) => (current.id === step.id ? step : current));
36
+ }
37
+ function start(job, step) {
38
+ const next = job.steps.find(({ state }) => state === "todo");
39
+ if (next?.id !== step) {
40
+ throw new Error(`Publish ${job.id} cannot start ${step} now`);
41
+ }
42
+ return {
43
+ ...job,
44
+ steps: replaceStep(job, {
45
+ ...expectState(job, step, "todo"),
46
+ state: "running",
47
+ }),
48
+ };
49
+ }
50
+ function committed(job, commit) {
51
+ const step = job.steps.find(({ id }) => id === "commit");
52
+ const ended = step?.state === "done" || step?.state === "skipped";
53
+ if (job.status !== "running" || !ended || job.commit !== null) {
54
+ throw new Error(`Publish ${job.id} cannot name its commit now`);
55
+ }
56
+ return { ...job, commit };
57
+ }
58
+ /**
59
+ * Applies an event to a publish. A step starts only after the ones before it
60
+ * ended; the publish names its commit once the commit step ended; it succeeds
61
+ * when its last step ends, and fails, leaving the steps after it to do, when
62
+ * one step fails.
63
+ *
64
+ * @throws When the event does not follow from the publish's state.
65
+ */
66
+ function reduceJob(job, event) {
67
+ if (event.type === "started")
68
+ return start(job, event.step);
69
+ if (event.type === "committed")
70
+ return committed(job, event.commit);
71
+ const running = expectState(job, event.step, "running");
72
+ if (event.type === "failed") {
73
+ return {
74
+ ...job,
75
+ status: "failed",
76
+ steps: replaceStep(job, { ...running, state: "failed", log: event.log }),
77
+ failure: {
78
+ step: event.step,
79
+ message: event.message,
80
+ origin: event.origin,
81
+ },
82
+ finishedAt: event.at,
83
+ };
84
+ }
85
+ const steps = replaceStep(job, {
86
+ ...running,
87
+ state: event.state,
88
+ detail: event.detail,
89
+ log: event.log,
90
+ });
91
+ const last = event.step === exports.STEP_ORDER[exports.STEP_ORDER.length - 1];
92
+ return {
93
+ ...job,
94
+ status: last ? "succeeded" : "running",
95
+ steps,
96
+ finishedAt: last ? event.at : null,
97
+ };
98
+ }
99
+ //# sourceMappingURL=publish-job.js.map