@factorialco/gat 3.0.4 → 3.2.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/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import { Workflow } from "./workflow";
2
- import { type ConcurrencyGroup, type JobOptions, type Matrix, type Service } from "./job";
2
+ import { type ConcurrencyGroup, type StepsJobOptions, type UsesJobOptions, type Matrix, type Service } from "./job";
3
3
  import { type RunStep, type UseStep, type BaseStep } from "./step";
4
- export { Workflow, RunStep, UseStep, BaseStep, ConcurrencyGroup, JobOptions, Matrix, Service, };
4
+ export { Workflow, RunStep, UseStep, BaseStep, ConcurrencyGroup, StepsJobOptions, UsesJobOptions, Matrix, Service, };
package/dist/job.d.ts CHANGED
@@ -20,7 +20,7 @@ export interface Service {
20
20
  options?: string;
21
21
  volumes?: string[];
22
22
  }
23
- export interface JobOptions<Step, RunnerDefinition, Name> {
23
+ export interface BaseJobOptions<RunnerDefinition, Name> {
24
24
  prettyName?: string;
25
25
  permissions?: object;
26
26
  ifExpression?: string;
@@ -31,12 +31,19 @@ export interface JobOptions<Step, RunnerDefinition, Name> {
31
31
  env?: Record<string, string>;
32
32
  concurrency?: ConcurrencyGroup | null;
33
33
  matrix?: Matrix | string;
34
- steps: Step[];
35
34
  outputs?: Record<string, string>;
36
35
  workingDirectory?: string;
37
36
  }
37
+ export interface StepsJobOptions<Step, RunnerDefinition, Name> extends BaseJobOptions<RunnerDefinition, Name> {
38
+ steps: Step[];
39
+ }
40
+ export interface UsesJobOptions<RunnerDefinition, Name> extends BaseJobOptions<RunnerDefinition, Name> {
41
+ uses: string;
42
+ with?: Record<string, string | number | boolean | object>;
43
+ secrets?: Record<string, string | number | boolean | object> | "inherit";
44
+ }
38
45
  export type StringWithNoSpaces<T> = T extends `${string} ${string}` ? never : T extends ` ${string}` ? never : T extends `${string} ` ? never : T;
39
46
  export interface Job<Step, RunnerDefinition, Name> {
40
47
  name: string;
41
- options: JobOptions<Step, RunnerDefinition, Name>;
48
+ options: StepsJobOptions<Step, RunnerDefinition, Name> | UsesJobOptions<RunnerDefinition, Name>;
42
49
  }
@@ -1,4 +1,4 @@
1
- import { ConcurrencyGroup, Job, JobOptions, StringWithNoSpaces } from "./job";
1
+ import { ConcurrencyGroup, Job, StepsJobOptions, 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: StepsJobOptions<JobStep, Runner, JobName> | UsesJobOptions<Runner, JobName>): 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,9 +90,9 @@ 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: { prettyName, permissions, ifExpression, runsOn, matrix, env, steps, dependsOn, services, timeout, concurrency, outputs, workingDirectory, }, }) => [
94
- name,
95
- {
93
+ jobs: Object.fromEntries(await Promise.all(this.jobs.map(async ({ name, options: jobOptions }) => {
94
+ const { prettyName, permissions, ifExpression, runsOn, matrix, env, dependsOn, services, timeout, concurrency, outputs, workingDirectory, } = jobOptions;
95
+ const computedOptions = {
96
96
  name: prettyName,
97
97
  permissions,
98
98
  if: ifExpression,
@@ -128,22 +128,39 @@ class Workflow {
128
128
  },
129
129
  }
130
130
  : undefined,
131
- steps: await Promise.all(steps.map(async (step) => {
132
- const { id, name, ifExpression, workingDirectory, continueOnError, timeout, ...options } = step;
133
- return {
134
- id,
135
- name,
136
- if: ifExpression,
137
- "continue-on-error": continueOnError,
138
- "working-directory": workingDirectory,
139
- "timeout-minutes": timeout,
140
- ...options,
141
- uses: await supplyChainAttack(step),
142
- };
143
- })),
144
131
  outputs,
145
- },
146
- ]))),
132
+ };
133
+ if ("uses" in jobOptions) {
134
+ return [
135
+ name,
136
+ {
137
+ ...computedOptions,
138
+ uses: jobOptions.uses,
139
+ with: jobOptions.with,
140
+ secrets: jobOptions.secrets,
141
+ },
142
+ ];
143
+ }
144
+ return [
145
+ name,
146
+ {
147
+ ...computedOptions,
148
+ steps: await Promise.all(jobOptions.steps.map(async (step) => {
149
+ const { id, name, ifExpression, workingDirectory, continueOnError, timeout, ...options } = step;
150
+ return {
151
+ id,
152
+ name,
153
+ if: ifExpression,
154
+ "continue-on-error": continueOnError,
155
+ "working-directory": workingDirectory,
156
+ "timeout-minutes": timeout,
157
+ ...options,
158
+ uses: await supplyChainAttack(step),
159
+ };
160
+ })),
161
+ },
162
+ ];
163
+ }))),
147
164
  };
148
165
  const compiled = `# Workflow automatically generated by gat\n# DO NOT CHANGE THIS FILE MANUALLY\n\n${(0, js_yaml_1.dump)(result, {
149
166
  noRefs: true,
@@ -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
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@factorialco/gat",
3
- "version": "3.0.4",
3
+ "version": "3.2.0",
4
4
  "description": "Write your GitHub Actions workflows using TypeScript",
5
5
  "bin": {
6
6
  "gat": "dist/cli.js"