@kici-dev/sdk 0.0.0 → 0.1.2
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.
- package/LICENSE +202 -0
- package/README.md +1 -6
- package/dist/api-types.d.ts +47 -0
- package/dist/api-types.js +15 -0
- package/dist/chunk-gOLHoazu.js +4 -0
- package/dist/context.d.ts +185 -0
- package/dist/context.js +2 -0
- package/dist/dynamic-group.d.ts +29 -0
- package/dist/dynamic-group.js +34 -0
- package/dist/errors.d.ts +9 -0
- package/dist/errors.js +17 -0
- package/dist/events/define-event.d.ts +32 -0
- package/dist/events/define-event.js +29 -0
- package/dist/events/event-payloads.d.ts +396 -0
- package/dist/events/event-payloads.js +21 -0
- package/dist/events/index.d.ts +6 -0
- package/dist/events/index.js +4 -0
- package/dist/events/types.d.ts +13 -0
- package/dist/events/types.js +2 -0
- package/dist/fixture.d.ts +50 -0
- package/dist/fixture.js +35 -0
- package/dist/hooks/index.d.ts +33 -0
- package/dist/hooks/index.js +94 -0
- package/dist/hooks/types.d.ts +35 -0
- package/dist/hooks/types.js +2 -0
- package/dist/idempotent.d.ts +71 -0
- package/dist/idempotent.js +77 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.js +50 -0
- package/dist/job.d.ts +31 -0
- package/dist/job.js +46 -0
- package/dist/matrix/expand.d.ts +32 -0
- package/dist/matrix/expand.js +77 -0
- package/dist/matrix/index.d.ts +4 -0
- package/dist/matrix/index.js +4 -0
- package/dist/matrix/types.d.ts +60 -0
- package/dist/matrix/types.js +18 -0
- package/dist/outputs.d.ts +86 -0
- package/dist/outputs.js +180 -0
- package/dist/rules/evaluator.d.ts +24 -0
- package/dist/rules/evaluator.js +52 -0
- package/dist/rules/index.d.ts +6 -0
- package/dist/rules/index.js +5 -0
- package/dist/rules/rule.d.ts +34 -0
- package/dist/rules/rule.js +37 -0
- package/dist/rules/types.d.ts +42 -0
- package/dist/rules/types.js +2 -0
- package/dist/secrets.d.ts +192 -0
- package/dist/secrets.js +132 -0
- package/dist/step.d.ts +50 -0
- package/dist/step.js +78 -0
- package/dist/triggers/comment.d.ts +20 -0
- package/dist/triggers/comment.js +47 -0
- package/dist/triggers/create.d.ts +20 -0
- package/dist/triggers/create.js +32 -0
- package/dist/triggers/delete.d.ts +20 -0
- package/dist/triggers/delete.js +29 -0
- package/dist/triggers/dispatch.d.ts +17 -0
- package/dist/triggers/dispatch.js +27 -0
- package/dist/triggers/fork.d.ts +17 -0
- package/dist/triggers/fork.js +26 -0
- package/dist/triggers/generic-webhook.d.ts +32 -0
- package/dist/triggers/generic-webhook.js +45 -0
- package/dist/triggers/index.d.ts +28 -0
- package/dist/triggers/index.js +25 -0
- package/dist/triggers/job-complete.d.ts +23 -0
- package/dist/triggers/job-complete.js +33 -0
- package/dist/triggers/kici-event.d.ts +23 -0
- package/dist/triggers/kici-event.js +34 -0
- package/dist/triggers/lifecycle.d.ts +20 -0
- package/dist/triggers/lifecycle.js +29 -0
- package/dist/triggers/pr.d.ts +27 -0
- package/dist/triggers/pr.js +48 -0
- package/dist/triggers/push.d.ts +29 -0
- package/dist/triggers/push.js +48 -0
- package/dist/triggers/release.d.ts +17 -0
- package/dist/triggers/release.js +27 -0
- package/dist/triggers/review-comment.d.ts +17 -0
- package/dist/triggers/review-comment.js +27 -0
- package/dist/triggers/review.d.ts +17 -0
- package/dist/triggers/review.js +28 -0
- package/dist/triggers/schedule.d.ts +20 -0
- package/dist/triggers/schedule.js +29 -0
- package/dist/triggers/star.d.ts +17 -0
- package/dist/triggers/star.js +27 -0
- package/dist/triggers/status.d.ts +17 -0
- package/dist/triggers/status.js +28 -0
- package/dist/triggers/tag.d.ts +20 -0
- package/dist/triggers/tag.js +31 -0
- package/dist/triggers/types.d.ts +529 -0
- package/dist/triggers/types.js +36 -0
- package/dist/triggers/watch.d.ts +17 -0
- package/dist/triggers/watch.js +27 -0
- package/dist/triggers/webhook.d.ts +19 -0
- package/dist/triggers/webhook.js +29 -0
- package/dist/triggers/workflow-complete.d.ts +23 -0
- package/dist/triggers/workflow-complete.js +32 -0
- package/dist/triggers/workflow-run.d.ts +17 -0
- package/dist/triggers/workflow-run.js +29 -0
- package/dist/types.d.ts +483 -0
- package/dist/types.js +35 -0
- package/dist/validation/dag.d.ts +42 -0
- package/dist/validation/dag.js +70 -0
- package/dist/validation/index.d.ts +3 -0
- package/dist/validation/index.js +3 -0
- package/dist/wait-for.d.ts +109 -0
- package/dist/wait-for.js +144 -0
- package/dist/workflow.d.ts +3 -0
- package/dist/workflow.js +83 -0
- package/package.json +42 -6
- package/sbom.spdx.json +9150 -0
- package/index.js +0 -3
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import "../chunk-gOLHoazu.js";
|
|
2
|
+
//#region src/triggers/workflow-complete.ts
|
|
3
|
+
/**
|
|
4
|
+
* Create a workflow completion trigger configuration.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* // Match any workflow completion
|
|
8
|
+
* workflowComplete()
|
|
9
|
+
*
|
|
10
|
+
* // Match specific workflow by name
|
|
11
|
+
* workflowComplete({ name: 'CI' })
|
|
12
|
+
*
|
|
13
|
+
* // Match successful completions only
|
|
14
|
+
* workflowComplete({ name: 'CI', status: ['success'] })
|
|
15
|
+
*
|
|
16
|
+
* // Cross-repo source filter
|
|
17
|
+
* workflowComplete({ name: 'CI', status: ['success'], source: 'org/repo' })
|
|
18
|
+
*/
|
|
19
|
+
function workflowComplete(config) {
|
|
20
|
+
const result = {
|
|
21
|
+
_tag: "WorkflowCompleteTrigger",
|
|
22
|
+
...config?.name !== void 0 && { name: config.name },
|
|
23
|
+
...config?.status !== void 0 && { status: Object.freeze([...config.status]) },
|
|
24
|
+
...config?.source !== void 0 && { source: config.source },
|
|
25
|
+
...config?.description !== void 0 && { description: config.description }
|
|
26
|
+
};
|
|
27
|
+
return Object.freeze(result);
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { workflowComplete };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=workflow-complete.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow run trigger helper - creates triggers for workflow_run events.
|
|
3
|
+
* Returns a frozen WorkflowRunTriggerConfig directly.
|
|
4
|
+
*/
|
|
5
|
+
import type { WorkflowRunConfigInput, WorkflowRunTriggerConfig } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Create a workflow run trigger configuration.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* // Match any workflow run event
|
|
11
|
+
* workflowRun()
|
|
12
|
+
*
|
|
13
|
+
* // Match specific workflows and conclusions
|
|
14
|
+
* workflowRun({ workflows: ['CI'], actions: ['completed'], conclusions: ['success'] })
|
|
15
|
+
*/
|
|
16
|
+
export declare function workflowRun(config?: WorkflowRunConfigInput): WorkflowRunTriggerConfig;
|
|
17
|
+
//# sourceMappingURL=workflow-run.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import "../chunk-gOLHoazu.js";
|
|
2
|
+
import { asArray, toBranchPattern } from "./types.js";
|
|
3
|
+
//#region src/triggers/workflow-run.ts
|
|
4
|
+
/**
|
|
5
|
+
* Create a workflow run trigger configuration.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* // Match any workflow run event
|
|
9
|
+
* workflowRun()
|
|
10
|
+
*
|
|
11
|
+
* // Match specific workflows and conclusions
|
|
12
|
+
* workflowRun({ workflows: ['CI'], actions: ['completed'], conclusions: ['success'] })
|
|
13
|
+
*/
|
|
14
|
+
function workflowRun(config) {
|
|
15
|
+
const repos = config?.repos ? asArray(config.repos).map(toBranchPattern) : [];
|
|
16
|
+
const result = {
|
|
17
|
+
_tag: "WorkflowRunTrigger",
|
|
18
|
+
actions: Object.freeze(config?.actions ? [...config.actions] : []),
|
|
19
|
+
workflows: Object.freeze(config?.workflows ? [...config.workflows] : []),
|
|
20
|
+
conclusions: Object.freeze(config?.conclusions ? [...config.conclusions] : []),
|
|
21
|
+
repos: Object.freeze([...repos]),
|
|
22
|
+
...config?.description !== void 0 && { description: config.description }
|
|
23
|
+
};
|
|
24
|
+
return Object.freeze(result);
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { workflowRun };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=workflow-run.js.map
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { $ as Shell } from 'zx';
|
|
3
|
+
import type { ResourceRequest } from '@kici-dev/engine';
|
|
4
|
+
import type { StepContext, Logger } from './context.js';
|
|
5
|
+
import type { TriggerConfig } from './triggers/types.js';
|
|
6
|
+
import type { Rule } from './rules/types.js';
|
|
7
|
+
import type { Matrix, MatrixInclude, MatrixExclude } from './matrix/types.js';
|
|
8
|
+
import type { HookInput } from './hooks/types.js';
|
|
9
|
+
import type { KiciApi } from './api-types.js';
|
|
10
|
+
import type { DynamicGroupRef } from './dynamic-group.js';
|
|
11
|
+
export type { ResourceRequest, ResourceSpec } from '@kici-dev/engine';
|
|
12
|
+
/** Source location captured at a step() call site. */
|
|
13
|
+
export interface SourceLocation {
|
|
14
|
+
readonly file: string;
|
|
15
|
+
readonly line: number;
|
|
16
|
+
readonly column: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* OutputProxy<T> represents a lazy proxy over step/job outputs.
|
|
20
|
+
* At the type level it mirrors T's shape for type-safe property access.
|
|
21
|
+
* At runtime it's a Proxy that defers property access to an OutputsMap.
|
|
22
|
+
*/
|
|
23
|
+
export type OutputProxy<T> = {
|
|
24
|
+
readonly [K in keyof T]: T[K];
|
|
25
|
+
};
|
|
26
|
+
/** Output schema type - record of Zod types */
|
|
27
|
+
export type OutputSchema = Record<string, z.ZodTypeAny>;
|
|
28
|
+
/** Infer the output type from an output schema */
|
|
29
|
+
export type InferOutputs<T extends OutputSchema> = z.infer<z.ZodObject<T>>;
|
|
30
|
+
/**
|
|
31
|
+
* Step definition returned by step() factory.
|
|
32
|
+
*
|
|
33
|
+
* TResult is the inferred return type of the run function (defaults to void for backward compat).
|
|
34
|
+
* The optional `outputs` field holds a Zod schema for runtime validation but does NOT drive the generic.
|
|
35
|
+
*/
|
|
36
|
+
export interface Step<TResult = void> {
|
|
37
|
+
readonly _tag: 'Step';
|
|
38
|
+
/** Step name. Empty string for id-less steps (compiler assigns counter IDs). */
|
|
39
|
+
readonly name: string;
|
|
40
|
+
/** Optional Zod schema for runtime output validation. */
|
|
41
|
+
readonly outputs?: OutputSchema;
|
|
42
|
+
readonly run: (ctx: StepContext) => Promise<TResult>;
|
|
43
|
+
/** When true, job proceeds even if this step fails (recorded as failed but not fatal). */
|
|
44
|
+
readonly continueOnError?: boolean;
|
|
45
|
+
/** Step-level timeout in milliseconds. Overrides the agent's default (30 minutes). */
|
|
46
|
+
readonly timeout?: number;
|
|
47
|
+
/** Step-level conditional rules (evaluated agent-side). */
|
|
48
|
+
readonly rules?: Rule[];
|
|
49
|
+
/** Runs on cancellation. */
|
|
50
|
+
readonly onCancel?: HookInput;
|
|
51
|
+
/** Always runs after step (success, failure, or cancel). */
|
|
52
|
+
readonly cleanup?: HookInput;
|
|
53
|
+
/** Internal: source location captured at step() call site. Not part of public API. */
|
|
54
|
+
readonly _sourceLocation?: SourceLocation;
|
|
55
|
+
/**
|
|
56
|
+
* Type-safe proxy for accessing this step's outputs.
|
|
57
|
+
* Only meaningful when TResult is non-void. Accessing .result on a void step is a compile-time error.
|
|
58
|
+
* At runtime, resolves against the shared outputs map populated by the workflow runner.
|
|
59
|
+
*/
|
|
60
|
+
readonly result: TResult extends void ? never : OutputProxy<TResult>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Bare async function accepted directly in the steps array.
|
|
64
|
+
* Counter-named at compile time, return-type-inferred, no Zod validation.
|
|
65
|
+
*/
|
|
66
|
+
export type BareStepFn<TResult = void> = (ctx: StepContext) => Promise<TResult>;
|
|
67
|
+
/**
|
|
68
|
+
* Union type for items accepted in a job's steps array.
|
|
69
|
+
* Accepts both Step objects and bare async functions.
|
|
70
|
+
*/
|
|
71
|
+
export type StepInput = Step<any> | BareStepFn<any>;
|
|
72
|
+
/** Options for step() factory - simple form (just async function) */
|
|
73
|
+
export type StepRunFn = (ctx: StepContext) => Promise<void>;
|
|
74
|
+
/** Options for step() factory - full form with outputs and generic return type */
|
|
75
|
+
export interface StepOptions<TResult = void> {
|
|
76
|
+
/** Optional Zod schema for runtime output validation. */
|
|
77
|
+
outputs?: OutputSchema;
|
|
78
|
+
run: (ctx: StepContext) => Promise<TResult>;
|
|
79
|
+
/** When true, job proceeds even if this step fails (recorded as failed but not fatal). */
|
|
80
|
+
continueOnError?: boolean;
|
|
81
|
+
/** Step-level timeout in milliseconds. Overrides the agent's default (30 minutes). */
|
|
82
|
+
timeout?: number;
|
|
83
|
+
/** Step-level conditional rules (evaluated agent-side). */
|
|
84
|
+
rules?: Rule[];
|
|
85
|
+
/** Runs on cancellation. */
|
|
86
|
+
onCancel?: HookInput;
|
|
87
|
+
/** Always runs after step (success, failure, or cancel). */
|
|
88
|
+
cleanup?: HookInput;
|
|
89
|
+
}
|
|
90
|
+
/** Trigger type (config objects returned by pr()/push() factory functions) */
|
|
91
|
+
export type Trigger = TriggerConfig;
|
|
92
|
+
/**
|
|
93
|
+
* Context passed to dynamic job generator functions.
|
|
94
|
+
* Uses destructured form: async ({$, ctx, log, env}) => jobs
|
|
95
|
+
*
|
|
96
|
+
* **Determinism requirement:** the executing agent re-evaluates the DynamicJobFn
|
|
97
|
+
* to extract step closures (functions can't be serialized). For a given job name,
|
|
98
|
+
* the re-evaluation must produce a job with the same name and the same steps.
|
|
99
|
+
*
|
|
100
|
+
* - `ctx.event` is deterministic — frozen from the original webhook payload.
|
|
101
|
+
* - `$`, `env`, and `kici` can return different results between eval and re-eval
|
|
102
|
+
* (different agent, different time, different infrastructure state).
|
|
103
|
+
*
|
|
104
|
+
* **Guidance:** derive job names and structure from `ctx.event` data whenever
|
|
105
|
+
* possible. If you use `kici.infrastructure.list()` or shell commands to
|
|
106
|
+
* determine job names, be aware that changes between eval and re-eval will
|
|
107
|
+
* cause a non-determinism warning (or failure if a job disappears).
|
|
108
|
+
*/
|
|
109
|
+
export interface DynamicJobContext {
|
|
110
|
+
/** zx shell executor for running commands */
|
|
111
|
+
$: typeof Shell;
|
|
112
|
+
/** Event context and workflow metadata */
|
|
113
|
+
ctx: {
|
|
114
|
+
workflow: {
|
|
115
|
+
name: string;
|
|
116
|
+
};
|
|
117
|
+
event?: Record<string, unknown>;
|
|
118
|
+
};
|
|
119
|
+
/** Structured logger */
|
|
120
|
+
log: Logger;
|
|
121
|
+
/** Environment variables */
|
|
122
|
+
env: Record<string, string | undefined>;
|
|
123
|
+
/** Typed KiCI API — orchestrator queries over WS (e.g., kici.infrastructure.list()) */
|
|
124
|
+
kici: KiciApi;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Async function that generates jobs dynamically at runtime.
|
|
128
|
+
* Signature: async ({$, ctx, log, env}) => Job[]
|
|
129
|
+
*
|
|
130
|
+
* **Determinism contract:** this function is called twice — once during the eval
|
|
131
|
+
* phase (to discover which jobs to create) and once during execution (to extract
|
|
132
|
+
* step closures for the specific job being run). The second call must produce a
|
|
133
|
+
* job with the same name and equivalent steps as the first call.
|
|
134
|
+
*
|
|
135
|
+
* A mismatch in sibling job names triggers a warning; a missing target job
|
|
136
|
+
* causes a hard failure with a clear determinism error.
|
|
137
|
+
*
|
|
138
|
+
* See `docs/architecture/dynamic-jobs.md` for the full re-evaluation flow.
|
|
139
|
+
*/
|
|
140
|
+
export type DynamicJobFn = (context: DynamicJobContext) => Promise<Job[]>;
|
|
141
|
+
/**
|
|
142
|
+
* A job definition or an async function that generates jobs.
|
|
143
|
+
* Used in workflow jobs array for mixing static and dynamic jobs.
|
|
144
|
+
*/
|
|
145
|
+
export type JobOrFactory = Job | DynamicJobFn;
|
|
146
|
+
/**
|
|
147
|
+
* Type guard to check if a JobOrFactory is a dynamic job generator.
|
|
148
|
+
*/
|
|
149
|
+
export declare function isDynamicJobFn(item: JobOrFactory): item is DynamicJobFn;
|
|
150
|
+
declare const DYNAMIC_JOB_GROUP_TAG: unique symbol;
|
|
151
|
+
/** A DynamicJobFn tagged with a group name via dynamicJob(). */
|
|
152
|
+
export interface TaggedDynamicJobFn extends DynamicJobFn {
|
|
153
|
+
readonly [DYNAMIC_JOB_GROUP_TAG]: string;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Tag a DynamicJobFn with a group name for cross-domain needs.
|
|
157
|
+
* Static jobs can then depend on this group via `needs: [dynamicGroup('name')]`.
|
|
158
|
+
*
|
|
159
|
+
* @param groupName - The group name (must match what static jobs reference)
|
|
160
|
+
* @param fn - The dynamic job generator function
|
|
161
|
+
*/
|
|
162
|
+
export declare function dynamicJob(groupName: string, fn: DynamicJobFn): TaggedDynamicJobFn;
|
|
163
|
+
/**
|
|
164
|
+
* Get the group name from a DynamicJobFn, if it was tagged with dynamicJob().
|
|
165
|
+
* Returns undefined for untagged functions.
|
|
166
|
+
*/
|
|
167
|
+
export declare function getDynamicJobGroup(fn: DynamicJobFn): string | undefined;
|
|
168
|
+
export { DYNAMIC_JOB_GROUP_TAG };
|
|
169
|
+
/**
|
|
170
|
+
* Container configuration for job execution.
|
|
171
|
+
* When set, all steps run inside the specified container.
|
|
172
|
+
*/
|
|
173
|
+
export interface ContainerConfig {
|
|
174
|
+
/** Docker image name (e.g., 'node:20-alpine') */
|
|
175
|
+
image: string;
|
|
176
|
+
/** Additional environment variables for the container */
|
|
177
|
+
env?: Record<string, string>;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Structured runsOn selector with required and excluded labels.
|
|
181
|
+
* Used when jobs need to target specific agents while excluding others.
|
|
182
|
+
*
|
|
183
|
+
* **Reserved namespace:** Labels with the `kici:` prefix are reserved for internal use
|
|
184
|
+
* (e.g., `kici:role:builder`, `kici:role:init-runner`). User-supplied labels starting with
|
|
185
|
+
* `kici:` will be rejected at compile time and agent startup.
|
|
186
|
+
*/
|
|
187
|
+
export interface RunsOnSelector {
|
|
188
|
+
labels: string | string[];
|
|
189
|
+
exclude?: string | string[];
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Polymorphic runsOn type: string shorthand, array shorthand, or full selector object.
|
|
193
|
+
* - `'linux'` — single label shorthand
|
|
194
|
+
* - `['linux', 'docker']` — multi-label shorthand
|
|
195
|
+
* - `{ labels: ['linux', 'docker'], exclude: ['gpu'] }` — full selector with exclusions
|
|
196
|
+
*
|
|
197
|
+
* **Reserved namespace:** Labels with the `kici:` prefix are reserved for internal use
|
|
198
|
+
* (e.g., `kici:role:builder`, `kici:role:init-runner`). User-supplied labels starting with
|
|
199
|
+
* `kici:` will be rejected at compile time and agent startup.
|
|
200
|
+
*/
|
|
201
|
+
export type RunsOn = string | string[] | RunsOnSelector;
|
|
202
|
+
/** Job definition returned by job() factory */
|
|
203
|
+
export interface Job {
|
|
204
|
+
readonly _tag: 'Job';
|
|
205
|
+
readonly name: string;
|
|
206
|
+
readonly runsOn: RunsOn;
|
|
207
|
+
readonly steps: readonly StepInput[];
|
|
208
|
+
readonly needs?: ReadonlyArray<Job | string | DynamicGroupRef | {
|
|
209
|
+
name: string;
|
|
210
|
+
ifFailed: 'skip' | 'run';
|
|
211
|
+
} | {
|
|
212
|
+
group: string;
|
|
213
|
+
ifFailed: 'skip' | 'run';
|
|
214
|
+
}>;
|
|
215
|
+
/** Rules for conditional execution */
|
|
216
|
+
readonly rules?: Rule[];
|
|
217
|
+
/** Optional description */
|
|
218
|
+
readonly description?: string;
|
|
219
|
+
/** Matrix configuration (unexpanded) */
|
|
220
|
+
readonly matrix?: Matrix;
|
|
221
|
+
/** Include combinations */
|
|
222
|
+
readonly include?: MatrixInclude[];
|
|
223
|
+
/** Exclude combinations */
|
|
224
|
+
readonly exclude?: MatrixExclude[];
|
|
225
|
+
/** When false, agent skips git clone (default: true). Useful for deploy/notify jobs. */
|
|
226
|
+
readonly checkout?: boolean;
|
|
227
|
+
/** Docker image for job execution. All steps run inside the container. */
|
|
228
|
+
readonly container?: string | ContainerConfig;
|
|
229
|
+
/** Deployment environment for this job. String for static, async function for dynamic (resolved at orchestrator two-phase eval). */
|
|
230
|
+
readonly environment?: string | ((event: Record<string, unknown>) => string | Promise<string>);
|
|
231
|
+
/** Environment variables. Static object or async function (resolved at orchestrator two-phase eval). */
|
|
232
|
+
readonly env?: Record<string, string> | ((event: Record<string, unknown>) => Record<string, string> | Promise<Record<string, string>>);
|
|
233
|
+
/** Concurrency group name. Defaults to environment name if not set. String or async function. */
|
|
234
|
+
readonly concurrencyGroup?: string | ((event: Record<string, unknown>) => string | Promise<string>);
|
|
235
|
+
/** Runs on cancellation. */
|
|
236
|
+
readonly onCancel?: HookInput;
|
|
237
|
+
/** Always runs after job (success, failure, or cancel). */
|
|
238
|
+
readonly cleanup?: HookInput;
|
|
239
|
+
/** Runs on job success. */
|
|
240
|
+
readonly onSuccess?: HookInput;
|
|
241
|
+
/** Runs on job failure. */
|
|
242
|
+
readonly onFailure?: HookInput;
|
|
243
|
+
/** Runs before each step in this job. */
|
|
244
|
+
readonly beforeStep?: HookInput;
|
|
245
|
+
/** Runs after each step in this job. */
|
|
246
|
+
readonly afterStep?: HookInput;
|
|
247
|
+
/** Seconds before SIGKILL after SIGTERM during cancellation. */
|
|
248
|
+
readonly gracePeriod?: number;
|
|
249
|
+
/**
|
|
250
|
+
* Resource request and limit for this job. Used by the scaler to enforce
|
|
251
|
+
* per-scaler / per-orchestrator / per-machine caps and the kernel-side limits
|
|
252
|
+
* on the spawned agent.
|
|
253
|
+
*
|
|
254
|
+
* `requests` drive scheduler accounting (cap aggregation).
|
|
255
|
+
* `limits` drive kernel enforcement (Docker memory + nanoCpus, FC memSizeMib + vcpuCount,
|
|
256
|
+
* optional bare-metal systemd-run scope).
|
|
257
|
+
*
|
|
258
|
+
* If only one side is set, the other inherits its values. If neither is set,
|
|
259
|
+
* the scaler default applies; if neither is set anywhere, the job counts only
|
|
260
|
+
* toward the agent-count cap.
|
|
261
|
+
*/
|
|
262
|
+
readonly resources?: ResourceRequest;
|
|
263
|
+
/**
|
|
264
|
+
* Type-safe proxy for accessing this job's outputs.
|
|
265
|
+
* For multi-step jobs: jobRef.result.stepName.field
|
|
266
|
+
* For single-step (run shorthand) jobs: jobRef.result.field
|
|
267
|
+
* At runtime, resolves against the shared job outputs map populated by the workflow runner.
|
|
268
|
+
*/
|
|
269
|
+
readonly result: OutputProxy<any>;
|
|
270
|
+
}
|
|
271
|
+
/** Options for job() factory */
|
|
272
|
+
export interface JobOptions {
|
|
273
|
+
runsOn: RunsOn;
|
|
274
|
+
/**
|
|
275
|
+
* Steps to execute in this job. Accepts Step objects and bare async functions.
|
|
276
|
+
* Mutually exclusive with `run`.
|
|
277
|
+
*/
|
|
278
|
+
steps?: StepInput[];
|
|
279
|
+
/**
|
|
280
|
+
* Single-step shorthand: an async function that becomes the job's only step.
|
|
281
|
+
* Mutually exclusive with `steps`.
|
|
282
|
+
*/
|
|
283
|
+
run?: (ctx: StepContext) => Promise<any>;
|
|
284
|
+
needs?: Array<Job | string | DynamicGroupRef | {
|
|
285
|
+
name: string;
|
|
286
|
+
ifFailed: 'skip' | 'run';
|
|
287
|
+
} | {
|
|
288
|
+
group: string;
|
|
289
|
+
ifFailed: 'skip' | 'run';
|
|
290
|
+
}>;
|
|
291
|
+
/** Rules that must pass for job to execute */
|
|
292
|
+
rules?: Rule[];
|
|
293
|
+
/** Optional description for documentation */
|
|
294
|
+
description?: string;
|
|
295
|
+
/**
|
|
296
|
+
* Matrix configuration for job expansion.
|
|
297
|
+
* - Single dimension: string[] like ['linux', 'mac', 'windows']
|
|
298
|
+
* - Multi-dimensional: Record like {os: ['linux', 'mac'], node: ['18', '20']}
|
|
299
|
+
* - Dynamic: async function returning either form
|
|
300
|
+
*/
|
|
301
|
+
matrix?: Matrix;
|
|
302
|
+
/**
|
|
303
|
+
* Additional matrix combinations to include.
|
|
304
|
+
* Applied after expansion, can add combinations not in original matrix.
|
|
305
|
+
*/
|
|
306
|
+
include?: MatrixInclude[];
|
|
307
|
+
/**
|
|
308
|
+
* Matrix combinations to exclude.
|
|
309
|
+
* Applied before include, removes matching combinations.
|
|
310
|
+
*/
|
|
311
|
+
exclude?: MatrixExclude[];
|
|
312
|
+
/** When false, agent skips git clone (default: true). Useful for deploy/notify jobs. */
|
|
313
|
+
checkout?: boolean;
|
|
314
|
+
/**
|
|
315
|
+
* Docker image for job execution.
|
|
316
|
+
* Simple string form for image name, object form for additional config.
|
|
317
|
+
* When set, all steps run inside the container.
|
|
318
|
+
*/
|
|
319
|
+
container?: string | ContainerConfig;
|
|
320
|
+
/** Deployment environment for this job. String for static, async function for dynamic (resolved at orchestrator two-phase eval). */
|
|
321
|
+
environment?: string | ((event: Record<string, unknown>) => string | Promise<string>);
|
|
322
|
+
/** Environment variables. Static object or async function (resolved at orchestrator two-phase eval). */
|
|
323
|
+
env?: Record<string, string> | ((event: Record<string, unknown>) => Record<string, string> | Promise<Record<string, string>>);
|
|
324
|
+
/** Concurrency group name. Defaults to environment name if not set. String or async function. */
|
|
325
|
+
concurrencyGroup?: string | ((event: Record<string, unknown>) => string | Promise<string>);
|
|
326
|
+
/** Runs on cancellation. */
|
|
327
|
+
onCancel?: HookInput;
|
|
328
|
+
/** Always runs after job (success, failure, or cancel). */
|
|
329
|
+
cleanup?: HookInput;
|
|
330
|
+
/** Runs on job success. */
|
|
331
|
+
onSuccess?: HookInput;
|
|
332
|
+
/** Runs on job failure. */
|
|
333
|
+
onFailure?: HookInput;
|
|
334
|
+
/** Runs before each step in this job. */
|
|
335
|
+
beforeStep?: HookInput;
|
|
336
|
+
/** Runs after each step in this job. */
|
|
337
|
+
afterStep?: HookInput;
|
|
338
|
+
/** Seconds before SIGKILL after SIGTERM during cancellation. */
|
|
339
|
+
gracePeriod?: number;
|
|
340
|
+
/**
|
|
341
|
+
* Resource request and limit for this job. Used by the scaler to enforce
|
|
342
|
+
* per-scaler / per-orchestrator / per-machine caps and the kernel-side limits
|
|
343
|
+
* on the spawned agent.
|
|
344
|
+
*
|
|
345
|
+
* `requests` drive scheduler accounting (cap aggregation).
|
|
346
|
+
* `limits` drive kernel enforcement (Docker memory + nanoCpus, FC memSizeMib + vcpuCount,
|
|
347
|
+
* optional bare-metal systemd-run scope).
|
|
348
|
+
*
|
|
349
|
+
* If only one side is set, the other inherits its values. If neither is set,
|
|
350
|
+
* the scaler default applies; if neither is set anywhere, the job counts only
|
|
351
|
+
* toward the agent-count cap.
|
|
352
|
+
*/
|
|
353
|
+
resources?: ResourceRequest;
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Private npm registry declaration. Tells the agent to authenticate against
|
|
357
|
+
* a private package registry before running `npm install`.
|
|
358
|
+
*
|
|
359
|
+
* `tokenSecret` uses qualified `<environment>:<secret-name>` syntax — the
|
|
360
|
+
* orchestrator resolves the secret from the named environment's scoped secret
|
|
361
|
+
* store at dispatch time. Example: `tokenSecret: 'production:NPM_TOKEN'`.
|
|
362
|
+
*/
|
|
363
|
+
export interface Registry {
|
|
364
|
+
/** Registry URL (e.g. `https://npm.pkg.github.com`). */
|
|
365
|
+
readonly url: string;
|
|
366
|
+
/**
|
|
367
|
+
* Optional npm package scope this registry serves (e.g. `@my-org`).
|
|
368
|
+
* If omitted, the registry becomes the default (only one default per workflow).
|
|
369
|
+
*/
|
|
370
|
+
readonly scope?: string;
|
|
371
|
+
/**
|
|
372
|
+
* Qualified secret reference of the form `<environment>:<secret-name>`.
|
|
373
|
+
* The orchestrator resolves it at dispatch via `secretResolver.resolveForJob(orgId, environment)`.
|
|
374
|
+
*/
|
|
375
|
+
readonly tokenSecret: string;
|
|
376
|
+
/** Whether to require auth on every request (rendered as `always-auth=true` in `.npmrc`). Defaults to `true`. */
|
|
377
|
+
readonly alwaysAuth?: boolean;
|
|
378
|
+
}
|
|
379
|
+
/** Workflow definition returned by workflow() factory */
|
|
380
|
+
export interface Workflow {
|
|
381
|
+
readonly _tag: 'Workflow';
|
|
382
|
+
readonly name: string;
|
|
383
|
+
/**
|
|
384
|
+
* Jobs array (may contain static jobs and dynamic job generators).
|
|
385
|
+
* Dynamic generators are expanded at agent runtime.
|
|
386
|
+
*/
|
|
387
|
+
readonly jobs: JobOrFactory[];
|
|
388
|
+
/** Trigger configs (built from Trigger instances) */
|
|
389
|
+
readonly on?: TriggerConfig[];
|
|
390
|
+
/** Rules for conditional execution */
|
|
391
|
+
readonly rules?: Rule[];
|
|
392
|
+
/** Optional description */
|
|
393
|
+
readonly description?: string;
|
|
394
|
+
/**
|
|
395
|
+
* Optional paths or glob patterns (relative to repo root) to include in the workflow content hash.
|
|
396
|
+
* When any of these files change, the lock file content hash changes so cache is invalidated.
|
|
397
|
+
*/
|
|
398
|
+
readonly hashFiles?: string[];
|
|
399
|
+
/**
|
|
400
|
+
* Private npm registries the agent should authenticate against before `npm install`.
|
|
401
|
+
* Each registry's `tokenSecret` uses qualified `<environment>:<secret-name>` syntax.
|
|
402
|
+
*/
|
|
403
|
+
readonly registries?: readonly Registry[];
|
|
404
|
+
/**
|
|
405
|
+
* Extra secrets to project as environment variables on the install subprocess.
|
|
406
|
+
* Used together with a customer-committed `.kici/.npmrc` containing `${VAR}` placeholders.
|
|
407
|
+
* Each entry uses qualified `<environment>:<secret-name>` syntax; the resolved value is
|
|
408
|
+
* exposed to the install subprocess under the `<secret-name>` key (the environment
|
|
409
|
+
* prefix is stripped for the env-var name).
|
|
410
|
+
*/
|
|
411
|
+
readonly installEnv?: readonly string[];
|
|
412
|
+
/** Runs on cancellation. */
|
|
413
|
+
readonly onCancel?: HookInput;
|
|
414
|
+
/** Always runs after workflow (success, failure, or cancel). */
|
|
415
|
+
readonly cleanup?: HookInput;
|
|
416
|
+
/** Runs on workflow success. */
|
|
417
|
+
readonly onSuccess?: HookInput;
|
|
418
|
+
/** Runs on workflow failure. */
|
|
419
|
+
readonly onFailure?: HookInput;
|
|
420
|
+
/** Concurrency configuration for this workflow. */
|
|
421
|
+
readonly concurrency?: {
|
|
422
|
+
readonly group: (ctx: {
|
|
423
|
+
branch: string;
|
|
424
|
+
event: Record<string, unknown>;
|
|
425
|
+
}) => string;
|
|
426
|
+
readonly cancelInProgress?: boolean;
|
|
427
|
+
readonly max?: number;
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
/** Options for workflow() factory */
|
|
431
|
+
export interface WorkflowOptions {
|
|
432
|
+
/**
|
|
433
|
+
* Jobs in the workflow.
|
|
434
|
+
* Can be static Job objects or async functions that generate jobs.
|
|
435
|
+
* Dynamic job functions are evaluated at agent runtime.
|
|
436
|
+
*/
|
|
437
|
+
jobs: JobOrFactory[];
|
|
438
|
+
/** Trigger conditions - when should this workflow run */
|
|
439
|
+
on?: Trigger | Trigger[];
|
|
440
|
+
/** Rules that must pass for workflow to execute */
|
|
441
|
+
rules?: Rule[];
|
|
442
|
+
/** Optional description for documentation */
|
|
443
|
+
description?: string;
|
|
444
|
+
/**
|
|
445
|
+
* Optional paths or glob patterns (relative to repo root) to include in the workflow content hash.
|
|
446
|
+
* When any of these files change, the lock file content hash changes so cache is invalidated.
|
|
447
|
+
*/
|
|
448
|
+
hashFiles?: string[];
|
|
449
|
+
/**
|
|
450
|
+
* Private npm registries the agent should authenticate against before `npm install`.
|
|
451
|
+
* Each registry's `tokenSecret` uses qualified `<environment>:<secret-name>` syntax.
|
|
452
|
+
*/
|
|
453
|
+
registries?: Registry[];
|
|
454
|
+
/**
|
|
455
|
+
* Extra secrets to project as environment variables on the install subprocess.
|
|
456
|
+
* Used together with a customer-committed `.kici/.npmrc` containing `${VAR}` placeholders.
|
|
457
|
+
* Each entry uses qualified `<environment>:<secret-name>` syntax; the resolved value is
|
|
458
|
+
* exposed to the install subprocess under the `<secret-name>` key.
|
|
459
|
+
*/
|
|
460
|
+
installEnv?: string[];
|
|
461
|
+
/** Runs on cancellation. */
|
|
462
|
+
onCancel?: HookInput;
|
|
463
|
+
/** Always runs after workflow (success, failure, or cancel). */
|
|
464
|
+
cleanup?: HookInput;
|
|
465
|
+
/** Runs on workflow success. */
|
|
466
|
+
onSuccess?: HookInput;
|
|
467
|
+
/** Runs on workflow failure. */
|
|
468
|
+
onFailure?: HookInput;
|
|
469
|
+
/** Concurrency configuration for this workflow. */
|
|
470
|
+
concurrency?: {
|
|
471
|
+
group: (ctx: {
|
|
472
|
+
branch: string;
|
|
473
|
+
event: Record<string, unknown>;
|
|
474
|
+
}) => string;
|
|
475
|
+
cancelInProgress?: boolean;
|
|
476
|
+
max?: number;
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
export type { TriggerConfig, PrTriggerConfig, PushTriggerConfig } from './triggers/types.js';
|
|
480
|
+
export type { Rule, RuleContext, RuleCheckFn, RuleResult } from './rules/types.js';
|
|
481
|
+
export type { Matrix, MatrixInclude, MatrixExclude, MatrixValues } from './matrix/types.js';
|
|
482
|
+
export type { HookInput, HookFn, HookConfig, HookContext, OutcomeMetadata } from './hooks/types.js';
|
|
483
|
+
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import "./chunk-gOLHoazu.js";
|
|
2
|
+
//#region src/types.ts
|
|
3
|
+
/**
|
|
4
|
+
* Type guard to check if a JobOrFactory is a dynamic job generator.
|
|
5
|
+
*/
|
|
6
|
+
function isDynamicJobFn(item) {
|
|
7
|
+
return typeof item === "function";
|
|
8
|
+
}
|
|
9
|
+
const DYNAMIC_JOB_GROUP_TAG = Symbol.for("kici:dynamicJobGroup");
|
|
10
|
+
/**
|
|
11
|
+
* Tag a DynamicJobFn with a group name for cross-domain needs.
|
|
12
|
+
* Static jobs can then depend on this group via `needs: [dynamicGroup('name')]`.
|
|
13
|
+
*
|
|
14
|
+
* @param groupName - The group name (must match what static jobs reference)
|
|
15
|
+
* @param fn - The dynamic job generator function
|
|
16
|
+
*/
|
|
17
|
+
function dynamicJob(groupName, fn) {
|
|
18
|
+
const tagged = fn;
|
|
19
|
+
Object.defineProperty(tagged, DYNAMIC_JOB_GROUP_TAG, {
|
|
20
|
+
value: groupName,
|
|
21
|
+
enumerable: false
|
|
22
|
+
});
|
|
23
|
+
return tagged;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get the group name from a DynamicJobFn, if it was tagged with dynamicJob().
|
|
27
|
+
* Returns undefined for untagged functions.
|
|
28
|
+
*/
|
|
29
|
+
function getDynamicJobGroup(fn) {
|
|
30
|
+
return fn[DYNAMIC_JOB_GROUP_TAG];
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { DYNAMIC_JOB_GROUP_TAG, dynamicJob, getDynamicJobGroup, isDynamicJobFn };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a node in a Directed Acyclic Graph.
|
|
3
|
+
* Used for validating job dependency graphs.
|
|
4
|
+
*/
|
|
5
|
+
export interface DagNode {
|
|
6
|
+
id: string;
|
|
7
|
+
needs: string[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Result of DAG validation.
|
|
11
|
+
* Discriminated union for different validation outcomes.
|
|
12
|
+
*/
|
|
13
|
+
export type DagValidationResult = {
|
|
14
|
+
valid: true;
|
|
15
|
+
sortedOrder: string[];
|
|
16
|
+
} | {
|
|
17
|
+
valid: false;
|
|
18
|
+
error: 'cycle';
|
|
19
|
+
nodesInCycle: string[];
|
|
20
|
+
} | {
|
|
21
|
+
valid: false;
|
|
22
|
+
error: 'self-reference';
|
|
23
|
+
nodeId: string;
|
|
24
|
+
} | {
|
|
25
|
+
valid: false;
|
|
26
|
+
error: 'missing-dependency';
|
|
27
|
+
nodeId: string;
|
|
28
|
+
missingDep: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Validate a DAG for common issues: self-references, missing dependencies, and cycles.
|
|
32
|
+
*
|
|
33
|
+
* Validation order:
|
|
34
|
+
* 1. Check for self-references (node depends on itself)
|
|
35
|
+
* 2. Check for missing dependencies (depends on non-existent node)
|
|
36
|
+
* 3. Check for cycles using Kahn's algorithm
|
|
37
|
+
*
|
|
38
|
+
* @param nodes - Array of DAG nodes to validate
|
|
39
|
+
* @returns Validation result with error details or sorted order
|
|
40
|
+
*/
|
|
41
|
+
export declare function validateDag(nodes: DagNode[]): DagValidationResult;
|
|
42
|
+
//# sourceMappingURL=dag.d.ts.map
|