@factorialco/gat 3.0.3 → 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/event.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export type EventName = "push" | "pull_request" | "pull_request_review" | "workflow_run" | "workflow_dispatch" | "schedule" | "pull_request_target" | "repository_dispatch";
2
- export type EventOptions<T extends EventName> = T extends "push" ? PushEventOptions : T extends "pull_request" ? PullRequestEventOptions : T extends "pull_request_review" ? PullRequestReviewEventOptions : T extends "workflow_run" ? WorkflowRunEventOptions : T extends "workflow_dispatch" ? WorkflowDispatchEventOptions : T extends "schedule" ? ScheduleEventOptions : T extends "repository_dispatch" ? RepositoryDispatchEventOptions : never;
1
+ export type EventName = "push" | "pull_request" | "pull_request_review" | "workflow_run" | "workflow_dispatch" | "workflow_call" | "schedule" | "pull_request_target" | "repository_dispatch";
2
+ export type EventOptions<T extends EventName> = T extends "push" ? PushEventOptions : T extends "pull_request" ? PullRequestEventOptions : T extends "pull_request_review" ? PullRequestReviewEventOptions : T extends "workflow_run" ? WorkflowRunEventOptions : T extends "workflow_dispatch" ? WorkflowDispatchEventOptions : T extends "workflow_call" ? WorkflowCallEventOptions : T extends "schedule" ? ScheduleEventOptions : T extends "repository_dispatch" ? RepositoryDispatchEventOptions : never;
3
3
  interface PushEventOptions {
4
4
  branches?: string[];
5
5
  paths?: string[];
@@ -27,6 +27,14 @@ interface WorkflowDispatchInput {
27
27
  interface WorkflowDispatchEventOptions {
28
28
  inputs?: Record<string, WorkflowDispatchInput>;
29
29
  }
30
+ interface WorkflowCallSecret {
31
+ description?: string;
32
+ required?: boolean;
33
+ }
34
+ interface WorkflowCallEventOptions {
35
+ inputs?: Record<string, WorkflowDispatchInput>;
36
+ secrets?: Record<string, WorkflowCallSecret>;
37
+ }
30
38
  type ScheduleEventOptions = Array<{
31
39
  cron: string;
32
40
  }>;
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
  }
@@ -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: { prettyName, permissions, ifExpression, runsOn, matrix, env, steps, dependsOn, services, timeout, concurrency, outputs, workingDirectory, }, }) => [
94
- name,
95
- {
96
- name: prettyName,
97
- permissions,
98
- if: ifExpression,
99
- "runs-on": runsOn ?? this.defaultRunner(),
100
- "timeout-minutes": timeout ?? 15,
101
- needs: dependsOn,
102
- services,
103
- concurrency: concurrency
104
- ? {
105
- group: `${(0, kebabCase_1.default)(this.name)}-${name}-${concurrency.groupSuffix}`,
106
- "cancel-in-progress": concurrency.cancelPrevious,
107
- }
108
- : undefined,
109
- strategy: matrix
110
- ? {
111
- "fail-fast": false,
112
- matrix: typeof matrix === "string"
113
- ? matrix
114
- : {
115
- ...Object.fromEntries(matrix.elements.map(({ id, options }) => [
116
- id,
117
- options,
118
- ])),
119
- include: matrix.extra,
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
- : undefined,
123
- env,
124
- defaults: workingDirectory
125
- ? {
126
- run: {
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
- : 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
- 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,
@@ -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.3",
3
+ "version": "3.1.0",
4
4
  "description": "Write your GitHub Actions workflows using TypeScript",
5
5
  "bin": {
6
6
  "gat": "dist/cli.js"