@factorialco/gat 2.6.0 → 3.0.1

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/cli.js CHANGED
File without changes
package/dist/job.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export interface ConcurrencyGroup {
1
+ export type ConcurrencyGroup = {
2
2
  groupSuffix: string;
3
3
  cancelPrevious: boolean;
4
- }
4
+ };
5
5
  export interface Matrix {
6
6
  elements: Array<{
7
7
  id: string;
@@ -20,23 +20,23 @@ export interface Service {
20
20
  options?: string;
21
21
  volumes?: string[];
22
22
  }
23
- export interface JobOptions<Step, Runner, Name> {
23
+ export interface JobOptions<Step, RunnerDefinition, Name> {
24
24
  prettyName?: string;
25
25
  permissions?: object;
26
26
  ifExpression?: string;
27
- runsOn?: Runner;
27
+ runsOn?: RunnerDefinition;
28
28
  timeout?: number;
29
29
  dependsOn?: Array<Name>;
30
30
  services?: Record<string, Service>;
31
31
  env?: Record<string, string>;
32
- concurrency?: ConcurrencyGroup;
32
+ concurrency?: ConcurrencyGroup | null;
33
33
  matrix?: Matrix | string;
34
34
  steps: Step[];
35
35
  outputs?: Record<string, string>;
36
36
  workingDirectory?: string;
37
37
  }
38
38
  export type StringWithNoSpaces<T> = T extends `${string} ${string}` ? never : T extends ` ${string}` ? never : T extends `${string} ` ? never : T;
39
- export interface Job<Step, Runner, Name> {
39
+ export interface Job<Step, RunnerDefinition, Name> {
40
40
  name: string;
41
- options: JobOptions<Step, Runner, Name>;
41
+ options: JobOptions<Step, RunnerDefinition, Name>;
42
42
  }
@@ -1,7 +1,6 @@
1
1
  import { ConcurrencyGroup, Job, JobOptions, StringWithNoSpaces } from "./job";
2
2
  import type { Event, EventName, EventOptions } from "./event";
3
3
  import { type Step } from "./step";
4
- declare const DEFAULT_RUNNERS: string[];
5
4
  interface DefaultOptions {
6
5
  workingDirectory: string;
7
6
  }
@@ -9,21 +8,24 @@ interface EnvVar {
9
8
  name: string;
10
9
  value: string;
11
10
  }
12
- export declare class Workflow<JobStep extends Step = Step, Runner = typeof DEFAULT_RUNNERS, JobName = never> {
11
+ export type RunnerDefinition = string | {
12
+ group: string;
13
+ labels?: string[];
14
+ } | ["self-hosted", string];
15
+ export declare class Workflow<JobStep extends Step = Step, Runner extends RunnerDefinition = RunnerDefinition, JobName = never> {
13
16
  name: string;
14
17
  events: Event[];
15
18
  jobs: Array<Job<JobStep, Runner, JobName>>;
16
19
  defaultOptions: DefaultOptions | null;
17
20
  env: EnvVar[];
18
- concurrencyGroup?: ConcurrencyGroup;
21
+ concurrencyGroup?: ConcurrencyGroup | null;
19
22
  constructor(name: string);
20
23
  on<T extends EventName>(name: T, options?: EventOptions<T>): this;
21
24
  addDefaults(options: DefaultOptions): this;
22
25
  addJob<T extends string>(name: StringWithNoSpaces<T>, options: JobOptions<JobStep, Runner, JobName>): Workflow<JobStep, Runner, JobName | T>;
23
26
  setEnv(name: string, value: string): this;
24
- setConcurrencyGroup(concurrencyGroup: ConcurrencyGroup): this;
27
+ setConcurrencyGroup(concurrencyGroup: ConcurrencyGroup | null): this;
25
28
  defaultRunner(): string;
26
- private assignRunner;
27
29
  compile(filepath?: string): Promise<string | void>;
28
30
  }
29
31
  export {};
package/dist/workflow.js CHANGED
@@ -12,7 +12,6 @@ const util_1 = require("util");
12
12
  const axios_1 = __importDefault(require("axios"));
13
13
  const step_1 = require("./step");
14
14
  const writeFilePromise = (0, util_1.promisify)(fs_1.default.writeFile);
15
- const DEFAULT_RUNNERS = ["ubuntu-22.04"];
16
15
  const chainAttackCache = {};
17
16
  const supplyChainAttack = async (step, enabled = false) => {
18
17
  if (!(0, step_1.isUseStep)(step))
@@ -68,11 +67,6 @@ class Workflow {
68
67
  defaultRunner() {
69
68
  return "ubuntu-22.04";
70
69
  }
71
- assignRunner(runsOn) {
72
- const runnerName = runsOn ?? this.defaultRunner();
73
- const isSelfHosted = !DEFAULT_RUNNERS.includes(runnerName);
74
- return isSelfHosted ? ["self-hosted", runnerName] : runnerName;
75
- }
76
70
  async compile(filepath) {
77
71
  const result = {
78
72
  name: this.name,
@@ -102,7 +96,7 @@ class Workflow {
102
96
  name: prettyName,
103
97
  permissions,
104
98
  if: ifExpression,
105
- "runs-on": this.assignRunner(runsOn),
99
+ "runs-on": runsOn ?? this.defaultRunner(),
106
100
  "timeout-minutes": timeout ?? 15,
107
101
  needs: dependsOn,
108
102
  services,
@@ -147,7 +147,7 @@ const workflow_1 = require("./workflow");
147
147
  (0, vitest_1.it)("allows custom types in a workflow", async () => {
148
148
  const workflow = new workflow_1.Workflow("With custom types");
149
149
  workflow.on("push").addJob("job1", {
150
- runsOn: "standard-runner",
150
+ runsOn: ["self-hosted", "standard-runner"],
151
151
  steps: [
152
152
  {
153
153
  run: "echo 'Do something'",
@@ -243,4 +243,18 @@ exit 0`,
243
243
  });
244
244
  (0, vitest_1.expect)(await workflow.compile()).toMatchSnapshot();
245
245
  });
246
+ (0, vitest_1.it)("allows creating jobs with concurrency set to null", async () => {
247
+ const workflow = new workflow_1.Workflow("Without concurrency")
248
+ .on("push")
249
+ .addJob("job1", {
250
+ concurrency: null,
251
+ steps: [
252
+ {
253
+ name: "Do something",
254
+ run: "exit 0",
255
+ },
256
+ ],
257
+ });
258
+ (0, vitest_1.expect)(await workflow.compile()).toMatchSnapshot();
259
+ });
246
260
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@factorialco/gat",
3
- "version": "2.6.0",
3
+ "version": "3.0.1",
4
4
  "description": "Write your GitHub Actions workflows using TypeScript",
5
5
  "bin": {
6
6
  "gat": "dist/cli.js"
@@ -11,16 +11,6 @@
11
11
  "dist/**/*"
12
12
  ],
13
13
  "types": "dist/index.d.ts",
14
- "scripts": {
15
- "build": "tsc",
16
- "prepare": "npm run build",
17
- "prepublishOnly": "vitest run",
18
- "test": "vitest",
19
- "coverage": "vitest run --coverage",
20
- "lint": "eslint src/**/*.ts",
21
- "format": "prettier --write .",
22
- "format:check": "prettier --check ."
23
- },
24
14
  "author": "David Morcillo <david.morcillo@factorial.co>",
25
15
  "license": "ISC",
26
16
  "devDependencies": {
@@ -49,5 +39,13 @@
49
39
  "bugs": {
50
40
  "url": "https://github.com/factorialco/gat/issues"
51
41
  },
52
- "homepage": "https://github.com/factorialco/gat#readme"
53
- }
42
+ "homepage": "https://github.com/factorialco/gat#readme",
43
+ "scripts": {
44
+ "build": "tsc",
45
+ "test": "vitest",
46
+ "coverage": "vitest run --coverage",
47
+ "lint": "eslint src/**/*.ts",
48
+ "format": "prettier --write .",
49
+ "format:check": "prettier --check ."
50
+ }
51
+ }