@olivervea/pipelines 2.0.0-beta.18 → 2.0.0-beta.19

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 (51) hide show
  1. package/package.json +4 -2
  2. package/src/assets.d.ts +2 -2
  3. package/src/build/build.ts +111 -43
  4. package/src/build/cli.ts +28 -21
  5. package/src/build/elf.ts +8 -7
  6. package/src/build/hashes.ts +61 -28
  7. package/src/build/project.ts +69 -30
  8. package/src/builder/pipeline.ts +274 -102
  9. package/src/builder/refs.ts +12 -6
  10. package/src/core/brands.ts +6 -6
  11. package/src/core/config-refs.ts +46 -20
  12. package/src/core/config.ts +110 -33
  13. package/src/core/external.ts +30 -12
  14. package/src/core/handlers.ts +54 -14
  15. package/src/core/models.ts +29 -14
  16. package/src/core/origin.ts +7 -4
  17. package/src/core/secrets.ts +2 -2
  18. package/src/core/steps.ts +39 -23
  19. package/src/core/types.ts +5 -1
  20. package/src/core/webhooks.ts +21 -7
  21. package/src/ctx/files.ts +111 -40
  22. package/src/ctx/index.ts +75 -34
  23. package/src/ctx/sh.ts +104 -44
  24. package/src/ctx/types.ts +4 -4
  25. package/src/describe/describe.ts +550 -196
  26. package/src/describe/manifest-schema.ts +210 -80
  27. package/src/describe/mapper-source.ts +249 -104
  28. package/src/describe/record.ts +67 -37
  29. package/src/dev/cli.ts +64 -34
  30. package/src/harness/env.ts +33 -27
  31. package/src/harness/execute.ts +55 -29
  32. package/src/harness/index.ts +21 -8
  33. package/src/harness/main.ts +197 -74
  34. package/src/harness/result.ts +38 -22
  35. package/src/harness/validate.ts +62 -19
  36. package/src/index.ts +123 -14
  37. package/src/library/checks.ts +11 -6
  38. package/src/library/compose-deploy.ts +40 -23
  39. package/src/library/github-source.ts +69 -39
  40. package/src/library/helm-deploy-ssh.ts +213 -76
  41. package/src/library/helm-deploy.ts +263 -85
  42. package/src/library/http-health.ts +7 -5
  43. package/src/library/image-build.ts +293 -117
  44. package/src/library/index.ts +47 -15
  45. package/src/library/models.ts +17 -9
  46. package/src/library/ssh.ts +31 -14
  47. package/src/testing/index.ts +63 -24
  48. package/src/util/canonical.ts +7 -4
  49. package/src/util/handler-hash.ts +15 -5
  50. package/src/util/hash.ts +5 -5
  51. package/src/util/tar.ts +74 -37
@@ -1,11 +1,11 @@
1
1
  // Layout of a pipeline directory and the identity of the SDK building it.
2
- import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
3
- import { dirname, join, relative, resolve } from "node:path";
4
- import { isImplementation } from "../core/handlers.ts";
5
- import { sha256Hex } from "../util/hash.ts";
6
- import type { HarnessInfo } from "../util/handler-hash.ts";
2
+ import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
3
+ import { dirname, join, relative, resolve } from 'node:path';
4
+ import { isImplementation } from '../core/handlers.ts';
5
+ import { sha256Hex } from '../util/hash.ts';
6
+ import type { HarnessInfo } from '../util/handler-hash.ts';
7
7
 
8
- export const SDK_ROOT = resolve(import.meta.dir, "../..");
8
+ export const SDK_ROOT = resolve(import.meta.dir, '../..');
9
9
 
10
10
  export interface Project {
11
11
  dir: string;
@@ -17,33 +17,56 @@ export interface Project {
17
17
  }
18
18
 
19
19
  export class ProjectError extends Error {
20
- override name = "ProjectError";
20
+ override name = 'ProjectError';
21
21
  }
22
22
 
23
23
  export async function loadProject(dirArg: string): Promise<Project> {
24
24
  const dir = resolve(dirArg);
25
- if (!existsSync(dir) || !statSync(dir).isDirectory()) throw new ProjectError(`${dirArg} is not a directory`);
26
- const pipelineFile = join(dir, "pipeline.ts");
27
- if (!existsSync(pipelineFile)) throw new ProjectError(`${join(dirArg, "pipeline.ts")} not found (it must default-export pipeline({...}))`);
28
- const contractFiles = ["pipeline.ts", "models.ts"].map((f) => join(dir, f)).filter((f) => existsSync(f));
29
- const hdir = join(dir, "handlers");
25
+ if (!existsSync(dir) || !statSync(dir).isDirectory())
26
+ throw new ProjectError(`${dirArg} is not a directory`);
27
+ const pipelineFile = join(dir, 'pipeline.ts');
28
+ if (!existsSync(pipelineFile))
29
+ throw new ProjectError(
30
+ `${join(dirArg, 'pipeline.ts')} not found (it must default-export pipeline({...}))`,
31
+ );
32
+ const contractFiles = ['pipeline.ts', 'models.ts']
33
+ .map((f) => join(dir, f))
34
+ .filter((f) => existsSync(f));
35
+ const hdir = join(dir, 'handlers');
30
36
  const files = existsSync(hdir)
31
37
  ? readdirSync(hdir)
32
- .filter((f) => f.endsWith(".ts") && !f.endsWith(".test.ts") && !f.endsWith(".d.ts") && statSync(join(hdir, f)).isFile())
38
+ .filter(
39
+ (f) =>
40
+ f.endsWith('.ts') &&
41
+ !f.endsWith('.test.ts') &&
42
+ !f.endsWith('.d.ts') &&
43
+ statSync(join(hdir, f)).isFile(),
44
+ )
33
45
  .sort()
34
46
  : [];
35
- return { dir, pipelineFile, contractFiles, handlers: await resolveHandlers(hdir, files) };
47
+ return {
48
+ dir,
49
+ pipelineFile,
50
+ contractFiles,
51
+ handlers: await resolveHandlers(hdir, files),
52
+ };
36
53
  }
37
54
 
38
55
  /** The default export of pipeline.ts. */
39
56
  export async function loadPipeline(project: Project): Promise<unknown> {
40
57
  const mod = (await import(project.pipelineFile)) as { default?: unknown };
41
- if (!mod.default) throw new ProjectError(`${project.pipelineFile} has no default export (export default pipeline({...})...)`);
58
+ if (!mod.default)
59
+ throw new ProjectError(
60
+ `${project.pipelineFile} has no default export (export default pipeline({...})...)`,
61
+ );
42
62
  return mod.default;
43
63
  }
44
64
 
45
65
  /** Pairs each handler file with the step its default export implements (file names don't matter). */
46
- async function resolveHandlers(hdir: string, files: string[]): Promise<[string, string][]> {
66
+ async function resolveHandlers(
67
+ hdir: string,
68
+ files: string[],
69
+ ): Promise<[string, string][]> {
47
70
  const byStep = new Map<string, string>();
48
71
  for (const f of files) {
49
72
  const file = join(hdir, f);
@@ -51,13 +74,20 @@ async function resolveHandlers(hdir: string, files: string[]): Promise<[string,
51
74
  try {
52
75
  impl = ((await import(file)) as { default?: unknown }).default;
53
76
  } catch (e) {
54
- throw new ProjectError(`handlers/${f} failed to load: ${(e as Error)?.message ?? String(e)}`);
77
+ throw new ProjectError(
78
+ `handlers/${f} failed to load: ${(e as Error)?.message ?? String(e)}`,
79
+ );
55
80
  }
56
81
  if (!isImplementation(impl))
57
- throw new ProjectError(`handlers/${f} must default-export implement(<step>, …); put shared code in a subfolder such as handlers/lib/`);
82
+ throw new ProjectError(
83
+ `handlers/${f} must default-export implement(<step>, …); put shared code in a subfolder such as handlers/lib/`,
84
+ );
58
85
  const step = (impl.step as { name: string }).name;
59
86
  const other = byStep.get(step);
60
- if (other) throw new ProjectError(`handlers/${other.slice(hdir.length + 1)} and handlers/${f} both implement step '${step}'`);
87
+ if (other)
88
+ throw new ProjectError(
89
+ `handlers/${other.slice(hdir.length + 1)} and handlers/${f} both implement step '${step}'`,
90
+ );
61
91
  byStep.set(step, file);
62
92
  }
63
93
  return [...byStep].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
@@ -80,28 +110,37 @@ let cached: HarnessInfo | undefined;
80
110
  */
81
111
  export function harnessInfo(): HarnessInfo {
82
112
  if (cached) return cached;
83
- const pkg = JSON.parse(readFileSync(join(SDK_ROOT, "package.json"), "utf8")) as { version: string };
84
- const src = join(SDK_ROOT, "src");
113
+ const pkg = JSON.parse(readFileSync(join(SDK_ROOT, 'package.json'), 'utf8')) as {
114
+ version: string;
115
+ };
116
+ const src = join(SDK_ROOT, 'src');
85
117
  const files = listFiles(src)
86
- .map((f) => relative(src, f).split("\\").join("/"))
87
- .filter((f) => !f.startsWith("build/") && !f.startsWith("dev/") && !f.startsWith("testing/") && f.endsWith(".ts"))
118
+ .map((f) => relative(src, f).split('\\').join('/'))
119
+ .filter(
120
+ (f) =>
121
+ !f.startsWith('build/') &&
122
+ !f.startsWith('dev/') &&
123
+ !f.startsWith('testing/') &&
124
+ f.endsWith('.ts'),
125
+ )
88
126
  .sort();
89
- const h = new Bun.CryptoHasher("sha256");
127
+ const h = new Bun.CryptoHasher('sha256');
90
128
  for (const f of files) h.update(`${f}\0${sha256Hex(readFileSync(join(src, f)))}\n`);
91
- let zodVersion = "unknown";
129
+ let zodVersion = 'unknown';
92
130
  try {
93
- const zodPkg = Bun.resolveSync("zod/package.json", SDK_ROOT);
94
- zodVersion = (JSON.parse(readFileSync(zodPkg, "utf8")) as { version: string }).version;
131
+ const zodPkg = Bun.resolveSync('zod/package.json', SDK_ROOT);
132
+ zodVersion = (JSON.parse(readFileSync(zodPkg, 'utf8')) as { version: string })
133
+ .version;
95
134
  } catch {
96
135
  /* keep unknown */
97
136
  }
98
137
  h.update(`zod@${zodVersion}\n`);
99
- cached = { bun: Bun.version, sdk: pkg.version, sdkHash: "sha256:" + h.digest("hex") };
138
+ cached = { bun: Bun.version, sdk: pkg.version, sdkHash: 'sha256:' + h.digest('hex') };
100
139
  return cached;
101
140
  }
102
141
 
103
142
  export const relPosix = (from: string, to: string) => {
104
- const r = relative(from, to).split("\\").join("/");
105
- return r.startsWith(".") ? r : `./${r}`;
143
+ const r = relative(from, to).split('\\').join('/');
144
+ return r.startsWith('.') ? r : `./${r}`;
106
145
  };
107
146
  export { dirname };