@factorialco/gat 3.0.4 → 3.1.0
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/job.d.ts +6 -1
- package/dist/workflow.d.ts +2 -2
- package/dist/workflow.js +65 -52
- package/dist/workflow.spec.js +21 -0
- package/package.json +1 -1
package/dist/job.d.ts
CHANGED
|
@@ -35,8 +35,13 @@ export interface JobOptions<Step, RunnerDefinition, Name> {
|
|
|
35
35
|
outputs?: Record<string, string>;
|
|
36
36
|
workingDirectory?: string;
|
|
37
37
|
}
|
|
38
|
+
export interface UsesJobOptions {
|
|
39
|
+
uses: string;
|
|
40
|
+
with?: Record<string, string | number | boolean | object>;
|
|
41
|
+
secrets?: Record<string, string | number | boolean | object> | "inherit";
|
|
42
|
+
}
|
|
38
43
|
export type StringWithNoSpaces<T> = T extends `${string} ${string}` ? never : T extends ` ${string}` ? never : T extends `${string} ` ? never : T;
|
|
39
44
|
export interface Job<Step, RunnerDefinition, Name> {
|
|
40
45
|
name: string;
|
|
41
|
-
options: JobOptions<Step, RunnerDefinition, Name
|
|
46
|
+
options: JobOptions<Step, RunnerDefinition, Name> | UsesJobOptions;
|
|
42
47
|
}
|
package/dist/workflow.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConcurrencyGroup, Job, JobOptions, StringWithNoSpaces } from "./job";
|
|
1
|
+
import { ConcurrencyGroup, Job, JobOptions, StringWithNoSpaces, UsesJobOptions } from "./job";
|
|
2
2
|
import type { Event, EventName, EventOptions } from "./event";
|
|
3
3
|
import { type Step } from "./step";
|
|
4
4
|
interface DefaultOptions {
|
|
@@ -22,7 +22,7 @@ export declare class Workflow<JobStep extends Step = Step, Runner extends Runner
|
|
|
22
22
|
constructor(name: string);
|
|
23
23
|
on<T extends EventName>(name: T, options?: EventOptions<T>): this;
|
|
24
24
|
addDefaults(options: DefaultOptions): this;
|
|
25
|
-
addJob<T extends string>(name: StringWithNoSpaces<T>, options: JobOptions<JobStep, Runner, JobName>): Workflow<JobStep, Runner, JobName | T>;
|
|
25
|
+
addJob<T extends string>(name: StringWithNoSpaces<T>, options: JobOptions<JobStep, Runner, JobName> | UsesJobOptions): Workflow<JobStep, Runner, JobName | T>;
|
|
26
26
|
setEnv(name: string, value: string): this;
|
|
27
27
|
setConcurrencyGroup(concurrencyGroup: ConcurrencyGroup | null): this;
|
|
28
28
|
defaultRunner(): string;
|
package/dist/workflow.js
CHANGED
|
@@ -90,60 +90,73 @@ class Workflow {
|
|
|
90
90
|
env: this.env.length > 0
|
|
91
91
|
? Object.fromEntries(this.env.map(({ name, value }) => [name, value]))
|
|
92
92
|
: undefined,
|
|
93
|
-
jobs: Object.fromEntries(await Promise.all(this.jobs.map(async ({ name, options:
|
|
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
|
-
|
|
93
|
+
jobs: Object.fromEntries(await Promise.all(this.jobs.map(async ({ name, options: jobOptions }) => {
|
|
94
|
+
if ("uses" in jobOptions) {
|
|
95
|
+
return [
|
|
96
|
+
name,
|
|
97
|
+
{
|
|
98
|
+
uses: jobOptions.uses,
|
|
99
|
+
with: jobOptions.with,
|
|
100
|
+
secrets: jobOptions.secrets,
|
|
101
|
+
},
|
|
102
|
+
];
|
|
103
|
+
}
|
|
104
|
+
const { prettyName, permissions, ifExpression, runsOn, matrix, env, steps, dependsOn, services, timeout, concurrency, outputs, workingDirectory, } = jobOptions;
|
|
105
|
+
return [
|
|
106
|
+
name,
|
|
107
|
+
{
|
|
108
|
+
name: prettyName,
|
|
109
|
+
permissions,
|
|
110
|
+
if: ifExpression,
|
|
111
|
+
"runs-on": runsOn ?? this.defaultRunner(),
|
|
112
|
+
"timeout-minutes": timeout ?? 15,
|
|
113
|
+
needs: dependsOn,
|
|
114
|
+
services,
|
|
115
|
+
concurrency: concurrency
|
|
116
|
+
? {
|
|
117
|
+
group: `${(0, kebabCase_1.default)(this.name)}-${name}-${concurrency.groupSuffix}`,
|
|
118
|
+
"cancel-in-progress": concurrency.cancelPrevious,
|
|
119
|
+
}
|
|
120
|
+
: undefined,
|
|
121
|
+
strategy: matrix
|
|
122
|
+
? {
|
|
123
|
+
"fail-fast": false,
|
|
124
|
+
matrix: typeof matrix === "string"
|
|
125
|
+
? matrix
|
|
126
|
+
: {
|
|
127
|
+
...Object.fromEntries(matrix.elements.map(({ id, options }) => [
|
|
128
|
+
id,
|
|
129
|
+
options,
|
|
130
|
+
])),
|
|
131
|
+
include: matrix.extra,
|
|
132
|
+
},
|
|
133
|
+
}
|
|
134
|
+
: undefined,
|
|
135
|
+
env,
|
|
136
|
+
defaults: workingDirectory
|
|
137
|
+
? {
|
|
138
|
+
run: {
|
|
139
|
+
"working-directory": workingDirectory,
|
|
120
140
|
},
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
141
|
+
}
|
|
142
|
+
: undefined,
|
|
143
|
+
steps: await Promise.all(steps.map(async (step) => {
|
|
144
|
+
const { id, name, ifExpression, workingDirectory, continueOnError, timeout, ...options } = step;
|
|
145
|
+
return {
|
|
146
|
+
id,
|
|
147
|
+
name,
|
|
148
|
+
if: ifExpression,
|
|
149
|
+
"continue-on-error": continueOnError,
|
|
127
150
|
"working-directory": workingDirectory,
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
"continue-on-error": continueOnError,
|
|
138
|
-
"working-directory": workingDirectory,
|
|
139
|
-
"timeout-minutes": timeout,
|
|
140
|
-
...options,
|
|
141
|
-
uses: await supplyChainAttack(step),
|
|
142
|
-
};
|
|
143
|
-
})),
|
|
144
|
-
outputs,
|
|
145
|
-
},
|
|
146
|
-
]))),
|
|
151
|
+
"timeout-minutes": timeout,
|
|
152
|
+
...options,
|
|
153
|
+
uses: await supplyChainAttack(step),
|
|
154
|
+
};
|
|
155
|
+
})),
|
|
156
|
+
outputs,
|
|
157
|
+
},
|
|
158
|
+
];
|
|
159
|
+
}))),
|
|
147
160
|
};
|
|
148
161
|
const compiled = `# Workflow automatically generated by gat\n# DO NOT CHANGE THIS FILE MANUALLY\n\n${(0, js_yaml_1.dump)(result, {
|
|
149
162
|
noRefs: true,
|
package/dist/workflow.spec.js
CHANGED
|
@@ -257,4 +257,25 @@ exit 0`,
|
|
|
257
257
|
});
|
|
258
258
|
(0, vitest_1.expect)(await workflow.compile()).toMatchSnapshot();
|
|
259
259
|
});
|
|
260
|
+
(0, vitest_1.it)("allows creating jobs with no steps, uses and secrets", async () => {
|
|
261
|
+
const workflow = new workflow_1.Workflow("Uses job")
|
|
262
|
+
.on("push")
|
|
263
|
+
.addJob("job1", {
|
|
264
|
+
uses: "example/example/.github/workflows/example1.yml@main",
|
|
265
|
+
with: {
|
|
266
|
+
foo: "foo",
|
|
267
|
+
},
|
|
268
|
+
secrets: "inherit",
|
|
269
|
+
})
|
|
270
|
+
.addJob("job2", {
|
|
271
|
+
uses: "example/example/.github/workflows/example2.yml@main",
|
|
272
|
+
with: {
|
|
273
|
+
bar: "bar",
|
|
274
|
+
},
|
|
275
|
+
secrets: {
|
|
276
|
+
secret: "super-secret",
|
|
277
|
+
},
|
|
278
|
+
});
|
|
279
|
+
(0, vitest_1.expect)(await workflow.compile()).toMatchSnapshot();
|
|
280
|
+
});
|
|
260
281
|
});
|