gagen 0.3.1 → 0.3.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/README.md +40 -84
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ initial code is more easily maintainable.
|
|
|
16
16
|
## Basic usage
|
|
17
17
|
|
|
18
18
|
```ts
|
|
19
|
-
#!/usr/bin/env -S deno run --allow-read=ci.yml --allow-write=ci.yml
|
|
19
|
+
#!/usr/bin/env -S deno run --allow-read=ci.generated.yml --allow-write=ci.generated.yml
|
|
20
20
|
import { conditions, createWorkflow, step } from "gagen";
|
|
21
21
|
|
|
22
22
|
const checkout = step({
|
|
@@ -56,17 +56,17 @@ createWorkflow({
|
|
|
56
56
|
steps: [lint, test],
|
|
57
57
|
}],
|
|
58
58
|
}).writeOrLint({
|
|
59
|
-
filePath: new URL("./ci.yml", import.meta.url),
|
|
60
|
-
header: "# GENERATED BY ./ci.
|
|
59
|
+
filePath: new URL("./ci.generated.yml", import.meta.url),
|
|
60
|
+
header: "# GENERATED BY ./ci.ts -- DO NOT DIRECTLY EDIT",
|
|
61
61
|
});
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
-
This generates a `ci.yml` with steps in the correct order and figures
|
|
65
|
-
it should only install deno when the lint step should be run and it
|
|
66
|
-
step only until it's necessary.
|
|
64
|
+
This generates a `ci.generated.yml` with steps in the correct order and figures
|
|
65
|
+
out that it should only install deno when the lint step should be run and it
|
|
66
|
+
defers that step only until it's necessary.
|
|
67
67
|
|
|
68
68
|
```yaml
|
|
69
|
-
# GENERATED BY ./ci.
|
|
69
|
+
# GENERATED BY ./ci.ts -- DO NOT DIRECTLY EDIT
|
|
70
70
|
|
|
71
71
|
name: ci
|
|
72
72
|
on:
|
|
@@ -92,15 +92,15 @@ jobs:
|
|
|
92
92
|
# gagen:pin denoland/setup-deno@v2 = 667a34cdef165d8d2b2e98dde39547c9daac7282
|
|
93
93
|
```
|
|
94
94
|
|
|
95
|
-
When run normally, this writes `ci.yml`. When run with `--lint`, it
|
|
96
|
-
existing file and compares the parsed YAML — exiting with a non-zero
|
|
97
|
-
they differ. This lets you add a CI step to verify the generated file is
|
|
98
|
-
date:
|
|
95
|
+
When run normally, this writes `ci.generated.yml`. When run with `--lint`, it
|
|
96
|
+
reads the existing file and compares the parsed YAML — exiting with a non-zero
|
|
97
|
+
code if they differ. This lets you add a CI step to verify the generated file is
|
|
98
|
+
up to date:
|
|
99
99
|
|
|
100
100
|
```ts
|
|
101
101
|
const lintStep = step({
|
|
102
102
|
name: "Lint CI generation",
|
|
103
|
-
run: "./.github/workflows/ci.
|
|
103
|
+
run: "./.github/workflows/ci.ts --lint",
|
|
104
104
|
});
|
|
105
105
|
```
|
|
106
106
|
|
|
@@ -133,7 +133,7 @@ dependencies.
|
|
|
133
133
|
To force re-resolving all pins, run with the `--update-pins` flag:
|
|
134
134
|
|
|
135
135
|
```sh
|
|
136
|
-
./ci.
|
|
136
|
+
./ci.ts --update-pins
|
|
137
137
|
```
|
|
138
138
|
|
|
139
139
|
Pinning can be disabled by setting `pinDeps` to `false`:
|
|
@@ -238,7 +238,7 @@ const runner = os.equals("linux").then("ubuntu-latest")
|
|
|
238
238
|
|
|
239
239
|
// use in job config
|
|
240
240
|
createWorkflow({
|
|
241
|
-
...,
|
|
241
|
+
// ...,
|
|
242
242
|
jobs: [
|
|
243
243
|
{ id: "build", runsOn: runner, steps: [test] },
|
|
244
244
|
],
|
|
@@ -411,17 +411,16 @@ Error: Cycle detected in step ordering: A → B → A
|
|
|
411
411
|
`defineMatrix()` gives you typed access to matrix values:
|
|
412
412
|
|
|
413
413
|
```ts
|
|
414
|
-
import { defineMatrix } from "gagen";
|
|
414
|
+
import { createWorkflow, defineMatrix } from "gagen";
|
|
415
415
|
|
|
416
416
|
const matrix = defineMatrix({
|
|
417
417
|
include: [
|
|
418
|
-
{
|
|
419
|
-
{
|
|
418
|
+
{ runner: "ubuntu-latest" },
|
|
419
|
+
{ runner: "macos-latest" },
|
|
420
420
|
],
|
|
421
421
|
});
|
|
422
422
|
|
|
423
|
-
matrix.
|
|
424
|
-
matrix.runner; // ExpressionValue("matrix.runner")
|
|
423
|
+
matrix.runner; // ExpressionValue("matrix.runner") — autocompletes
|
|
425
424
|
matrix.foo; // TypeScript error — not a matrix key
|
|
426
425
|
|
|
427
426
|
createWorkflow({
|
|
@@ -499,57 +498,6 @@ createWorkflow({
|
|
|
499
498
|
Permission scopes (`contents`, `packages`, `id-token`, etc.) and levels (`read`,
|
|
500
499
|
`write`, `none`) are fully typed.
|
|
501
500
|
|
|
502
|
-
## Reusable workflows
|
|
503
|
-
|
|
504
|
-
Define reusable workflows with `workflow_call` triggers and call them from other
|
|
505
|
-
jobs:
|
|
506
|
-
|
|
507
|
-
```ts
|
|
508
|
-
import { createWorkflow } from "gagen";
|
|
509
|
-
|
|
510
|
-
// define a reusable workflow
|
|
511
|
-
const wf = createWorkflow({
|
|
512
|
-
name: "Reusable Build",
|
|
513
|
-
on: {
|
|
514
|
-
workflow_call: {
|
|
515
|
-
inputs: {
|
|
516
|
-
environment: { type: "string", required: true },
|
|
517
|
-
debug: { type: "boolean", default: false },
|
|
518
|
-
},
|
|
519
|
-
outputs: {
|
|
520
|
-
build_id: {
|
|
521
|
-
description: "The build ID",
|
|
522
|
-
value: "${{ jobs.build.outputs.id }}",
|
|
523
|
-
},
|
|
524
|
-
},
|
|
525
|
-
secrets: {
|
|
526
|
-
deploy_key: { required: true },
|
|
527
|
-
},
|
|
528
|
-
},
|
|
529
|
-
},
|
|
530
|
-
});
|
|
531
|
-
```
|
|
532
|
-
|
|
533
|
-
Call a reusable workflow from a job using `uses` instead of `runsOn`:
|
|
534
|
-
|
|
535
|
-
```ts
|
|
536
|
-
const wf = createWorkflow({
|
|
537
|
-
name: "CI",
|
|
538
|
-
on: ["push", "pull_request"],
|
|
539
|
-
jobs: [
|
|
540
|
-
{
|
|
541
|
-
id: "build",
|
|
542
|
-
uses: "octo-org/example/.github/workflows/build.yml@main",
|
|
543
|
-
with: { environment: "production" },
|
|
544
|
-
secrets: "inherit",
|
|
545
|
-
},
|
|
546
|
-
],
|
|
547
|
-
});
|
|
548
|
-
```
|
|
549
|
-
|
|
550
|
-
Reusable jobs support `with`, `secrets` (either `"inherit"` or a record), and
|
|
551
|
-
all common job fields (`name`, `needs`, `if`, `permissions`, `concurrency`).
|
|
552
|
-
|
|
553
501
|
## Artifacts
|
|
554
502
|
|
|
555
503
|
Link upload and download artifact steps across jobs with automatic `needs`
|
|
@@ -564,22 +512,30 @@ import {
|
|
|
564
512
|
|
|
565
513
|
const artifact = defineArtifact("build-output");
|
|
566
514
|
|
|
567
|
-
const buildStep = step({ name: "Build", run: "make build" });
|
|
568
|
-
const upload = artifact.upload({ path: "dist/" });
|
|
569
|
-
|
|
570
|
-
const download = artifact.download({ dirPath: "output/" });
|
|
571
|
-
const deployStep = step.dependsOn(download)({
|
|
572
|
-
name: "Deploy",
|
|
573
|
-
run: "make deploy",
|
|
574
|
-
});
|
|
575
|
-
|
|
576
515
|
const wf = createWorkflow({
|
|
577
516
|
name: "CI",
|
|
578
517
|
on: ["push", "pull_request"],
|
|
579
518
|
jobs: [
|
|
580
|
-
{
|
|
581
|
-
|
|
582
|
-
|
|
519
|
+
{
|
|
520
|
+
id: "build",
|
|
521
|
+
runsOn: "ubuntu-latest",
|
|
522
|
+
steps: [
|
|
523
|
+
step({ name: "Build", run: "make build" }),
|
|
524
|
+
artifact.upload({ path: "dist/" }),
|
|
525
|
+
],
|
|
526
|
+
},
|
|
527
|
+
// `needs: [build]` is inferred automatically from the artifact link
|
|
528
|
+
{
|
|
529
|
+
id: "deploy",
|
|
530
|
+
runsOn: "ubuntu-latest",
|
|
531
|
+
steps: [
|
|
532
|
+
artifact.download({ dirPath: "output/" }),
|
|
533
|
+
step({
|
|
534
|
+
name: "Deploy",
|
|
535
|
+
run: "make deploy",
|
|
536
|
+
}),
|
|
537
|
+
],
|
|
538
|
+
},
|
|
583
539
|
],
|
|
584
540
|
});
|
|
585
541
|
```
|
|
@@ -601,8 +557,8 @@ const artifact = defineArtifact("build-output", {
|
|
|
601
557
|
```ts
|
|
602
558
|
const matrix = defineMatrix({
|
|
603
559
|
include: [
|
|
604
|
-
{
|
|
605
|
-
{
|
|
560
|
+
{ runner: "ubuntu-latest" },
|
|
561
|
+
{ runner: "macos-latest" },
|
|
606
562
|
],
|
|
607
563
|
});
|
|
608
564
|
|