@olivervea/pipelines 2.0.0-beta.2 → 2.0.0-beta.20

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 (54) hide show
  1. package/README.md +125 -62
  2. package/manifest.schema.json +208 -11
  3. package/package.json +6 -4
  4. package/src/assets.d.ts +2 -2
  5. package/src/build/build.ts +121 -51
  6. package/src/build/cli.ts +29 -22
  7. package/src/build/elf.ts +8 -7
  8. package/src/build/hashes.ts +82 -20
  9. package/src/build/project.ts +95 -28
  10. package/src/builder/pipeline.ts +344 -88
  11. package/src/builder/refs.ts +15 -5
  12. package/src/core/brands.ts +7 -5
  13. package/src/core/config-refs.ts +103 -0
  14. package/src/core/config.ts +224 -0
  15. package/src/core/external.ts +86 -0
  16. package/src/core/handlers.ts +61 -15
  17. package/src/core/models.ts +32 -15
  18. package/src/core/origin.ts +23 -0
  19. package/src/core/secrets.ts +2 -2
  20. package/src/core/steps.ts +89 -38
  21. package/src/core/types.ts +5 -1
  22. package/src/core/webhooks.ts +21 -7
  23. package/src/ctx/files.ts +111 -40
  24. package/src/ctx/index.ts +84 -31
  25. package/src/ctx/sh.ts +105 -44
  26. package/src/ctx/types.ts +12 -4
  27. package/src/describe/describe.ts +701 -133
  28. package/src/describe/manifest-schema.ts +258 -61
  29. package/src/describe/mapper-source.ts +249 -104
  30. package/src/describe/record.ts +67 -37
  31. package/src/dev/cli.ts +72 -35
  32. package/src/harness/env.ts +45 -25
  33. package/src/harness/execute.ts +58 -29
  34. package/src/harness/index.ts +22 -9
  35. package/src/harness/main.ts +239 -78
  36. package/src/harness/result.ts +38 -22
  37. package/src/harness/validate.ts +77 -15
  38. package/src/index.ts +124 -11
  39. package/src/library/checks.ts +28 -0
  40. package/src/library/compose-deploy.ts +113 -0
  41. package/src/library/github-source.ts +100 -47
  42. package/src/library/helm-deploy-ssh.ts +452 -108
  43. package/src/library/helm-deploy.ts +449 -0
  44. package/src/library/http-health.ts +7 -5
  45. package/src/library/image-build.ts +499 -105
  46. package/src/library/index.ts +48 -12
  47. package/src/library/models.ts +33 -9
  48. package/src/library/ssh.ts +67 -0
  49. package/src/testing/index.ts +74 -36
  50. package/src/util/canonical.ts +7 -4
  51. package/src/util/handler-hash.ts +17 -7
  52. package/src/util/hash.ts +5 -5
  53. package/src/util/tar.ts +86 -36
  54. package/src/library/script.ts +0 -85
@@ -1,138 +1,332 @@
1
1
  // The manifest format, defined once in zod. `manifest.schema.json` is generated from this
2
2
  // (bun scripts/gen-manifest-schema.ts) and describe validates every manifest against it.
3
- import { z } from "zod";
3
+ import { z } from 'zod';
4
4
 
5
- export const API_VERSION = "2.0";
5
+ export const API_VERSION = '2.0';
6
6
 
7
- const stepName = z.string().regex(/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/).describe("Step name: lower-case kebab, 1-63 chars. The step's identity.");
8
- const modelName = z.string().regex(/^[A-Za-z][A-Za-z0-9_]*$/).describe("Model name (key of `models`).");
9
- const secretName = z.string().regex(/^[A-Z_][A-Z0-9_]*$/).describe("Secret name; also the env var name in the step container.");
7
+ const stepName = z
8
+ .string()
9
+ .regex(/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/)
10
+ .describe("Step name: lower-case kebab, 1-63 chars. The step's identity.");
11
+ const modelName = z
12
+ .string()
13
+ .regex(/^[A-Za-z][A-Za-z0-9_]*$/)
14
+ .describe('Model name (key of `models`).');
15
+ const secretName = z
16
+ .string()
17
+ .regex(/^[A-Z_][A-Z0-9_]*$/)
18
+ .describe('Secret name; also the env var name in the step container.');
19
+ const configName = z
20
+ .string()
21
+ .regex(/^[a-z][a-zA-Z0-9]*$/)
22
+ .describe("Config entry name; a key of the pipeline's config document.");
10
23
  const hash = z.string().regex(/^sha256:[0-9a-f]{64}$/);
11
- const Json = z.json().meta({ id: "Json", description: "Any JSON value." });
12
- const jsonSchema = z.record(z.string(), z.unknown()).describe("A JSON Schema (draft 2020-12) object, canonical (sorted keys, no $schema).");
24
+ const Json = z.json().meta({ id: 'Json', description: 'Any JSON value.' });
25
+ const jsonSchema = z
26
+ .record(z.string(), z.unknown())
27
+ .describe('A JSON Schema (draft 2020-12) object, canonical (sorted keys, no $schema).');
13
28
 
14
29
  export const RefMapping = z
15
30
  .strictObject({
16
31
  ref: z
17
32
  .string()
18
33
  .regex(/^(?:input|failure|[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)(?:\.[^.]+)*$/)
19
- .describe("'<root>' or '<root>.<field>.<field>…'. Root: 'input' (pipeline input), a step name (that step's output) or 'failure' (FailureContext, failure handlers only)."),
34
+ .describe(
35
+ "'<root>' or '<root>.<field>.<field>…'. Root: 'input' (pipeline input), a step name (that step's output) or 'failure' (FailureContext, failure handlers only).",
36
+ ),
20
37
  })
21
- .describe("Value taken from the run pool. A ref whose root step was skipped yields no value (only allowed for optional inputs).");
22
- export const ConstMapping = z.strictObject({ const: Json }).describe("A JSON constant.");
38
+ .describe(
39
+ 'Value taken from the run pool. A ref whose root step was skipped yields no value (only allowed for optional inputs).',
40
+ );
41
+ export const ConstMapping = z.strictObject({ const: Json }).describe('A JSON constant.');
23
42
 
24
43
  export type Mapping = { ref: string } | { const: unknown } | { [field: string]: Mapping };
25
44
  export const Mapping: z.ZodType<Mapping> = z
26
45
  .union([
27
46
  RefMapping,
28
47
  ConstMapping,
29
- z.record(z.string(), z.lazy(() => Mapping)).describe(
30
- "An object built field by field. Discrimination: an object whose only key is 'ref' (string value) is a ref, whose only key is 'const' is a constant, anything else is a nested object (describe never emits a nested object whose only key is 'ref' or 'const').",
31
- ),
48
+ z
49
+ .record(
50
+ z.string(),
51
+ z.lazy(() => Mapping),
52
+ )
53
+ .describe(
54
+ "An object built field by field. Discrimination: an object whose only key is 'ref' (string value) is a ref, whose only key is 'const' is a constant, anything else is a nested object (describe never emits a nested object whose only key is 'ref' or 'const').",
55
+ ),
32
56
  ])
33
- .meta({ id: "Mapping" });
57
+ .meta({ id: 'Mapping' });
34
58
 
35
59
  export const ModelSchemas = z
36
60
  .strictObject({
37
- output: jsonSchema.describe("z.output view: validates step outputs, trigger results and the pool. Every object has additionalProperties: false."),
38
- input: jsonSchema.optional().describe("z.input view (defaults make fields optional; `default` values are listed). Present only when it differs from `output`."),
61
+ output: jsonSchema.describe(
62
+ 'z.output view: validates step outputs, trigger results and the pool. Every object has additionalProperties: false.',
63
+ ),
64
+ input: jsonSchema
65
+ .optional()
66
+ .describe(
67
+ 'z.input view (defaults make fields optional; `default` values are listed). Present only when it differs from `output`.',
68
+ ),
39
69
  })
40
- .meta({ id: "ModelSchemas" });
70
+ .meta({ id: 'ModelSchemas' });
41
71
 
42
72
  export const InputType = z
43
73
  .union([
44
- z.strictObject({ model: modelName, optional: z.boolean().describe("optional(Model): may be absent because its producer was skipped.") }),
45
- z.strictObject({ schema: ModelSchemas.describe("A plain (unnamed) zod schema. Such inputs always have an explicit mapping.") }),
74
+ z.strictObject({
75
+ model: modelName,
76
+ optional: z
77
+ .boolean()
78
+ .describe('optional(Model): may be absent because its producer was skipped.'),
79
+ }),
80
+ z.strictObject({
81
+ schema: ModelSchemas.describe(
82
+ 'A plain (unnamed) zod schema. Such inputs always have an explicit mapping.',
83
+ ),
84
+ }),
46
85
  ])
47
- .meta({ id: "InputType" });
86
+ .meta({ id: 'InputType' });
48
87
 
49
88
  export const StepDescriptor = z
50
89
  .strictObject({
51
90
  name: stepName,
52
- description: z.string().describe("What the step does, shown in the UI (may be empty)."),
53
- kind: z.enum(["custom", "script", "gitHubSource", "imageBuild", "helmDeployOverSsh"]).describe("'custom' = handlers/<name>.ts; others are SDK library steps."),
54
- image: z.string().min(1).describe("Container image the step runs in."),
55
- inputTypes: z.record(z.string(), InputType).describe("Declared input entries, keyed like input.json."),
56
- input: z.record(z.string(), Mapping).describe("How the service assembles input.json: one mapping per input key (same keys as inputTypes)."),
57
- output: modelName.nullable().describe("Output model, or null if the step produces no output."),
58
- secrets: z.array(secretName).describe("Declared secrets (sorted). Mount exactly these, as env vars of the same name."),
59
- handlerHash: hash.describe("Implementation identity: handler bundle (contract files excluded) + harness (bun + sdkHash); for library steps kind + config + harness."),
91
+ description: z
92
+ .string()
93
+ .describe('What the step does, shown in the UI (may be empty).'),
94
+ kind: z
95
+ .string()
96
+ .min(1)
97
+ .describe(
98
+ "'custom' = the handler is a handlers/*.ts file; any other kind is a step that carries its implementation (an SDK or package step). A label: the service accepts any kind.",
99
+ ),
100
+ image: z.string().min(1).describe('Container image the step runs in.'),
101
+ inputTypes: z
102
+ .record(z.string(), InputType)
103
+ .describe('Declared input entries, keyed like input.json.'),
104
+ input: z
105
+ .record(z.string(), Mapping)
106
+ .describe(
107
+ 'How the service assembles input.json: one mapping per input key (same keys as inputTypes).',
108
+ ),
109
+ output: modelName
110
+ .nullable()
111
+ .describe('Output model, or null if the step produces no output.'),
112
+ secrets: z
113
+ .array(secretName)
114
+ .describe(
115
+ 'Declared secrets (sorted). Mount exactly these, as env vars of the same name.',
116
+ ),
117
+ handlerHash: hash.describe(
118
+ 'Implementation identity: handler bundle (contract files excluded) + harness (bun + sdkHash); for a step that carries its implementation kind + config + harness + the hash of the code of its kind.',
119
+ ),
60
120
  timeoutSeconds: z.number().int().positive().optional(),
61
121
  retries: z.number().int().nonnegative().optional(),
62
- config: z.record(z.string(), Json).optional().describe("Library-step configuration (display only; already covered by handlerHash)."),
122
+ config: z
123
+ .record(z.string(), Json)
124
+ .optional()
125
+ .describe(
126
+ 'The step\'s settings (display only; already covered by handlerHash). A config reference is recorded as {"$config": "<entry>.<field>…"}; the entry is in configEntries.',
127
+ ),
128
+ configEntries: z
129
+ .array(configName)
130
+ .optional()
131
+ .describe(
132
+ "Config entries the step receives (sorted; omitted when none). The service delivers them in input.json under '$config'.",
133
+ ),
134
+ clusterAccess: z
135
+ .literal(true)
136
+ .optional()
137
+ .describe(
138
+ "The step pod gets the instance's step ServiceAccount token (Kubernetes:StepServiceAccount), if the instance grants one. Omitted = no token.",
139
+ ),
140
+ externalInputs: z
141
+ .record(
142
+ z.string(),
143
+ z.strictObject({
144
+ model: modelName.describe(
145
+ "The value is validated against this model's input view.",
146
+ ),
147
+ title: z.string().min(1).describe('What is asked, shown to whoever answers.'),
148
+ description: z.string(),
149
+ from: z
150
+ .array(
151
+ z.discriminatedUnion('kind', [
152
+ z.strictObject({ kind: z.literal('person') }),
153
+ z.strictObject({ kind: z.literal('callback') }),
154
+ z.strictObject({
155
+ kind: z.literal('poll'),
156
+ url: z
157
+ .string()
158
+ .describe(
159
+ 'GET while waiting; {run.id} and {run.number} are filled in.',
160
+ ),
161
+ valuePath: z
162
+ .string()
163
+ .min(1)
164
+ .describe("Dot path to the value; '.' is the whole body."),
165
+ intervalSeconds: z.int().min(10),
166
+ }),
167
+ ]),
168
+ )
169
+ .min(1)
170
+ .describe('Who or what may answer.'),
171
+ }),
172
+ )
173
+ .optional()
174
+ .describe(
175
+ 'Inputs answered from outside the run (omitted when none): the step waits until every one has a value, which the service writes into input.json under its key.',
176
+ ),
63
177
  })
64
- .meta({ id: "Step" });
178
+ .meta({ id: 'Step' });
65
179
 
66
- export type Stage = { steps: z.infer<typeof StepDescriptor>[] } | { when: Record<string, (string | number | boolean)[]>; stages: Stage[] };
180
+ export type Stage =
181
+ | { steps: z.infer<typeof StepDescriptor>[] }
182
+ | { when: Record<string, (string | number | boolean)[]>; stages: Stage[] }
183
+ | { select: string; discriminator: string; cases: Record<string, Stage[]> };
67
184
  export const Stage: z.ZodType<Stage> = z
68
185
  .union([
69
- z.strictObject({ steps: z.array(StepDescriptor).min(1).describe("Steps run in parallel; the stage is a barrier.") }),
70
186
  z.strictObject({
71
- when: z.record(z.string(), z.array(z.union([z.string(), z.number(), z.boolean()])).min(1)).describe(
72
- "Pipeline-input field → accepted values (all fields must match). Empty object = always.",
73
- ),
187
+ steps: z
188
+ .array(StepDescriptor)
189
+ .min(1)
190
+ .describe('Steps run in parallel; the stage is a barrier.'),
191
+ }),
192
+ z.strictObject({
193
+ when: z
194
+ .record(
195
+ z.string(),
196
+ z.array(z.union([z.string(), z.number(), z.boolean()])).min(1),
197
+ )
198
+ .describe(
199
+ 'Pipeline-input field → accepted values (all fields must match). Empty object = always.',
200
+ ),
74
201
  stages: z.array(z.lazy(() => Stage)),
75
202
  }),
203
+ z.strictObject({
204
+ select: z
205
+ .string()
206
+ .min(1)
207
+ .describe(
208
+ "Config reference (`<entry>.<field>…`) to a discriminated union; the run's config snapshot picks the case.",
209
+ ),
210
+ discriminator: z
211
+ .string()
212
+ .min(1)
213
+ .describe("The union's literal field whose value names the case."),
214
+ cases: z
215
+ .record(z.string(), z.array(z.lazy(() => Stage)))
216
+ .describe(
217
+ 'Discriminator value → stages. Exactly one case runs; a step name may repeat across cases, nowhere else.',
218
+ ),
219
+ }),
76
220
  ])
77
- .meta({ id: "Stage" });
221
+ .meta({ id: 'Stage' });
78
222
 
79
223
  export const Trigger = z
80
- .discriminatedUnion("kind", [
81
- z.strictObject({ kind: z.literal("push"), name: z.literal("push") }).describe("GitHub push. Event = the webhook payload."),
224
+ .discriminatedUnion('kind', [
225
+ z
226
+ .strictObject({ kind: z.literal('push'), name: z.literal('push') })
227
+ .describe('GitHub push. Event = the webhook payload.'),
82
228
  z
83
229
  .strictObject({
84
- kind: z.literal("poll"),
230
+ kind: z.literal('poll'),
85
231
  name: z.string().regex(/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/),
86
232
  url: z.string(),
87
- headers: z.record(z.string(), z.string()).describe("Values may contain '$SECRET:NAME' (NAME ∈ secrets)."),
233
+ headers: z
234
+ .record(z.string(), z.string())
235
+ .describe("Values may contain '$SECRET:NAME' (NAME ∈ secrets)."),
88
236
  secrets: z.array(secretName),
89
- valuePath: z.string().describe("Dot path into the JSON response; a change triggers map-trigger with {\"value\": <string>}."),
237
+ valuePath: z
238
+ .string()
239
+ .describe(
240
+ 'Dot path into the JSON response; a change triggers map-trigger with {"value": <string>}.',
241
+ ),
90
242
  intervalSeconds: z.number().int().positive(),
91
243
  })
92
- .describe("Background poller."),
244
+ .describe('Background poller.'),
93
245
  z
94
246
  .strictObject({
95
- kind: z.literal("webhook"),
247
+ kind: z.literal('webhook'),
96
248
  name: z.string().regex(/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/),
97
- verify: z.discriminatedUnion("scheme", [
249
+ verify: z.discriminatedUnion('scheme', [
98
250
  z.strictObject({
99
- scheme: z.literal("hmac-sha256"),
251
+ scheme: z.literal('hmac-sha256'),
100
252
  secret: secretName,
101
253
  header: z.string().min(1),
102
- prefix: z.string().describe("Text before the hex digest in the header, e.g. 'sha256='."),
254
+ prefix: z
255
+ .string()
256
+ .describe("Text before the hex digest in the header, e.g. 'sha256='."),
103
257
  }),
104
- z.strictObject({ scheme: z.literal("bearer"), secret: secretName }),
258
+ z.strictObject({ scheme: z.literal('bearer'), secret: secretName }),
105
259
  ]),
106
260
  })
107
- .describe("Inbound HTTP delivery to /api/hooks/<pipeline id>/<name>. Event = {headers, body}; a null mapping ignores it."),
261
+ .describe(
262
+ 'Inbound HTTP delivery to /api/hooks/<pipeline id>/<name>. Event = {headers, body}; a null mapping ignores it.',
263
+ ),
108
264
  ])
109
- .meta({ id: "Trigger" });
265
+ .meta({ id: 'Trigger' });
110
266
 
111
267
  export const Manifest = z
112
268
  .strictObject({
113
269
  apiVersion: z.literal(API_VERSION),
114
270
  name: z.string().min(1),
115
271
  description: z.string().optional(),
116
- input: modelName.describe("Pipeline input model."),
272
+ input: modelName.describe('Pipeline input model.'),
117
273
  harness: z
118
274
  .strictObject({
119
- bun: z.string().describe("Bun runtime version compiled into the binary."),
120
- sdk: z.string().describe("@olve/pipelines package version."),
121
- sdkHash: hash.describe("Hash of the SDK runtime sources + zod version."),
275
+ bun: z.string().describe('Bun runtime version compiled into the binary.'),
276
+ sdk: z.string().describe('@olivervea/pipelines package version.'),
277
+ sdkHash: hash.describe('Hash of the SDK runtime sources + zod version.'),
122
278
  })
123
- .describe("Harness identity. Already folded into every handlerHash."),
124
- models: z.record(modelName, ModelSchemas).describe("Every model referenced by the pipeline (input, step inputs/outputs)."),
125
- secrets: z.array(z.strictObject({ name: secretName, description: z.string() })).describe("All declared secrets (steps + poll triggers), sorted by name."),
279
+ .describe('Harness identity. Already folded into every handlerHash.'),
280
+ models: z
281
+ .record(modelName, ModelSchemas)
282
+ .describe('Every model referenced by the pipeline (input, step inputs/outputs).'),
283
+ secrets: z
284
+ .array(z.strictObject({ name: secretName, description: z.string() }))
285
+ .describe('All declared secrets (steps + poll triggers), sorted by name.'),
286
+ config: z
287
+ .array(
288
+ z.strictObject({
289
+ name: configName,
290
+ description: z.string(),
291
+ required: z
292
+ .boolean()
293
+ .describe(
294
+ 'False when the schema accepts a missing value (optional, or a default).',
295
+ ),
296
+ schema: jsonSchema.describe(
297
+ "z.input view: validates the config document's value for this entry (defaults listed).",
298
+ ),
299
+ }),
300
+ )
301
+ .optional()
302
+ .describe(
303
+ 'Config entries used by steps, sorted by name (omitted when none). Fields of kind secretRef ({secret: NAME}) name a secret.',
304
+ ),
305
+ retention: z
306
+ .strictObject({
307
+ keepLatestRuns: z.int().min(0).optional(),
308
+ minRunAgeDays: z.int().min(0).optional(),
309
+ buildGraceDays: z.int().min(0).optional(),
310
+ })
311
+ .optional()
312
+ .describe(
313
+ 'Retention overrides for this pipeline (omitted when none). Each field replaces the instance setting of the same meaning.',
314
+ ),
126
315
  triggers: z.array(Trigger),
127
316
  stages: z.array(Stage),
128
317
  failureHandlers: z.array(
129
318
  z.strictObject({
130
- step: StepDescriptor.describe("The handler step. Not part of any stage; its inputs are all FailureContext ({ref: 'failure'})."),
131
- steps: z.array(stepName).nullable().describe("Steps whose failure triggers the handler (null = any step)."),
319
+ step: StepDescriptor.describe(
320
+ "The handler step. Not part of any stage; its inputs are all FailureContext ({ref: 'failure'}).",
321
+ ),
322
+ steps: z
323
+ .array(stepName)
324
+ .nullable()
325
+ .describe('Steps whose failure triggers the handler (null = any step).'),
132
326
  }),
133
327
  ),
134
328
  })
135
- .meta({ id: "Manifest", title: "Olve.Pipelines v2 manifest" });
329
+ .meta({ id: 'Manifest', title: 'Olve.Pipelines v2 manifest' });
136
330
 
137
331
  export type ManifestT = z.infer<typeof Manifest>;
138
332
  export type StepDescriptorT = z.infer<typeof StepDescriptor>;
@@ -141,6 +335,9 @@ export type ModelSchemasT = z.infer<typeof ModelSchemas>;
141
335
 
142
336
  /** The JSON Schema document written to manifest.schema.json. */
143
337
  export function manifestJsonSchema(): Record<string, unknown> {
144
- const js = z.toJSONSchema(Manifest, { target: "draft-2020-12" }) as Record<string, unknown>;
145
- return { ...js, $id: "https://olve.dev/schemas/pipelines/manifest-2.0.json" };
338
+ const js = z.toJSONSchema(Manifest, { target: 'draft-2020-12' }) as Record<
339
+ string,
340
+ unknown
341
+ >;
342
+ return { ...js, $id: 'https://olve.dev/schemas/pipelines/manifest-2.0.json' };
146
343
  }