sykli 0.5.3

CI pipelines defined in Rust instead of YAML
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
# Sykli Rust SDK - API Reference

Complete API documentation for the Sykli Rust SDK.

## Table of Contents

- [Pipeline]#pipeline
- [Task]#task
- [Template]#template
- [Resources]#resources
- [Composition]#composition
- [Conditions]#conditions
- [Secrets]#secrets
- [Kubernetes]#kubernetes
- [Language Presets]#language-presets

---

## Pipeline

### new

```rust
fn Pipeline::new() -> Pipeline
```

Creates a new pipeline.

**Example:**
```rust
let mut p = Pipeline::new();
```

### task

```rust
fn task(&mut self, name: &str) -> Task<'_>
```

Creates a new task. Panics if name is empty.

### template

```rust
fn template(&mut self, name: &str) -> Template
```

Creates a reusable task template.

### dir

```rust
fn dir(&self, path: &str) -> Directory
```

Creates a directory resource for mounting into containers.

### cache

```rust
fn cache(&self, name: &str) -> CacheVolume
```

Creates a named cache volume for persisting data between runs.

### emit

```rust
fn emit(&self)
```

Outputs the pipeline as JSON if `--emit` flag is present. Call this at the end of your pipeline.

### emit_to

```rust
fn emit_to<W: Write>(&self, writer: W) -> io::Result<()>
```

Writes the pipeline JSON to the given writer.

---

## Task

### run

```rust
fn run(self, cmd: &str) -> Self
```

Sets the command for this task. **Required.**

### container

```rust
fn container(self, image: &str) -> Self
```

Sets the container image for this task.

### mount

```rust
fn mount(self, dir: &Directory, path: &str) -> Self
```

Mounts a directory into the container. Path must be absolute.

### mount_cache

```rust
fn mount_cache(self, cache: &CacheVolume, path: &str) -> Self
```

Mounts a cache volume into the container.

### mount_cwd

```rust
fn mount_cwd(self) -> Self
```

Convenience method: mounts current directory to `/work` and sets workdir.

### mount_cwd_at

```rust
fn mount_cwd_at(self, path: &str) -> Self
```

Mounts current directory to a custom path and sets workdir.

### workdir

```rust
fn workdir(self, path: &str) -> Self
```

Sets the working directory inside the container.

### env

```rust
fn env(self, key: &str, value: &str) -> Self
```

Sets an environment variable.

### inputs

```rust
fn inputs(self, patterns: &[&str]) -> Self
```

Sets input file patterns for caching. Supports glob patterns (`**/*.rs`).

### output

```rust
fn output(self, name: &str, path: &str) -> Self
```

Declares a named output artifact.

### outputs

```rust
fn outputs(self, paths: &[&str]) -> Self
```

Declares multiple output artifacts with auto-generated names.

### input_from

```rust
fn input_from(self, from_task: &str, output_name: &str, dest_path: &str) -> Self
```

Consumes an artifact from another task's output. Automatically adds dependency.

### after

```rust
fn after(self, tasks: &[&str]) -> Self
```

Sets dependencies - this task runs after the named tasks.

### after_one

```rust
fn after_one(self, task: &str) -> Self
```

Convenience for single dependency.

### after_group

```rust
fn after_group(self, group: &TaskGroup) -> Self
```

Depends on all tasks in the given group.

### from

```rust
fn from(self, tmpl: &Template) -> Self
```

Applies a template's configuration. Task settings override template settings.

### when

```rust
fn when(self, condition: &str) -> Self
```

Sets a string condition for when this task should run.

### when_cond

```rust
fn when_cond(self, condition: Condition) -> Self
```

Sets a type-safe condition (compile-time checked).

### secret

```rust
fn secret(self, name: &str) -> Self
```

Declares that this task requires a secret.

### secrets

```rust
fn secrets(self, names: &[&str]) -> Self
```

Declares multiple required secrets.

### secret_from

```rust
fn secret_from(self, name: &str, ref_: SecretRef) -> Self
```

Declares a typed secret reference with explicit source.

### service

```rust
fn service(self, image: &str, name: &str) -> Self
```

Adds a service container (database, cache) that runs alongside this task.

### matrix

```rust
fn matrix(self, key: &str, values: &[&str]) -> Self
```

Adds a matrix dimension. Creates task variants for each value.

### retry

```rust
fn retry(self, n: u32) -> Self
```

Sets the number of retry attempts on failure.

### timeout

```rust
fn timeout(self, seconds: u32) -> Self
```

Sets the task timeout in seconds.

### target

```rust
fn target(self, name: &str) -> Self
```

Sets the target for this specific task, overriding pipeline default.

### k8s

```rust
fn k8s(self, opts: K8sOptions) -> Self
```

Adds Kubernetes-specific options.

### k8s_raw

```rust
fn k8s_raw(self, json: &str) -> Self
```

Adds raw Kubernetes JSON for advanced options not covered by the minimal API.

### name

```rust
fn name(&self) -> String
```

Returns the task's name (for use in dependencies).

---

## Template

Templates provide reusable task configuration.

### container

```rust
fn container(mut self, image: &str) -> Self
```

### workdir

```rust
fn workdir(mut self, path: &str) -> Self
```

### env

```rust
fn env(mut self, key: &str, value: &str) -> Self
```

### mount_dir

```rust
fn mount_dir(mut self, dir: &Directory, path: &str) -> Self
```

### mount_cache

```rust
fn mount_cache(mut self, cache: &CacheVolume, path: &str) -> Self
```

---

## Resources

### Directory

```rust
pub struct Directory { /* ... */ }
```

Represents a host directory.

**Methods:**
- `glob(patterns: &[&str])` - Filter by glob patterns
- `id() -> String` - Returns unique identifier

### CacheVolume

```rust
pub struct CacheVolume { /* ... */ }
```

Represents a named persistent cache.

**Methods:**
- `id() -> String` - Returns cache name

---

## Composition

### parallel

```rust
fn parallel(&mut self, name: &str, tasks: Vec<Task<'_>>) -> TaskGroup
```

Creates a group of tasks that run concurrently.

### chain

```rust
fn chain(&mut self, items: Vec<ChainItem<'_>>)
```

Creates a sequential dependency chain.

### matrix

```rust
fn matrix<F>(&mut self, name: &str, values: &[&str], generator: F) -> TaskGroup
where F: FnMut(&str) -> Task<'_>
```

Creates tasks for each value using a generator function.

### TaskGroup

```rust
pub struct TaskGroup { /* ... */ }
```

A group of tasks created by `parallel()` or `matrix()`.

**Methods:**
- `after(deps: &[&str])` - Make all tasks depend on given deps
- `task_names() -> Vec<String>` - Get names of all tasks in group

---

## Conditions

### String Conditions

```rust
task.when("branch == 'main'")
task.when("tag != ''")
task.when("event == 'push'")
task.when("ci == true")
```

### Type-Safe Conditions

```rust
// Builders
Condition::branch(pattern: &str) -> Condition
Condition::tag(pattern: &str) -> Condition
Condition::has_tag() -> Condition
Condition::event(event_type: &str) -> Condition
Condition::in_ci() -> Condition
Condition::negate(c: Condition) -> Condition

// Combinators
condition.or(other: Condition) -> Condition
condition.and(other: Condition) -> Condition
```

**Examples:**
```rust
.when_cond(Condition::branch("main"))
.when_cond(Condition::tag("v*"))
.when_cond(Condition::branch("main").or(Condition::tag("v*")))
.when_cond(Condition::negate(Condition::branch("wip/*")).and(Condition::event("push")))
```

---

## Secrets

### from_env

```rust
SecretRef::from_env(env_var: &str) -> SecretRef
```

Reads secret from environment variable.

### from_file

```rust
SecretRef::from_file(path: &str) -> SecretRef
```

Reads secret from file.

### from_vault

```rust
SecretRef::from_vault(path: &str) -> SecretRef
```

Reads secret from HashiCorp Vault. Path format: `"path/to/secret#field"`.

---

## Kubernetes

### K8sOptions

```rust
pub struct K8sOptions {
    pub memory: Option<String>,  // e.g., "4Gi", "512Mi"
    pub cpu: Option<String>,     // e.g., "2", "500m"
    pub gpu: Option<u32>,        // NVIDIA GPU count
}
```

**Builder pattern:**
```rust
K8sOptions::default()
    .memory("4Gi")
    .cpu("2")
    .gpu(1)
```

### k8s_raw

For advanced options not covered by the minimal API (tolerations, affinity, security contexts), use raw JSON:

```rust
task.k8s_raw(r#"{"nodeSelector": {"gpu": "true"}, "tolerations": [{"key": "gpu", "effect": "NoSchedule"}]}"#)
```

---

## Language Presets

### Rust Preset

```rust
p.rust().test()                    // cargo test
p.rust().lint()                    // cargo clippy (or cargo check)
p.rust().build(output: &str)       // cargo build --release
RustPreset::inputs()               // ["**/*.rs", "Cargo.toml", "Cargo.lock"]
```

**Example:**
```rust
let mut p = Pipeline::new();
let src = p.dir(".");

p.rust().test()
    .container("rust:1.75")
    .mount(&src, "/src")
    .workdir("/src");

p.rust().build("target/release/app")
    .container("rust:1.75")
    .mount(&src, "/src")
    .workdir("/src")
    .after(&["test"]);

p.emit();
```