@factorialco/gat 3.4.2 → 3.4.4

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 CHANGED
@@ -33,6 +33,7 @@ export interface StepsJobOptions<Step, RunnerDefinition, Name> {
33
33
  matrix?: Matrix | string;
34
34
  outputs?: Record<string, string>;
35
35
  workingDirectory?: string;
36
+ environment?: string;
36
37
  steps: Step[];
37
38
  }
38
39
  export interface UsesJobOptions<Name> {
@@ -42,6 +43,7 @@ export interface UsesJobOptions<Name> {
42
43
  uses: string;
43
44
  with?: Record<string, string | number | boolean | object>;
44
45
  secrets?: Record<string, string | number | boolean | object> | "inherit";
46
+ environment?: string;
45
47
  }
46
48
  export type StringWithNoSpaces<T> = T extends `${string} ${string}` ? never : T extends ` ${string}` ? never : T extends `${string} ` ? never : T;
47
49
  export interface Job<Step, RunnerDefinition, Name> {
package/dist/template.js CHANGED
@@ -32,15 +32,32 @@ const createLockFile = async (templates, lockFilePath) => {
32
32
  return;
33
33
  const { repository, version } = match.groups;
34
34
  const [owner, repo] = repository.split("/");
35
- const response = await octokit.rest.repos.listTags({
36
- owner,
37
- repo,
38
- });
39
- const tag = response.data.find((tag) => tag.name === version);
40
- if (!tag) {
41
- throw new Error(`Unable to retrieve ${action} from Github tags`);
35
+ if (/^[a-f0-9]{40}$/.test(version)) {
36
+ // Assume version is a SHA
37
+ resolvedActions[action] = `${repository}@${version}`;
38
+ }
39
+ else {
40
+ let tag = null;
41
+ let page = 1;
42
+ const perPage = 100;
43
+ while (!tag) {
44
+ const response = await octokit.rest.repos.listTags({
45
+ owner,
46
+ repo,
47
+ per_page: perPage,
48
+ page,
49
+ });
50
+ tag = response.data.find((tag) => tag.name === version);
51
+ if (response.data.length < perPage) {
52
+ break; // No more pages to check
53
+ }
54
+ page++;
55
+ }
56
+ if (!tag) {
57
+ throw new Error(`Unable to retrieve ${action} from Github tags`);
58
+ }
59
+ resolvedActions[action] = `${repository}@${tag.commit.sha}`;
42
60
  }
43
- resolvedActions[action] = `${repository}@${tag.commit.sha}`;
44
61
  }));
45
62
  fs_1.default.writeFileSync(lockFilePath, JSON.stringify(resolvedActions, null, 2));
46
63
  };
package/dist/workflow.js CHANGED
@@ -73,7 +73,7 @@ class Workflow {
73
73
  : undefined,
74
74
  jobs: Object.fromEntries(await Promise.all(this.jobs.map(async ({ name, options: jobOptions }) => {
75
75
  if ("uses" in jobOptions) {
76
- const { prettyName, ifExpression, dependsOn } = jobOptions;
76
+ const { prettyName, ifExpression, dependsOn, environment } = jobOptions;
77
77
  return [
78
78
  name,
79
79
  {
@@ -83,10 +83,11 @@ class Workflow {
83
83
  uses: jobOptions.uses,
84
84
  with: jobOptions.with,
85
85
  secrets: jobOptions.secrets,
86
+ environment,
86
87
  },
87
88
  ];
88
89
  }
89
- const { prettyName, permissions, ifExpression, runsOn, matrix, env, dependsOn, services, timeout, concurrency, outputs, workingDirectory, } = jobOptions;
90
+ const { prettyName, permissions, ifExpression, runsOn, matrix, env, dependsOn, services, timeout, concurrency, outputs, workingDirectory, environment, } = jobOptions;
90
91
  return [
91
92
  name,
92
93
  {
@@ -118,6 +119,7 @@ class Workflow {
118
119
  }
119
120
  : undefined,
120
121
  env,
122
+ environment,
121
123
  defaults: workingDirectory
122
124
  ? {
123
125
  run: {
@@ -291,4 +291,12 @@ exit 0`,
291
291
  },
292
292
  })).toMatchSnapshot();
293
293
  });
294
+ (0, vitest_1.it)("allows setting environment on a job", async () => {
295
+ const workflow = new workflow_1.Workflow("Job Environment");
296
+ workflow.on("push").addJob("job1", {
297
+ environment: "production",
298
+ steps: [{ name: "Do something", run: "echo 'Hello'" }],
299
+ });
300
+ (0, vitest_1.expect)(await workflow.compile()).toMatchSnapshot();
301
+ });
294
302
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@factorialco/gat",
3
- "version": "3.4.2",
3
+ "version": "3.4.4",
4
4
  "description": "Write your GitHub Actions workflows using TypeScript",
5
5
  "bin": {
6
6
  "gat": "dist/cli.js"