@invarn/cli 0.2.4 → 0.2.6

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.
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env node
2
+
3
+ // lib/local-run-worker.mjs
4
+ import { resolve } from "node:path";
5
+ var [, , pipelinePath, workflow] = process.argv;
6
+ if (!pipelinePath || !workflow) {
7
+ send({
8
+ type: "crashed",
9
+ error: "usage: local-run-worker <pipelinePath> <workflow>"
10
+ });
11
+ process.exit(2);
12
+ }
13
+ function send(msg) {
14
+ if (typeof process.send === "function") {
15
+ process.send(msg);
16
+ }
17
+ }
18
+ async function main() {
19
+ send({ type: "started" });
20
+ let cibuildLib;
21
+ try {
22
+ cibuildLib = await import("@invarn/cibuild/lib");
23
+ } catch (err) {
24
+ send({
25
+ type: "crashed",
26
+ error: `failed to load @invarn/cibuild/lib: ${err?.message ?? String(err)}`
27
+ });
28
+ process.exit(2);
29
+ }
30
+ const {
31
+ loadYAMLPipeline,
32
+ convertYAMLToPipelineDef,
33
+ PipelineRunner,
34
+ loadConfig
35
+ } = cibuildLib;
36
+ const absPath = resolve(process.cwd(), pipelinePath);
37
+ let yamlPipeline;
38
+ try {
39
+ yamlPipeline = loadYAMLPipeline(absPath);
40
+ } catch (err) {
41
+ send({
42
+ type: "failed",
43
+ exitCode: 1,
44
+ failureReason: `Pipeline YAML load failed: ${err?.message ?? String(err)}`
45
+ });
46
+ process.exit(1);
47
+ }
48
+ const config = loadConfig();
49
+ config.local = true;
50
+ let pipeline;
51
+ try {
52
+ const converted = await convertYAMLToPipelineDef(
53
+ yamlPipeline,
54
+ config,
55
+ workflow,
56
+ absPath
57
+ );
58
+ pipeline = converted.pipeline;
59
+ var warnings = converted.warnings;
60
+ var skippedSteps = converted.skippedSteps;
61
+ } catch (err) {
62
+ send({
63
+ type: "failed",
64
+ exitCode: 1,
65
+ failureReason: `Pipeline definition error: ${err?.message ?? String(err)}`
66
+ });
67
+ process.exit(1);
68
+ }
69
+ const runner = new PipelineRunner(config);
70
+ try {
71
+ await runner.runPipeline(pipeline, warnings, skippedSteps);
72
+ send({ type: "completed", exitCode: 0 });
73
+ process.exit(0);
74
+ } catch (err) {
75
+ const message = err?.message ?? String(err);
76
+ const stepMatch = /Step\s+"([^"]+)"\s+failed/i.exec(message);
77
+ const failedStepName = stepMatch ? stepMatch[1] : null;
78
+ send({
79
+ type: "failed",
80
+ exitCode: typeof err?.exitCode === "number" ? err.exitCode : 1,
81
+ failureReason: message,
82
+ failedStepName
83
+ });
84
+ process.exit(1);
85
+ }
86
+ }
87
+ main().catch((err) => {
88
+ send({
89
+ type: "crashed",
90
+ error: `worker uncaught: ${err?.message ?? String(err)}`
91
+ });
92
+ process.exit(2);
93
+ });