@scarn/sdk 0.8.2 → 0.8.3
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/dist/automations/define-automation.d.ts +20 -0
- package/dist/automations/index.d.ts +8 -0
- package/dist/automations/index.js +21 -0
- package/dist/automations/targets.d.ts +36 -0
- package/dist/automations/types.d.ts +116 -0
- package/dist/{chunk-nb0nkt71.js → chunk-01nfqm18.js} +1 -0
- package/dist/chunk-0vzq22dj.js +73 -0
- package/dist/chunk-11hbmexe.js +250 -0
- package/dist/{chunk-2fn95pdd.js → chunk-3gy0cb5f.js} +5 -1
- package/dist/{chunk-qrasq5xe.js → chunk-43y7tfn4.js} +33 -414
- package/dist/chunk-61jf8b6s.js +53 -0
- package/dist/chunk-76d1bwwz.js +119 -0
- package/dist/chunk-8z1wa3kd.js +109 -0
- package/dist/{chunk-p7yrcmqm.js → chunk-cnxaagfj.js} +2 -52
- package/dist/{chunk-cdanncng.js → chunk-ejzfdm1z.js} +21 -5
- package/dist/{chunk-gds7w7zh.js → chunk-fgfhvsee.js} +1 -4
- package/dist/{chunk-x9788y82.js → chunk-fyfvp6jx.js} +30 -13
- package/dist/{chunk-mz53r914.js → chunk-jj9pezwb.js} +22 -119
- package/dist/{chunk-8pyhrdgy.js → chunk-wnfj3wyx.js} +55 -11
- package/dist/chunk-x0hjhqrf.js +416 -0
- package/dist/chunk-y11p1q7r.js +159 -0
- package/dist/client.js +4 -2
- package/dist/contracts/automation-document/index.d.ts +5 -0
- package/dist/contracts/automation-document/index.js +34 -0
- package/dist/contracts/automation-document/schema.d.ts +363 -0
- package/dist/contracts/pipeline-document/built-ins.d.ts +1 -1
- package/dist/contracts/pipeline-document/index.js +9 -7
- package/dist/contracts/pipeline-document/schema.d.ts +3 -3
- package/dist/contracts/work-item-changes.d.ts +6 -0
- package/dist/contracts/work-item-changes.js +1 -0
- package/dist/defaults/index.js +2 -2
- package/dist/definitions/automations/automations-client.d.ts +178 -0
- package/dist/definitions/automations/index.d.ts +1 -0
- package/dist/definitions/automations/index.js +12 -0
- package/dist/definitions/pipelines/index.d.ts +0 -1
- package/dist/definitions/pipelines/index.js +4 -12
- package/dist/definitions/pipelines/work-item-fields.d.ts +11 -22
- package/dist/definitions/steps/define-code-step.d.ts +3 -1
- package/dist/definitions/steps/define-step.d.ts +13 -0
- package/dist/definitions/steps/index.js +9 -6
- package/dist/definitions/steps/repo.d.ts +11 -3
- package/dist/definitions/steps/runtime.d.ts +11 -12
- package/dist/definitions/steps/step-definitions-client.d.ts +12 -0
- package/dist/definitions/steps/step-features.d.ts +2 -2
- package/dist/definitions/steps/step-handle.d.ts +6 -1
- package/dist/definitions/validation/index.js +2 -2
- package/dist/generated/index.d.ts +2 -2
- package/dist/generated/sdk.gen.d.ts +37 -5
- package/dist/generated/types.gen.d.ts +2756 -1875
- package/dist/index.d.ts +1 -0
- package/dist/index.js +40 -30
- package/dist/pipelines/define-pipeline.d.ts +7 -7
- package/dist/pipelines/handles.d.ts +0 -5
- package/dist/pipelines/index.js +7 -4
- package/dist/pipelines/types.d.ts +13 -1
- package/dist/push/collect-definitions.d.ts +3 -8
- package/dist/push/collect-pipeline-documents.d.ts +13 -3
- package/dist/push/index.d.ts +2 -2
- package/dist/push/index.js +87 -124
- package/dist/push/push-from-directory.d.ts +10 -6
- package/dist/repo-config.d.ts +14 -4
- package/dist/repo-config.js +5 -1
- package/dist/task-plane-client.d.ts +40 -0
- package/package.json +13 -1
- package/dist/chunk-ra53p0v8.js +0 -256
- package/dist/definitions/pipelines/define-default-pipeline-assignment.d.ts +0 -263
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from "./contracts/artifact-markers";
|
|
|
5
5
|
export * from "./definitions/steps";
|
|
6
6
|
export * from "./definitions/pipelines";
|
|
7
7
|
export * from "./pipelines";
|
|
8
|
+
export * from "./automations";
|
|
8
9
|
export type { PipelineDefinition } from "./pipelines";
|
|
9
10
|
export * from "./opencode-mcp";
|
|
10
11
|
export * from "./jsonc";
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,13 @@ import {
|
|
|
3
3
|
SCARN_CONFIG_RELATIVE_PATH,
|
|
4
4
|
parseScarnConfig
|
|
5
5
|
} from "./chunk-0y2fy5en.js";
|
|
6
|
+
import {
|
|
7
|
+
PipelineDefinitionsApiError,
|
|
8
|
+
WORK_ITEM_FIELDS_PATH_PREFIX,
|
|
9
|
+
WORK_ITEM_TOP_LEVEL_FIELDS,
|
|
10
|
+
createPipelineDefinitionsClient,
|
|
11
|
+
resolveWorkItemFieldPath
|
|
12
|
+
} from "./chunk-8z1wa3kd.js";
|
|
6
13
|
import {
|
|
7
14
|
after,
|
|
8
15
|
all,
|
|
@@ -38,28 +45,26 @@ import {
|
|
|
38
45
|
sum,
|
|
39
46
|
workItem,
|
|
40
47
|
workItemField
|
|
41
|
-
} from "./chunk-
|
|
48
|
+
} from "./chunk-43y7tfn4.js";
|
|
49
|
+
import {
|
|
50
|
+
attach,
|
|
51
|
+
defineAutomation,
|
|
52
|
+
onEvent,
|
|
53
|
+
skip
|
|
54
|
+
} from "./chunk-11hbmexe.js";
|
|
55
|
+
import"./chunk-x0hjhqrf.js";
|
|
56
|
+
import"./chunk-76d1bwwz.js";
|
|
42
57
|
import {
|
|
43
58
|
parseJsonc,
|
|
44
59
|
stripJsoncComments,
|
|
45
60
|
stripTrailingCommas
|
|
46
61
|
} from "./chunk-rt9tq4j6.js";
|
|
47
|
-
import {
|
|
48
|
-
DEFAULT_PIPELINE_ASSIGNMENT_FILENAME,
|
|
49
|
-
PipelineDefinitionsApiError,
|
|
50
|
-
WORK_ITEM_FIELDS_PATH_PREFIX,
|
|
51
|
-
WORK_ITEM_TOP_LEVEL_FIELDS,
|
|
52
|
-
createPipelineDefinitionsClient,
|
|
53
|
-
defaultPipelineAssignment,
|
|
54
|
-
isDefaultPipelineAssignmentSpec,
|
|
55
|
-
resolveWorkItemFieldPath,
|
|
56
|
-
serializeDefaultPipelineAssignment
|
|
57
|
-
} from "./chunk-ra53p0v8.js";
|
|
58
62
|
import {
|
|
59
63
|
createScarnClient,
|
|
60
64
|
createTaskPlaneClient
|
|
61
|
-
} from "./chunk-
|
|
62
|
-
import"./chunk-
|
|
65
|
+
} from "./chunk-3gy0cb5f.js";
|
|
66
|
+
import"./chunk-61jf8b6s.js";
|
|
67
|
+
import"./chunk-cnxaagfj.js";
|
|
63
68
|
import {
|
|
64
69
|
ARTIFACT_BRAND,
|
|
65
70
|
Artifact,
|
|
@@ -74,6 +79,7 @@ import {
|
|
|
74
79
|
compileEnvironment,
|
|
75
80
|
compileMcps,
|
|
76
81
|
compileRepo,
|
|
82
|
+
compileStepConcurrency,
|
|
77
83
|
compileStepErrors,
|
|
78
84
|
compileStepMaxTurns,
|
|
79
85
|
compileStepRetry,
|
|
@@ -91,16 +97,7 @@ import {
|
|
|
91
97
|
resolveMcpChecks,
|
|
92
98
|
toStepHandle,
|
|
93
99
|
toStepSpec
|
|
94
|
-
} from "./chunk-
|
|
95
|
-
import"./chunk-63f90zky.js";
|
|
96
|
-
import {
|
|
97
|
-
PipelineBuildError,
|
|
98
|
-
formatIssue
|
|
99
|
-
} from "./chunk-mz53r914.js";
|
|
100
|
-
import"./chunk-5zsavw98.js";
|
|
101
|
-
import"./chunk-4ggr8af6.js";
|
|
102
|
-
import"./chunk-k4y5qt4y.js";
|
|
103
|
-
import"./chunk-cdanncng.js";
|
|
100
|
+
} from "./chunk-fyfvp6jx.js";
|
|
104
101
|
import {
|
|
105
102
|
collectEnvPlaceholderNames,
|
|
106
103
|
isEnvPlaceholderValue,
|
|
@@ -115,8 +112,19 @@ import {
|
|
|
115
112
|
openCodeResolvedMcpServerConfigSchema,
|
|
116
113
|
openCodeResolvedMcpServersSchema
|
|
117
114
|
} from "./chunk-e1h021kq.js";
|
|
115
|
+
import"./chunk-63f90zky.js";
|
|
116
|
+
import"./chunk-jj9pezwb.js";
|
|
117
|
+
import {
|
|
118
|
+
PipelineBuildError,
|
|
119
|
+
formatIssue
|
|
120
|
+
} from "./chunk-y11p1q7r.js";
|
|
121
|
+
import"./chunk-5zsavw98.js";
|
|
122
|
+
import"./chunk-4ggr8af6.js";
|
|
123
|
+
import"./chunk-k4y5qt4y.js";
|
|
124
|
+
import"./chunk-ejzfdm1z.js";
|
|
118
125
|
import {
|
|
119
126
|
Api,
|
|
127
|
+
Automations,
|
|
120
128
|
Billing,
|
|
121
129
|
Conversations,
|
|
122
130
|
GitHubIntegrations,
|
|
@@ -139,7 +147,7 @@ import {
|
|
|
139
147
|
WorkItemCommentDrafts,
|
|
140
148
|
WorkItemComments,
|
|
141
149
|
WorkItems
|
|
142
|
-
} from "./chunk-
|
|
150
|
+
} from "./chunk-wnfj3wyx.js";
|
|
143
151
|
import {
|
|
144
152
|
ARTIFACT_MARKER_SCHEME,
|
|
145
153
|
buildArtifactMarker,
|
|
@@ -159,7 +167,7 @@ import {
|
|
|
159
167
|
matchArtifactNode,
|
|
160
168
|
readArtifactKeyword
|
|
161
169
|
} from "./chunk-y2pv8d6a.js";
|
|
162
|
-
import"./chunk-
|
|
170
|
+
import"./chunk-01nfqm18.js";
|
|
163
171
|
import"./chunk-skzxcba3.js";
|
|
164
172
|
import"./chunk-y64skrwp.js";
|
|
165
173
|
export {
|
|
@@ -169,9 +177,9 @@ export {
|
|
|
169
177
|
Api,
|
|
170
178
|
Artifact,
|
|
171
179
|
ArtifactTypes,
|
|
180
|
+
Automations,
|
|
172
181
|
Billing,
|
|
173
182
|
Conversations,
|
|
174
|
-
DEFAULT_PIPELINE_ASSIGNMENT_FILENAME,
|
|
175
183
|
EMBEDDABLE_ARTIFACT_EXTENSIONS,
|
|
176
184
|
Env,
|
|
177
185
|
Features,
|
|
@@ -211,6 +219,7 @@ export {
|
|
|
211
219
|
artifactFileExtension,
|
|
212
220
|
artifactKindSchema,
|
|
213
221
|
artifactPlatforms,
|
|
222
|
+
attach,
|
|
214
223
|
avg,
|
|
215
224
|
before,
|
|
216
225
|
buildArtifactMarker,
|
|
@@ -219,6 +228,7 @@ export {
|
|
|
219
228
|
compileEnvironment,
|
|
220
229
|
compileMcps,
|
|
221
230
|
compileRepo,
|
|
231
|
+
compileStepConcurrency,
|
|
222
232
|
compileStepErrors,
|
|
223
233
|
compileStepMaxTurns,
|
|
224
234
|
compileStepRetry,
|
|
@@ -231,7 +241,7 @@ export {
|
|
|
231
241
|
createStepDefinitionsClient,
|
|
232
242
|
createTaskPlaneClient,
|
|
233
243
|
decision,
|
|
234
|
-
|
|
244
|
+
defineAutomation,
|
|
235
245
|
defineMcp,
|
|
236
246
|
definePipeline,
|
|
237
247
|
defineStep,
|
|
@@ -247,7 +257,6 @@ export {
|
|
|
247
257
|
formatIssue,
|
|
248
258
|
greaterThan,
|
|
249
259
|
greaterThanInclusive,
|
|
250
|
-
isDefaultPipelineAssignmentSpec,
|
|
251
260
|
isEmbeddableArtifactExtension,
|
|
252
261
|
isEmpty,
|
|
253
262
|
isEnvPlaceholderValue,
|
|
@@ -264,6 +273,7 @@ export {
|
|
|
264
273
|
normalizeEnv,
|
|
265
274
|
not,
|
|
266
275
|
notEqual,
|
|
276
|
+
onEvent,
|
|
267
277
|
openCodeMcpLocalConfigSchema,
|
|
268
278
|
openCodeMcpOAuthConfigSchema,
|
|
269
279
|
openCodeMcpProtocolSchema,
|
|
@@ -282,7 +292,7 @@ export {
|
|
|
282
292
|
reply,
|
|
283
293
|
resolveMcpChecks,
|
|
284
294
|
resolveWorkItemFieldPath,
|
|
285
|
-
|
|
295
|
+
skip,
|
|
286
296
|
some,
|
|
287
297
|
startsWith,
|
|
288
298
|
stepRef,
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* compiles the result to a pipeline JSON document. It doesn't validate the
|
|
4
|
-
* document (that's `validatePipeline` in `@scarn/shared-core/pipelines`);
|
|
5
|
-
* it reports what only the TS source can show, and throws
|
|
6
|
-
* `PipelineBuildError` when anything is wrong.
|
|
7
|
-
*/
|
|
1
|
+
import type { AutomationTarget, EventWorkItem } from "../automations/types";
|
|
2
|
+
import type { AutomationScope, AutomationSubject } from "../contracts/automation-document";
|
|
8
3
|
import type { PipelineDocument, StepCatalog } from "../contracts/pipeline-document";
|
|
9
4
|
import { type BuildIssue } from "./errors";
|
|
10
5
|
import { type SourceSite } from "./source";
|
|
@@ -27,6 +22,11 @@ export interface PipelineDefinition {
|
|
|
27
22
|
readonly steps: StepCatalog;
|
|
28
23
|
/** Problems that don't stop the build, such as chains left out of `flow`. */
|
|
29
24
|
readonly warnings: readonly BuildIssue[];
|
|
25
|
+
/**
|
|
26
|
+
* In an automation rule: a run of this pipeline for `workItem`
|
|
27
|
+
* (`r.workItem` or `r.child`). The bare pipeline runs for `r.workItem`.
|
|
28
|
+
*/
|
|
29
|
+
on(workItem: EventWorkItem<AutomationSubject>): AutomationTarget<AutomationScope>;
|
|
30
30
|
}
|
|
31
31
|
/** Compiles a pipeline to its JSON document. Throws `PipelineBuildError`. */
|
|
32
32
|
export declare function definePipeline(config: PipelineConfig): PipelineDefinition;
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Handles at run time: callable functions that record a target when called,
|
|
3
|
-
* with the chain-starting methods attached. Step handles from `defineStep` /
|
|
4
|
-
* `codeStep` and `stepRef` are built here, and so are wait handles.
|
|
5
|
-
*/
|
|
6
1
|
import type { JsonSchema } from "../contracts/pipeline-document";
|
|
7
2
|
import type { NodeDef, RawArgs } from "./model";
|
|
8
3
|
/** What `toPipelineStep` needs from a step definition. */
|
package/dist/pipelines/index.js
CHANGED
|
@@ -34,13 +34,16 @@ import {
|
|
|
34
34
|
sum,
|
|
35
35
|
workItem,
|
|
36
36
|
workItemField
|
|
37
|
-
} from "../chunk-
|
|
38
|
-
import"../chunk-
|
|
37
|
+
} from "../chunk-43y7tfn4.js";
|
|
38
|
+
import"../chunk-x0hjhqrf.js";
|
|
39
|
+
import"../chunk-61jf8b6s.js";
|
|
40
|
+
import"../chunk-cnxaagfj.js";
|
|
41
|
+
import"../chunk-jj9pezwb.js";
|
|
39
42
|
import {
|
|
40
43
|
PipelineBuildError,
|
|
41
44
|
formatIssue
|
|
42
|
-
} from "../chunk-
|
|
43
|
-
import"../chunk-
|
|
45
|
+
} from "../chunk-y11p1q7r.js";
|
|
46
|
+
import"../chunk-01nfqm18.js";
|
|
44
47
|
import"../chunk-skzxcba3.js";
|
|
45
48
|
import"../chunk-y64skrwp.js";
|
|
46
49
|
export {
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* `docs/plans/pipeline-ts-sdk.md`), so an unfinished or misordered chain is
|
|
5
5
|
* a type error rather than a build error.
|
|
6
6
|
*/
|
|
7
|
+
import type { AutomationTarget, EventWorkItem } from "../automations/types";
|
|
8
|
+
import type { AutomationScope, AutomationSubject } from "../contracts/automation-document";
|
|
7
9
|
import type { BUILT_IN_ERRORS, ToleratedFailures, WAIT_ERRORS } from "../contracts/pipeline-document";
|
|
8
10
|
import type { StepRef } from "../definitions/steps/step-ref";
|
|
9
11
|
import type { Condition } from "./condition-data";
|
|
@@ -39,6 +41,16 @@ type NoKeys = Record<never, never>;
|
|
|
39
41
|
export type CallArgs<I> = unknown extends I ? Readonly<Record<string, Ref<unknown> | JsonLiteral>> : Args<I>;
|
|
40
42
|
/** Calling a handle: args are optional only when the input has no required keys. */
|
|
41
43
|
export type Call<I> = NoKeys extends I ? (args?: CallArgs<I>) => Target : (args: CallArgs<I>) => Target;
|
|
44
|
+
/**
|
|
45
|
+
* A step called with its args. In a pipeline it's a target; in an
|
|
46
|
+
* automation rule, `.on(r.workItem | r.child)` picks the work item its Task
|
|
47
|
+
* is for.
|
|
48
|
+
*/
|
|
49
|
+
export interface StepTarget extends Target {
|
|
50
|
+
on(workItem: EventWorkItem<AutomationSubject>): AutomationTarget<AutomationScope>;
|
|
51
|
+
}
|
|
52
|
+
/** Calling a step handle: like `Call`, but the target also has `.on(...)`. */
|
|
53
|
+
export type StepCall<I> = NoKeys extends I ? (args?: CallArgs<I>) => StepTarget : (args: CallArgs<I>) => StepTarget;
|
|
42
54
|
/** A bare handle is a target only when its input has no required keys. */
|
|
43
55
|
export interface Bare<I> {
|
|
44
56
|
readonly [targetBrand]: NoKeys extends I ? true : false;
|
|
@@ -123,7 +135,7 @@ export interface StepChain<I, R, E extends string> extends StepAfterRetry<I, R,
|
|
|
123
135
|
settings(settings: StepSettings): StepAfterRetry<I, R, E>;
|
|
124
136
|
}
|
|
125
137
|
/** A step in a pipeline: callable as a target, and the start of its chain. */
|
|
126
|
-
export type PipelineStep<I, R, E extends string = string> =
|
|
138
|
+
export type PipelineStep<I, R, E extends string = string> = StepCall<I> & Bare<I> & StepRef<I, R, E> & StepChain<I, R, E> & Mergeable<I> & {
|
|
127
139
|
/** The same step as a second node, with id `id`. */
|
|
128
140
|
as(id: string): PipelineStep<I, R, E>;
|
|
129
141
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type DefaultPipelineAssignmentSpec } from "../definitions/pipelines/define-default-pipeline-assignment";
|
|
2
1
|
import type { StepDefinitionSpec } from "../definitions/steps";
|
|
3
2
|
/**
|
|
4
3
|
* The fixed, repo-root-relative directory `scarn pipelines init` scaffolds
|
|
@@ -15,8 +14,6 @@ export declare const PIPELINE_BUILDER_DIR = ".scarn/pipeline-builder";
|
|
|
15
14
|
export type CollectedDefinitions = {
|
|
16
15
|
/** Deduped by `key@vN`. */
|
|
17
16
|
readonly steps: readonly StepDefinitionSpec[];
|
|
18
|
-
/** Present only when `default-pipeline-assignment.ts` exists in the directory. */
|
|
19
|
-
readonly defaultPipelineAssignment: DefaultPipelineAssignmentSpec | null;
|
|
20
17
|
};
|
|
21
18
|
/**
|
|
22
19
|
* One source file that failed to import —
|
|
@@ -31,13 +28,11 @@ export type BrokenPipeline = {
|
|
|
31
28
|
export type TolerantCollectedDefinitions = CollectedDefinitions & {
|
|
32
29
|
readonly brokenPipelines: readonly BrokenPipeline[];
|
|
33
30
|
};
|
|
34
|
-
/** `.ts`/`.js` files in `dir` that declare definitions — excludes internal scripts
|
|
31
|
+
/** `.ts`/`.js` files in `dir` that declare definitions — excludes internal scripts. */
|
|
35
32
|
export declare function listSourceFiles(absDir: string): string[];
|
|
36
33
|
/**
|
|
37
|
-
* Imports every `.ts`/`.js` file in `dir` (except the push script itself and
|
|
38
|
-
*
|
|
39
|
-
* export. The assignment file, when present, is imported and
|
|
40
|
-
* validated too but returned separately — syncing it needs the server.
|
|
34
|
+
* Imports every `.ts`/`.js` file in `dir` (except the push script itself) and
|
|
35
|
+
* collects the step definitions they export.
|
|
41
36
|
*
|
|
42
37
|
* Designed to run on the user's native runtime (bun, node-with-tsx, deno), NOT
|
|
43
38
|
* inside a `bun --compile`'d binary — that runtime can't resolve scoped package
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export type BuiltDocumentKind = "pipeline" | "automation";
|
|
1
2
|
export type PipelineDocumentFile = {
|
|
2
3
|
/** The file name, relative to the builder directory. */
|
|
3
4
|
readonly file: string;
|
|
@@ -6,9 +7,18 @@ export type PipelineDocumentFile = {
|
|
|
6
7
|
/** The parsed document, sent to the server as-is. */
|
|
7
8
|
readonly document: Record<string, unknown>;
|
|
8
9
|
};
|
|
10
|
+
export type BuiltDocumentFile = PipelineDocumentFile & {
|
|
11
|
+
readonly kind: BuiltDocumentKind;
|
|
12
|
+
};
|
|
9
13
|
/**
|
|
10
|
-
* Every `.json` file in `dir` that holds a pipeline
|
|
11
|
-
*
|
|
12
|
-
*
|
|
14
|
+
* Every `.json` file in `dir` that holds a pipeline or automation document,
|
|
15
|
+
* sorted by file name. Other JSON is skipped. Throws on a file that isn't
|
|
16
|
+
* valid JSON, a document without a `key`, or two files with one `key`:
|
|
17
|
+
* pipelines and automations share one key space, like their `<key>.json`
|
|
18
|
+
* file names.
|
|
13
19
|
*/
|
|
20
|
+
export declare function collectBuiltDocuments(dir: string): BuiltDocumentFile[];
|
|
21
|
+
/** The pipeline documents in `dir` (see `collectBuiltDocuments`). */
|
|
14
22
|
export declare function collectPipelineDocuments(dir: string): PipelineDocumentFile[];
|
|
23
|
+
/** The automation documents in `dir` (see `collectBuiltDocuments`). */
|
|
24
|
+
export declare function collectAutomationDocuments(dir: string): PipelineDocumentFile[];
|
package/dist/push/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { PIPELINE_BUILDER_DIR, collectDefinitionsFromDirectory, collectDefinitionsFromDirectoryTolerant, } from "./collect-definitions";
|
|
2
2
|
export type { BrokenPipeline, CollectedDefinitions, TolerantCollectedDefinitions, } from "./collect-definitions";
|
|
3
|
-
export { collectPipelineDocuments } from "./collect-pipeline-documents";
|
|
4
|
-
export type { PipelineDocumentFile } from "./collect-pipeline-documents";
|
|
3
|
+
export { collectAutomationDocuments, collectBuiltDocuments, collectPipelineDocuments, } from "./collect-pipeline-documents";
|
|
4
|
+
export type { BuiltDocumentFile, BuiltDocumentKind, PipelineDocumentFile, } from "./collect-pipeline-documents";
|
|
5
5
|
export { pushFromDirectory } from "./push-from-directory";
|
|
6
6
|
export type { PushFromDirectoryOptions, PushFromDirectoryResult, } from "./push-from-directory";
|
package/dist/push/index.js
CHANGED
|
@@ -1,43 +1,42 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import {
|
|
3
|
-
assertValidDefinitionSpecs
|
|
4
|
-
} from "../chunk-gds7w7zh.js";
|
|
5
2
|
import {
|
|
6
3
|
isStepDefinitionSpec,
|
|
7
4
|
stepsInModule
|
|
8
5
|
} from "../chunk-ar6hcj1r.js";
|
|
9
6
|
import {
|
|
10
|
-
|
|
7
|
+
AutomationsApiError,
|
|
8
|
+
createAutomationsClient
|
|
9
|
+
} from "../chunk-0vzq22dj.js";
|
|
10
|
+
import {
|
|
11
|
+
assertValidDefinitionSpecs
|
|
12
|
+
} from "../chunk-fgfhvsee.js";
|
|
13
|
+
import {
|
|
11
14
|
PipelineDefinitionsApiError,
|
|
12
|
-
createPipelineDefinitionsClient
|
|
13
|
-
|
|
14
|
-
serializeDefaultPipelineAssignment
|
|
15
|
-
} from "../chunk-ra53p0v8.js";
|
|
15
|
+
createPipelineDefinitionsClient
|
|
16
|
+
} from "../chunk-8z1wa3kd.js";
|
|
16
17
|
import {
|
|
17
18
|
createStepDefinitionsClient,
|
|
18
19
|
toStepSpec
|
|
19
|
-
} from "../chunk-
|
|
20
|
+
} from "../chunk-fyfvp6jx.js";
|
|
21
|
+
import"../chunk-e1h021kq.js";
|
|
20
22
|
import"../chunk-63f90zky.js";
|
|
21
|
-
import"../chunk-
|
|
23
|
+
import"../chunk-jj9pezwb.js";
|
|
24
|
+
import"../chunk-y11p1q7r.js";
|
|
22
25
|
import"../chunk-5zsavw98.js";
|
|
23
26
|
import"../chunk-4ggr8af6.js";
|
|
24
27
|
import"../chunk-k4y5qt4y.js";
|
|
25
|
-
import"../chunk-
|
|
26
|
-
import"../chunk-
|
|
27
|
-
import {
|
|
28
|
-
Projects,
|
|
29
|
-
createClient
|
|
30
|
-
} from "../chunk-8pyhrdgy.js";
|
|
28
|
+
import"../chunk-ejzfdm1z.js";
|
|
29
|
+
import"../chunk-wnfj3wyx.js";
|
|
31
30
|
import"../chunk-ngy1fdcx.js";
|
|
32
31
|
import"../chunk-y2pv8d6a.js";
|
|
33
|
-
import"../chunk-
|
|
32
|
+
import"../chunk-01nfqm18.js";
|
|
34
33
|
import {
|
|
35
34
|
exports_external
|
|
36
35
|
} from "../chunk-skzxcba3.js";
|
|
37
36
|
import"../chunk-y64skrwp.js";
|
|
38
37
|
|
|
39
38
|
// src/push/collect-definitions.ts
|
|
40
|
-
import {
|
|
39
|
+
import { readdirSync } from "fs";
|
|
41
40
|
import { join, relative, resolve } from "path";
|
|
42
41
|
import { pathToFileURL } from "url";
|
|
43
42
|
var INTERNAL_SCRIPT_NAMES = new Set([
|
|
@@ -85,7 +84,7 @@ async function importModule(path) {
|
|
|
85
84
|
}
|
|
86
85
|
function listSourceFiles(absDir) {
|
|
87
86
|
const allFiles = readdirSync(absDir).filter((file) => file.endsWith(".ts") || file.endsWith(".js"));
|
|
88
|
-
return allFiles.filter((file) => !INTERNAL_SCRIPT_NAMES.has(file)
|
|
87
|
+
return allFiles.filter((file) => !INTERNAL_SCRIPT_NAMES.has(file));
|
|
89
88
|
}
|
|
90
89
|
function fileNameWithoutExtension(file) {
|
|
91
90
|
return file.replace(/\.(ts|js)$/, "");
|
|
@@ -109,10 +108,7 @@ async function collectDefinitionsFromDirectory(dir) {
|
|
|
109
108
|
for (const file of sourceFiles) {
|
|
110
109
|
await collectFile(join(absDir, file), absDir, state);
|
|
111
110
|
}
|
|
112
|
-
return {
|
|
113
|
-
steps: [...state.stepMap.values()],
|
|
114
|
-
defaultPipelineAssignment: await collectDefaultPipelineAssignment(absDir)
|
|
115
|
-
};
|
|
111
|
+
return { steps: [...state.stepMap.values()] };
|
|
116
112
|
}
|
|
117
113
|
async function collectDefinitionsFromDirectoryTolerant(dir) {
|
|
118
114
|
const absDir = resolve(dir);
|
|
@@ -129,32 +125,11 @@ async function collectDefinitionsFromDirectoryTolerant(dir) {
|
|
|
129
125
|
});
|
|
130
126
|
}
|
|
131
127
|
}
|
|
132
|
-
let defaultPipelineAssignment = null;
|
|
133
|
-
try {
|
|
134
|
-
defaultPipelineAssignment = await collectDefaultPipelineAssignment(absDir);
|
|
135
|
-
} catch (error) {
|
|
136
|
-
brokenPipelines.push({
|
|
137
|
-
key: fileNameWithoutExtension(DEFAULT_PIPELINE_ASSIGNMENT_FILENAME),
|
|
138
|
-
message: error instanceof Error ? error.message : String(error)
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
128
|
return {
|
|
142
129
|
steps: [...state.stepMap.values()],
|
|
143
|
-
defaultPipelineAssignment,
|
|
144
130
|
brokenPipelines
|
|
145
131
|
};
|
|
146
132
|
}
|
|
147
|
-
async function collectDefaultPipelineAssignment(absDir) {
|
|
148
|
-
const path = join(absDir, DEFAULT_PIPELINE_ASSIGNMENT_FILENAME);
|
|
149
|
-
if (!existsSync(path))
|
|
150
|
-
return null;
|
|
151
|
-
const mod = await importModule(path);
|
|
152
|
-
const spec = mod["default"];
|
|
153
|
-
if (!isDefaultPipelineAssignmentSpec(spec)) {
|
|
154
|
-
throw new Error(`${DEFAULT_PIPELINE_ASSIGNMENT_FILENAME} must have a default export produced by defaultPipelineAssignment(({ assign, skip, ... }) => ({ default: ..., rules: [...] })). Got: ${typeof spec}`);
|
|
155
|
-
}
|
|
156
|
-
return spec;
|
|
157
|
-
}
|
|
158
133
|
// src/push/collect-pipeline-documents.ts
|
|
159
134
|
import { readdirSync as readdirSync2, readFileSync } from "fs";
|
|
160
135
|
import { join as join2, resolve as resolve2 } from "path";
|
|
@@ -165,33 +140,58 @@ var NON_PIPELINE_JSON = new Set([
|
|
|
165
140
|
"jsconfig.json",
|
|
166
141
|
"deno.json"
|
|
167
142
|
]);
|
|
143
|
+
var automationDocumentSchema = exports_external.looseObject({
|
|
144
|
+
kind: exports_external.literal("automation")
|
|
145
|
+
});
|
|
168
146
|
var pipelineDocumentSchema = exports_external.looseObject({ nodes: exports_external.unknown() });
|
|
169
147
|
var documentHeaderSchema = exports_external.object({
|
|
170
148
|
key: exports_external.string().min(1),
|
|
171
149
|
title: exports_external.string().optional()
|
|
172
150
|
});
|
|
173
|
-
function
|
|
151
|
+
function documentKind(value) {
|
|
152
|
+
if (automationDocumentSchema.safeParse(value).success)
|
|
153
|
+
return "automation";
|
|
154
|
+
if (pipelineDocumentSchema.safeParse(value).success)
|
|
155
|
+
return "pipeline";
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
function collectBuiltDocuments(dir) {
|
|
174
159
|
const absDir = resolve2(dir);
|
|
175
160
|
const files = readdirSync2(absDir).filter((file) => file.endsWith(".json") && !NON_PIPELINE_JSON.has(file)).sort();
|
|
176
161
|
const byKey = new Map;
|
|
177
162
|
for (const file of files) {
|
|
178
|
-
const parsed =
|
|
179
|
-
|
|
163
|
+
const parsed = parseJsonFile(join2(absDir, file), file);
|
|
164
|
+
const kind = documentKind(parsed);
|
|
165
|
+
if (kind === undefined)
|
|
180
166
|
continue;
|
|
181
|
-
const document = parsed
|
|
167
|
+
const document = parsed;
|
|
182
168
|
const header = documentHeaderSchema.safeParse(document);
|
|
183
169
|
if (!header.success) {
|
|
184
|
-
throw new Error(`${file} has no "key": every
|
|
170
|
+
throw new Error(`${file} has no "key": every ${kind} document names the ${kind} it publishes to.`);
|
|
185
171
|
}
|
|
186
172
|
const { key, title } = header.data;
|
|
187
173
|
const existing = byKey.get(key);
|
|
188
174
|
if (existing) {
|
|
189
|
-
throw new Error(`${existing.file} and ${file} are both
|
|
175
|
+
throw new Error(`${existing.file} and ${file} are both "${key}". Delete the stale one and build again.`);
|
|
190
176
|
}
|
|
191
|
-
byKey.set(key, { file, key, title, document });
|
|
177
|
+
byKey.set(key, { file, kind, key, title, document });
|
|
192
178
|
}
|
|
193
179
|
return [...byKey.values()];
|
|
194
180
|
}
|
|
181
|
+
function withoutKind(file) {
|
|
182
|
+
return {
|
|
183
|
+
file: file.file,
|
|
184
|
+
key: file.key,
|
|
185
|
+
title: file.title,
|
|
186
|
+
document: file.document
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
function collectPipelineDocuments(dir) {
|
|
190
|
+
return collectBuiltDocuments(dir).filter((file) => file.kind === "pipeline").map(withoutKind);
|
|
191
|
+
}
|
|
192
|
+
function collectAutomationDocuments(dir) {
|
|
193
|
+
return collectBuiltDocuments(dir).filter((file) => file.kind === "automation").map(withoutKind);
|
|
194
|
+
}
|
|
195
195
|
function parseJsonFile(path, file) {
|
|
196
196
|
try {
|
|
197
197
|
return JSON.parse(readFileSync(path, "utf8"));
|
|
@@ -200,15 +200,17 @@ function parseJsonFile(path, file) {
|
|
|
200
200
|
}
|
|
201
201
|
}
|
|
202
202
|
// src/push/push-from-directory.ts
|
|
203
|
+
var latestVersionSchema = exports_external.object({ version: exports_external.number() });
|
|
203
204
|
async function pushFromDirectory(dir, opts) {
|
|
204
205
|
const log = opts.log ?? ((msg) => {
|
|
205
206
|
console.warn(msg);
|
|
206
207
|
});
|
|
207
208
|
const headers = { Authorization: `Bearer ${opts.accessToken}` };
|
|
208
|
-
const
|
|
209
|
-
const
|
|
210
|
-
const documents =
|
|
211
|
-
|
|
209
|
+
const { steps } = await collectDefinitionsFromDirectory(dir);
|
|
210
|
+
const built = collectBuiltDocuments(dir);
|
|
211
|
+
const documents = built.filter((file) => file.kind === "pipeline");
|
|
212
|
+
const automations = built.filter((file) => file.kind === "automation").sort((a, b) => Number(a.document["scope"] === "project") - Number(b.document["scope"] === "project"));
|
|
213
|
+
log(`Found ${String(steps.length)} step(s), ${String(documents.length)} pipeline document(s) and ${String(automations.length)} automation document(s).`);
|
|
212
214
|
assertValidDefinitionSpecs(steps);
|
|
213
215
|
const stepsClient = createStepDefinitionsClient(opts.baseUrl);
|
|
214
216
|
for (const spec of steps) {
|
|
@@ -226,12 +228,19 @@ async function pushFromDirectory(dir, opts) {
|
|
|
226
228
|
(published ? publishedPipelines : unchangedPipelines).push(document.key);
|
|
227
229
|
}
|
|
228
230
|
}
|
|
229
|
-
const
|
|
231
|
+
const automationsClient = createAutomationsClient(opts.baseUrl);
|
|
232
|
+
const publishedAutomations = [];
|
|
233
|
+
const unchangedAutomations = [];
|
|
234
|
+
for (const document of automations) {
|
|
235
|
+
const published = await publishAutomationDocument(document, opts.projectId, headers, automationsClient, log);
|
|
236
|
+
(published ? publishedAutomations : unchangedAutomations).push(document.key);
|
|
237
|
+
}
|
|
230
238
|
return {
|
|
231
239
|
pushedSteps: steps.length,
|
|
232
240
|
publishedPipelines,
|
|
233
241
|
unchangedPipelines,
|
|
234
|
-
|
|
242
|
+
publishedAutomations,
|
|
243
|
+
unchangedAutomations
|
|
235
244
|
};
|
|
236
245
|
}
|
|
237
246
|
async function publishPipelineDocument({ file, key, title, document }, pipelineDefinitionId, projectId, headers, pipelinesClient, log) {
|
|
@@ -246,80 +255,34 @@ async function publishPipelineDocument({ file, key, title, document }, pipelineD
|
|
|
246
255
|
log(result.published ? `\u2713 pipeline ${key} v${version} \u2192 published (${file})` : `\u2713 pipeline ${key} v${version} \u2192 unchanged (${file})`);
|
|
247
256
|
return result.published;
|
|
248
257
|
} catch (error) {
|
|
249
|
-
|
|
250
|
-
const issues = error.issues.map((issue) => issue.hint === undefined ? ` ${issue.path || "/"}: ${issue.message}` : ` ${issue.path || "/"}: ${issue.message}. ${issue.hint}`);
|
|
251
|
-
throw new Error([`Could not publish ${file}: ${error.message}`, ...issues].join(`
|
|
252
|
-
`), { cause: error });
|
|
253
|
-
}
|
|
254
|
-
throw error;
|
|
258
|
+
rethrowPublishError(file, error);
|
|
255
259
|
}
|
|
256
260
|
}
|
|
257
|
-
async function
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
for (const key of referencedKeys) {
|
|
271
|
-
if (!pipelineKeyToId.has(key)) {
|
|
272
|
-
throw new Error(`${DEFAULT_PIPELINE_ASSIGNMENT_FILENAME} references pipeline "${key}", ` + `but no pipeline with that key was found on the server. ` + `Run \`scarn pipelines build\` to write ${key}.json next to its source, then push again.`);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
const pipelineDefinitionId = pipelineKeyToId.get(serialized.pipelineDefinitionKey);
|
|
276
|
-
if (!pipelineDefinitionId) {
|
|
277
|
-
throw new Error(`Pipeline key "${serialized.pipelineDefinitionKey}" was not found on the server.`);
|
|
261
|
+
async function publishAutomationDocument({ file, key, document }, projectId, headers, automationsClient, log) {
|
|
262
|
+
try {
|
|
263
|
+
const result = await automationsClient.publish(projectId, key, document, {
|
|
264
|
+
headers
|
|
265
|
+
});
|
|
266
|
+
const latest = latestVersionSchema.safeParse(result.automation.latestVersion);
|
|
267
|
+
const version = latest.success ? ` v${String(latest.data.version)}` : "";
|
|
268
|
+
log(result.published ? `\u2713 automation ${key}${version} \u2192 published (${file})` : `\u2713 automation ${key}${version} \u2192 unchanged (${file})`);
|
|
269
|
+
return result.published;
|
|
270
|
+
} catch (error) {
|
|
271
|
+
rethrowPublishError(file, error);
|
|
278
272
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
if (!pId) {
|
|
284
|
-
throw new Error(`${DEFAULT_PIPELINE_ASSIGNMENT_FILENAME} assign() references pipeline "${pKey}" ` + `which was not found on the server.`);
|
|
285
|
-
}
|
|
286
|
-
return {
|
|
287
|
-
...rule,
|
|
288
|
-
event: {
|
|
289
|
-
...rule.event,
|
|
290
|
-
params: {
|
|
291
|
-
...rule.event.params,
|
|
292
|
-
pipelineDefinitionId: pId
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
return rule;
|
|
298
|
-
});
|
|
299
|
-
const projectsClient = new Projects({
|
|
300
|
-
client: createClient({ baseUrl: opts.baseUrl })
|
|
301
|
-
});
|
|
302
|
-
const result = await projectsClient.updateProjectDefaultPipelineAssignment({
|
|
303
|
-
path: { projectId: opts.projectId },
|
|
304
|
-
body: {
|
|
305
|
-
defaultPipelineAssignment: {
|
|
306
|
-
pipelineDefinitionId,
|
|
307
|
-
rulesJson: { rules: resolvedRules },
|
|
308
|
-
defaultEventType: serialized.defaultEventType,
|
|
309
|
-
defaultEventParamsJson: serialized.defaultEventParamsJson,
|
|
310
|
-
allowedEventTypes: serialized.allowedEventTypes
|
|
311
|
-
}
|
|
312
|
-
},
|
|
313
|
-
headers
|
|
314
|
-
});
|
|
315
|
-
if (result.error) {
|
|
316
|
-
throw new Error(`Failed to update project default pipeline assignment: ${JSON.stringify(result.error)}`);
|
|
273
|
+
}
|
|
274
|
+
function rethrowPublishError(file, error) {
|
|
275
|
+
if (!(error instanceof PipelineDefinitionsApiError) && !(error instanceof AutomationsApiError)) {
|
|
276
|
+
throw error;
|
|
317
277
|
}
|
|
318
|
-
|
|
319
|
-
|
|
278
|
+
const issues = error.issues.map((issue) => issue.hint === undefined ? ` ${issue.path || "/"}: ${issue.message}` : ` ${issue.path || "/"}: ${issue.message}. ${issue.hint}`);
|
|
279
|
+
throw new Error([`Could not publish ${file}: ${error.message}`, ...issues].join(`
|
|
280
|
+
`), { cause: error });
|
|
320
281
|
}
|
|
321
282
|
export {
|
|
322
283
|
PIPELINE_BUILDER_DIR,
|
|
284
|
+
collectAutomationDocuments,
|
|
285
|
+
collectBuiltDocuments,
|
|
323
286
|
collectDefinitionsFromDirectory,
|
|
324
287
|
collectDefinitionsFromDirectoryTolerant,
|
|
325
288
|
collectPipelineDocuments,
|