@cifn/runner 0.0.1

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,223 @@
1
+ import { MemoryStore, QueueClient, PipelineSpec } from 'cifn';
2
+
3
+ interface LogEntry {
4
+ runId: string;
5
+ jobKey: string;
6
+ stepKey: string;
7
+ line: string;
8
+ timestamp: string;
9
+ }
10
+ interface LogFnClient {
11
+ append(entry: LogEntry): void;
12
+ appendLines(runId: string, jobKey: string, stepKey: string, lines: string[]): void;
13
+ getLines(runId: string, jobKey: string): LogEntry[];
14
+ getAllLines(runId: string): LogEntry[];
15
+ }
16
+ declare class MemoryLogFnClient implements LogFnClient {
17
+ private entries;
18
+ append(entry: LogEntry): void;
19
+ appendLines(runId: string, jobKey: string, stepKey: string, lines: string[]): void;
20
+ getLines(runId: string, jobKey: string): LogEntry[];
21
+ getAllLines(runId: string): LogEntry[];
22
+ }
23
+
24
+ interface RunStepResult {
25
+ exitCode: number;
26
+ stdout: string;
27
+ stderr: string;
28
+ lines: string[];
29
+ }
30
+ declare function executeRunStep(command: string, workspacePath: string, env?: Record<string, string>): RunStepResult;
31
+
32
+ interface DockerExecutorOptions {
33
+ image: string;
34
+ workspace: string;
35
+ command: string;
36
+ env?: Record<string, string>;
37
+ }
38
+ interface DockerCommandRunner {
39
+ run(args: string[], options: {
40
+ cwd: string;
41
+ env?: Record<string, string>;
42
+ }): {
43
+ status: number | null;
44
+ stdout: string;
45
+ stderr: string;
46
+ error?: string;
47
+ };
48
+ }
49
+ declare class DockerExecutor {
50
+ private readonly runner;
51
+ constructor(runner?: DockerCommandRunner);
52
+ execute(options: DockerExecutorOptions): RunStepResult;
53
+ }
54
+
55
+ interface RunnerOptions {
56
+ store: MemoryStore;
57
+ queue: QueueClient;
58
+ logClient: LogFnClient;
59
+ pipelineSpecs?: Map<string, PipelineSpec>;
60
+ queueName?: string;
61
+ cleanWorkspace?: boolean;
62
+ fileFnClient?: {
63
+ upload(namespace: string, key: string, data: Buffer): Promise<string>;
64
+ downloadByKey(namespace: string, key: string): Promise<Buffer | null>;
65
+ };
66
+ artifactStore?: {
67
+ addArtifact(runId: string, artifact: {
68
+ name: string;
69
+ fileId: string;
70
+ url?: string;
71
+ }): void;
72
+ };
73
+ secretValues?: Map<string, string[]>;
74
+ /** Resolve secret by name for interpolation. When not set, ${{ secrets.* }} in run/with/cache key will fail. */
75
+ getSecret?: (runId: string, name: string) => Promise<string | null>;
76
+ labels?: string[];
77
+ runnerType?: 'default' | 'hostfn-runner';
78
+ dockerExecutor?: DockerExecutor;
79
+ defaultDockerImage?: string;
80
+ dockerRunOnLabels?: string[];
81
+ dockerForDefault?: boolean;
82
+ }
83
+ declare class Runner {
84
+ private store;
85
+ private queue;
86
+ private logClient;
87
+ private pipelineSpecs;
88
+ private queueName;
89
+ private cleanWorkspace;
90
+ private fileFnClient?;
91
+ private artifactStore?;
92
+ private secretValues;
93
+ private labels;
94
+ private runnerType;
95
+ private dockerExecutor?;
96
+ private defaultDockerImage;
97
+ private dockerRunOnLabels;
98
+ private dockerForDefault;
99
+ private getSecret?;
100
+ constructor(options: RunnerOptions);
101
+ registerPipelineSpec(runId: string, spec: PipelineSpec): void;
102
+ registerSecretValues(runId: string, values: string[]): void;
103
+ processNextJob(): Promise<boolean>;
104
+ processAllJobs(): Promise<number>;
105
+ private executeJob;
106
+ private executeRunCommand;
107
+ private shouldUseDocker;
108
+ private enqueueDependentJobs;
109
+ private checkRunCompletion;
110
+ }
111
+
112
+ interface CheckoutOptions {
113
+ repo: string;
114
+ ref: string;
115
+ workspace: string;
116
+ token?: string;
117
+ }
118
+ interface CheckoutResult {
119
+ success: boolean;
120
+ lines: string[];
121
+ error?: string;
122
+ }
123
+ declare function executeCheckout(options: CheckoutOptions): CheckoutResult;
124
+
125
+ interface ArtifactUploadOptions {
126
+ name: string;
127
+ path: string;
128
+ workspace: string;
129
+ runId: string;
130
+ fileFnClient: {
131
+ upload(namespace: string, key: string, data: Buffer): Promise<string>;
132
+ };
133
+ }
134
+ interface ArtifactUploadResult {
135
+ success: boolean;
136
+ fileId?: string;
137
+ lines: string[];
138
+ error?: string;
139
+ }
140
+ declare function executeArtifactUpload(options: ArtifactUploadOptions): Promise<ArtifactUploadResult>;
141
+
142
+ interface ArtifactDownloadOptions {
143
+ name: string;
144
+ workspace: string;
145
+ runId: string;
146
+ fileFnClient: {
147
+ downloadByKey(namespace: string, key: string): Promise<Buffer | null>;
148
+ };
149
+ }
150
+ interface ArtifactDownloadResult {
151
+ success: boolean;
152
+ lines: string[];
153
+ error?: string;
154
+ }
155
+ declare function executeArtifactDownload(options: ArtifactDownloadOptions): Promise<ArtifactDownloadResult>;
156
+
157
+ interface CacheSaveOptions {
158
+ key: string;
159
+ paths: string[];
160
+ workspace: string;
161
+ fileFnClient: {
162
+ upload(namespace: string, key: string, data: Buffer): Promise<string>;
163
+ };
164
+ }
165
+ interface CacheSaveResult {
166
+ success: boolean;
167
+ lines: string[];
168
+ error?: string;
169
+ }
170
+ declare function executeCacheSave(options: CacheSaveOptions): Promise<CacheSaveResult>;
171
+
172
+ interface CacheRestoreOptions {
173
+ key: string;
174
+ workspace: string;
175
+ fileFnClient: {
176
+ downloadByKey(namespace: string, key: string): Promise<Buffer | null>;
177
+ };
178
+ }
179
+ interface CacheRestoreResult {
180
+ success: boolean;
181
+ hit: boolean;
182
+ lines: string[];
183
+ error?: string;
184
+ }
185
+ declare function executeCacheRestore(options: CacheRestoreOptions): Promise<CacheRestoreResult>;
186
+
187
+ declare function redactSecrets(lines: string[], secretValues: string[]): string[];
188
+
189
+ interface TestFnRunOptions {
190
+ framework?: string;
191
+ testPattern?: string;
192
+ reporter?: string;
193
+ outputPath?: string;
194
+ workspace: string;
195
+ env?: Record<string, string>;
196
+ parallel?: number | 'auto';
197
+ timeout?: number;
198
+ retries?: number;
199
+ }
200
+ interface TestFnRunResult {
201
+ success: boolean;
202
+ exitCode: number;
203
+ lines: string[];
204
+ error?: string;
205
+ }
206
+ declare function executeTestFnRun(options: TestFnRunOptions): TestFnRunResult;
207
+
208
+ interface HostFnDeployOptions {
209
+ environment: string;
210
+ ci?: boolean;
211
+ local?: boolean;
212
+ workspace: string;
213
+ env?: Record<string, string>;
214
+ }
215
+ interface HostFnDeployResult {
216
+ success: boolean;
217
+ exitCode: number;
218
+ lines: string[];
219
+ error?: string;
220
+ }
221
+ declare function executeHostFnDeploy(options: HostFnDeployOptions): HostFnDeployResult;
222
+
223
+ export { type ArtifactDownloadOptions, type ArtifactDownloadResult, type ArtifactUploadOptions, type ArtifactUploadResult, type CacheRestoreOptions, type CacheRestoreResult, type CacheSaveOptions, type CacheSaveResult, type CheckoutOptions, type CheckoutResult, type DockerCommandRunner, DockerExecutor, type DockerExecutorOptions, type HostFnDeployOptions, type HostFnDeployResult, type LogEntry, type LogFnClient, MemoryLogFnClient, type RunStepResult, Runner, type RunnerOptions, type TestFnRunOptions, type TestFnRunResult, executeArtifactDownload, executeArtifactUpload, executeCacheRestore, executeCacheSave, executeCheckout, executeHostFnDeploy, executeRunStep, executeTestFnRun, redactSecrets };