@factorialco/gat 2.1.0 → 2.3.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/cli.js +22 -17
- package/dist/event.js +1 -2
- package/dist/index.js +2 -5
- package/dist/job.js +1 -2
- package/dist/step.js +1 -5
- package/dist/workflow.js +112 -105
- package/dist/workflow.spec.js +76 -69
- package/package.json +4 -2
package/dist/cli.js
CHANGED
|
@@ -1,28 +1,33 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
return (
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
5
10
|
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const cli = new commander_1.Command();
|
|
11
|
+
import fs from "fs";
|
|
12
|
+
import path from "path";
|
|
13
|
+
import { exec } from "child_process";
|
|
14
|
+
import { Command } from "commander";
|
|
15
|
+
import { promisify } from "util";
|
|
16
|
+
const execPromise = promisify(exec);
|
|
17
|
+
const folder = path.join(process.cwd(), ".github", "templates");
|
|
18
|
+
const cli = new Command();
|
|
15
19
|
cli
|
|
16
20
|
.version("2.0.0")
|
|
17
21
|
.description("Write your GitHub Actions workflows using TypeScript");
|
|
18
22
|
cli
|
|
19
23
|
.command("build")
|
|
20
24
|
.description("Transpile all Gat templates into GitHub Actions workflows.")
|
|
21
|
-
.action(
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
.action(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
+
var _a;
|
|
27
|
+
if (!fs.existsSync(path.join(folder, "..", "workflows"))) {
|
|
28
|
+
fs.mkdirSync(path.join(folder, "..", "workflows"));
|
|
24
29
|
}
|
|
25
|
-
|
|
30
|
+
yield execPromise(`npx ts-node ${(_a = process.env["GAT_BUILD_FLAGS"]) !== null && _a !== void 0 ? _a : "--swc -T"} ${path.join(folder, "index.ts")}`);
|
|
26
31
|
process.exit(0);
|
|
27
|
-
});
|
|
32
|
+
}));
|
|
28
33
|
cli.parse(process.argv);
|
package/dist/event.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.Workflow = void 0;
|
|
4
|
-
const workflow_1 = require("./workflow");
|
|
5
|
-
Object.defineProperty(exports, "Workflow", { enumerable: true, get: function () { return workflow_1.Workflow; } });
|
|
1
|
+
import { Workflow } from "./workflow";
|
|
2
|
+
export { Workflow, };
|
package/dist/job.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/dist/step.js
CHANGED
package/dist/workflow.js
CHANGED
|
@@ -1,20 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
4
9
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
+
var t = {};
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
+
t[p[i]] = s[p[i]];
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
};
|
|
21
|
+
import { dump } from "js-yaml";
|
|
22
|
+
import kebabCase from "lodash/kebabCase";
|
|
23
|
+
import fs from "fs";
|
|
24
|
+
import path from "path";
|
|
25
|
+
import { promisify } from "util";
|
|
26
|
+
import fetch from 'node-fetch';
|
|
27
|
+
import { isUseStep } from "./step";
|
|
28
|
+
const writeFilePromise = promisify(fs.writeFile);
|
|
14
29
|
const DEFAULT_RUNNERS = ["ubuntu-22.04"];
|
|
15
30
|
const chainAttackCache = {};
|
|
16
|
-
const supplyChainAttack =
|
|
17
|
-
if (!
|
|
31
|
+
const supplyChainAttack = (step) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
+
if (!isUseStep(step))
|
|
18
33
|
return;
|
|
19
34
|
const uses = step.uses;
|
|
20
35
|
if (!uses)
|
|
@@ -25,16 +40,16 @@ const supplyChainAttack = async (step) => {
|
|
|
25
40
|
if (!match)
|
|
26
41
|
return uses;
|
|
27
42
|
const { repository, version } = match.groups;
|
|
28
|
-
const response =
|
|
29
|
-
const tags = (
|
|
43
|
+
const response = yield fetch(`https://api.github.com/repos/${repository}/tags`);
|
|
44
|
+
const tags = (yield response.json());
|
|
30
45
|
const tag = tags.find((tag) => tag.name === version);
|
|
31
46
|
if (!tag)
|
|
32
47
|
return uses;
|
|
33
48
|
const result = `${repository}@${tag.commit.sha}`;
|
|
34
49
|
chainAttackCache[uses] = result;
|
|
35
50
|
return result;
|
|
36
|
-
};
|
|
37
|
-
class Workflow {
|
|
51
|
+
});
|
|
52
|
+
export class Workflow {
|
|
38
53
|
constructor(name) {
|
|
39
54
|
this.name = name;
|
|
40
55
|
this.events = [];
|
|
@@ -66,96 +81,88 @@ class Workflow {
|
|
|
66
81
|
return "ubuntu-22.04";
|
|
67
82
|
}
|
|
68
83
|
assignRunner(runsOn) {
|
|
69
|
-
const runnerName = runsOn
|
|
84
|
+
const runnerName = runsOn !== null && runsOn !== void 0 ? runsOn : this.defaultRunner();
|
|
70
85
|
const isSelfHosted = !DEFAULT_RUNNERS.includes(runnerName);
|
|
71
86
|
return isSelfHosted ? ["self-hosted", runnerName] : runnerName;
|
|
72
87
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
name,
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
name,
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
"timeout-minutes": timeout ?? 15,
|
|
104
|
-
needs: dependsOn,
|
|
105
|
-
services,
|
|
106
|
-
concurrency: concurrency
|
|
107
|
-
? {
|
|
108
|
-
group: `${(0, kebabCase_1.default)(this.name)}-${name}-${concurrency.groupSuffix}`,
|
|
109
|
-
"cancel-in-progress": concurrency.cancelPrevious,
|
|
110
|
-
}
|
|
111
|
-
: undefined,
|
|
112
|
-
strategy: matrix
|
|
113
|
-
? {
|
|
114
|
-
"fail-fast": false,
|
|
115
|
-
matrix: typeof matrix === "string"
|
|
116
|
-
? matrix
|
|
117
|
-
: {
|
|
118
|
-
...Object.fromEntries(matrix.elements.map(({ id, options }) => [
|
|
119
|
-
id,
|
|
120
|
-
options,
|
|
121
|
-
])),
|
|
122
|
-
include: matrix.extra,
|
|
123
|
-
},
|
|
124
|
-
}
|
|
125
|
-
: undefined,
|
|
126
|
-
env,
|
|
127
|
-
defaults: workingDirectory
|
|
128
|
-
? {
|
|
129
|
-
run: {
|
|
130
|
-
"working-directory": workingDirectory,
|
|
131
|
-
},
|
|
132
|
-
}
|
|
133
|
-
: undefined,
|
|
134
|
-
steps: await Promise.all(steps.map(async (step) => {
|
|
135
|
-
const { id, name, ifExpression, workingDirectory, continueOnError, timeout, ...options } = step;
|
|
136
|
-
return {
|
|
137
|
-
id,
|
|
138
|
-
name,
|
|
88
|
+
compile(filepath) {
|
|
89
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
const result = {
|
|
91
|
+
name: this.name,
|
|
92
|
+
on: Object.fromEntries(this.events.map(({ name, options }) => [
|
|
93
|
+
name,
|
|
94
|
+
options ? options : null,
|
|
95
|
+
])),
|
|
96
|
+
concurrency: this.concurrencyGroup
|
|
97
|
+
? {
|
|
98
|
+
group: this.concurrencyGroup.groupSuffix,
|
|
99
|
+
"cancel-in-progress": this.concurrencyGroup.cancelPrevious,
|
|
100
|
+
}
|
|
101
|
+
: undefined,
|
|
102
|
+
defaults: this.defaultOptions
|
|
103
|
+
? {
|
|
104
|
+
run: {
|
|
105
|
+
"working-directory": this.defaultOptions.workingDirectory,
|
|
106
|
+
},
|
|
107
|
+
}
|
|
108
|
+
: undefined,
|
|
109
|
+
env: this.env.length > 0
|
|
110
|
+
? Object.fromEntries(this.env.map(({ name, value }) => [name, value]))
|
|
111
|
+
: undefined,
|
|
112
|
+
jobs: Object.fromEntries(yield Promise.all(this.jobs.map(({ name, options: { prettyName, permissions, ifExpression, runsOn, matrix, env, steps, dependsOn, services, timeout, concurrency, outputs, workingDirectory, }, }) => __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
return [
|
|
114
|
+
name,
|
|
115
|
+
{
|
|
116
|
+
name: prettyName,
|
|
117
|
+
permissions,
|
|
139
118
|
if: ifExpression,
|
|
140
|
-
"
|
|
141
|
-
"
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
119
|
+
"runs-on": this.assignRunner(runsOn),
|
|
120
|
+
"timeout-minutes": timeout !== null && timeout !== void 0 ? timeout : 15,
|
|
121
|
+
needs: dependsOn,
|
|
122
|
+
services,
|
|
123
|
+
concurrency: concurrency
|
|
124
|
+
? {
|
|
125
|
+
group: `${kebabCase(this.name)}-${name}-${concurrency.groupSuffix}`,
|
|
126
|
+
"cancel-in-progress": concurrency.cancelPrevious,
|
|
127
|
+
}
|
|
128
|
+
: undefined,
|
|
129
|
+
strategy: matrix
|
|
130
|
+
? {
|
|
131
|
+
"fail-fast": false,
|
|
132
|
+
matrix: typeof matrix === "string"
|
|
133
|
+
? matrix
|
|
134
|
+
: Object.assign(Object.assign({}, Object.fromEntries(matrix.elements.map(({ id, options }) => [
|
|
135
|
+
id,
|
|
136
|
+
options,
|
|
137
|
+
]))), { include: matrix.extra }),
|
|
138
|
+
}
|
|
139
|
+
: undefined,
|
|
140
|
+
env,
|
|
141
|
+
defaults: workingDirectory
|
|
142
|
+
? {
|
|
143
|
+
run: {
|
|
144
|
+
"working-directory": workingDirectory,
|
|
145
|
+
},
|
|
146
|
+
}
|
|
147
|
+
: undefined,
|
|
148
|
+
steps: yield Promise.all(steps.map((step) => __awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
const { id, name, ifExpression, workingDirectory, continueOnError, timeout } = step, options = __rest(step, ["id", "name", "ifExpression", "workingDirectory", "continueOnError", "timeout"]);
|
|
150
|
+
return Object.assign(Object.assign({ id,
|
|
151
|
+
name, if: ifExpression, "continue-on-error": continueOnError, "working-directory": workingDirectory, "timeout-minutes": timeout }, options), { uses: yield supplyChainAttack(step) });
|
|
152
|
+
}))),
|
|
153
|
+
outputs,
|
|
154
|
+
},
|
|
155
|
+
];
|
|
156
|
+
})))),
|
|
157
|
+
};
|
|
158
|
+
const compiled = `# Workflow automatically generated by gat\n# DO NOT CHANGE THIS FILE MANUALLY\n\n${dump(result, {
|
|
159
|
+
noRefs: true,
|
|
160
|
+
lineWidth: 200,
|
|
161
|
+
noCompatMode: true,
|
|
162
|
+
})}`;
|
|
163
|
+
if (!filepath)
|
|
164
|
+
return compiled;
|
|
165
|
+
return writeFilePromise(path.join(process.cwd(), ".github", "workflows", filepath), compiled);
|
|
166
|
+
});
|
|
159
167
|
}
|
|
160
168
|
}
|
|
161
|
-
exports.Workflow = Workflow;
|
package/dist/workflow.spec.js
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
(
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { describe, it, expect } from "vitest";
|
|
11
|
+
import { Workflow } from "./workflow";
|
|
12
|
+
describe("Workflow", () => {
|
|
13
|
+
it("generates a simple workflow", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
const workflow = new Workflow("Simple");
|
|
8
15
|
workflow
|
|
9
16
|
.on("pull_request", { types: ["opened"] })
|
|
10
17
|
.addJob("job1", {
|
|
@@ -14,20 +21,20 @@ const workflow_1 = require("./workflow");
|
|
|
14
21
|
steps: [{ name: "Do something else", run: "exit 0" }],
|
|
15
22
|
dependsOn: ["job1"],
|
|
16
23
|
});
|
|
17
|
-
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
const workflow = new
|
|
24
|
+
expect(yield workflow.compile()).toMatchSnapshot();
|
|
25
|
+
}));
|
|
26
|
+
it("allows multiple events", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
+
const workflow = new Workflow("Multiple events");
|
|
21
28
|
workflow
|
|
22
29
|
.on("push", { branches: ["main"] })
|
|
23
30
|
.on("pull_request", { types: ["opened"] })
|
|
24
31
|
.addJob("job1", {
|
|
25
32
|
steps: [{ name: "Do something", run: "exit 0" }],
|
|
26
33
|
});
|
|
27
|
-
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const workflow = new
|
|
34
|
+
expect(yield workflow.compile()).toMatchSnapshot();
|
|
35
|
+
}));
|
|
36
|
+
it("allows declaring default options", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
const workflow = new Workflow("Default options");
|
|
31
38
|
workflow
|
|
32
39
|
.on("push", { branches: ["main"] })
|
|
33
40
|
.addDefaults({
|
|
@@ -36,10 +43,10 @@ const workflow_1 = require("./workflow");
|
|
|
36
43
|
.addJob("job1", {
|
|
37
44
|
steps: [{ name: "Do something", run: "exit 0" }],
|
|
38
45
|
});
|
|
39
|
-
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
const workflow = new
|
|
46
|
+
expect(yield workflow.compile()).toMatchSnapshot();
|
|
47
|
+
}));
|
|
48
|
+
it("allows declaring environment variables", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
+
const workflow = new Workflow("With Environment variables");
|
|
43
50
|
workflow
|
|
44
51
|
.on("push")
|
|
45
52
|
.setEnv("NODE_VERSION", "16")
|
|
@@ -52,10 +59,10 @@ const workflow_1 = require("./workflow");
|
|
|
52
59
|
},
|
|
53
60
|
],
|
|
54
61
|
});
|
|
55
|
-
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
const workflow = new
|
|
62
|
+
expect(yield workflow.compile()).toMatchSnapshot();
|
|
63
|
+
}));
|
|
64
|
+
it("allows using a concurrency group", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
|
+
const workflow = new Workflow("Concurrency group");
|
|
59
66
|
workflow.on("push").addJob("job1", {
|
|
60
67
|
concurrency: {
|
|
61
68
|
groupSuffix: "foo",
|
|
@@ -67,10 +74,10 @@ const workflow_1 = require("./workflow");
|
|
|
67
74
|
},
|
|
68
75
|
],
|
|
69
76
|
});
|
|
70
|
-
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
const workflow = new
|
|
77
|
+
expect(yield workflow.compile()).toMatchSnapshot();
|
|
78
|
+
}));
|
|
79
|
+
it("allows using outputs", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
80
|
+
const workflow = new Workflow("Using outputs");
|
|
74
81
|
workflow.on("push").addJob("job1", {
|
|
75
82
|
steps: [
|
|
76
83
|
{
|
|
@@ -82,10 +89,10 @@ const workflow_1 = require("./workflow");
|
|
|
82
89
|
"random-number": "${{ steps.random-number.outputs.random-number }}",
|
|
83
90
|
},
|
|
84
91
|
});
|
|
85
|
-
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
const workflow = new
|
|
92
|
+
expect(yield workflow.compile()).toMatchSnapshot();
|
|
93
|
+
}));
|
|
94
|
+
it("allows conditional jobs", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
95
|
+
const workflow = new Workflow("Conditional job");
|
|
89
96
|
workflow.on("push").addJob("job1", {
|
|
90
97
|
ifExpression: "${{ github.ref != 'refs/heads/main' }}",
|
|
91
98
|
steps: [
|
|
@@ -94,10 +101,10 @@ const workflow_1 = require("./workflow");
|
|
|
94
101
|
},
|
|
95
102
|
],
|
|
96
103
|
});
|
|
97
|
-
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
const workflow = new
|
|
104
|
+
expect(yield workflow.compile()).toMatchSnapshot();
|
|
105
|
+
}));
|
|
106
|
+
it("allows a job matrix", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
107
|
+
const workflow = new Workflow("Conditional job");
|
|
101
108
|
workflow.on("push").addJob("job1", {
|
|
102
109
|
matrix: {
|
|
103
110
|
elements: [
|
|
@@ -124,10 +131,10 @@ const workflow_1 = require("./workflow");
|
|
|
124
131
|
},
|
|
125
132
|
],
|
|
126
133
|
});
|
|
127
|
-
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
const workflow = new
|
|
134
|
+
expect(yield workflow.compile()).toMatchSnapshot();
|
|
135
|
+
}));
|
|
136
|
+
it("allows uses steps", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
137
|
+
const workflow = new Workflow("Uses steps");
|
|
131
138
|
workflow
|
|
132
139
|
.on("push")
|
|
133
140
|
.setEnv("NODE_VERSION", "16")
|
|
@@ -142,10 +149,10 @@ const workflow_1 = require("./workflow");
|
|
|
142
149
|
},
|
|
143
150
|
],
|
|
144
151
|
});
|
|
145
|
-
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
const workflow = new
|
|
152
|
+
expect(yield workflow.compile()).toMatchSnapshot();
|
|
153
|
+
}));
|
|
154
|
+
it("allows custom types in a workflow", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
155
|
+
const workflow = new Workflow("With custom types");
|
|
149
156
|
workflow.on("push").addJob("job1", {
|
|
150
157
|
runsOn: "standard-runner",
|
|
151
158
|
steps: [
|
|
@@ -160,10 +167,10 @@ const workflow_1 = require("./workflow");
|
|
|
160
167
|
},
|
|
161
168
|
],
|
|
162
169
|
});
|
|
163
|
-
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
const workflow = new
|
|
170
|
+
expect(yield workflow.compile()).toMatchSnapshot();
|
|
171
|
+
}));
|
|
172
|
+
it("support workflow dispatch event", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
173
|
+
const workflow = new Workflow("Workflow dispatch");
|
|
167
174
|
workflow
|
|
168
175
|
.on("workflow_dispatch", {
|
|
169
176
|
inputs: {
|
|
@@ -181,27 +188,27 @@ const workflow_1 = require("./workflow");
|
|
|
181
188
|
.addJob("job1", {
|
|
182
189
|
steps: [{ name: "Do something", run: "exit 0" }],
|
|
183
190
|
});
|
|
184
|
-
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
const workflow = new
|
|
191
|
+
expect(yield workflow.compile()).toMatchSnapshot();
|
|
192
|
+
}));
|
|
193
|
+
it("supports schedule event", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
194
|
+
const workflow = new Workflow("Schedule")
|
|
188
195
|
.on("schedule", [{ cron: "0 4 * * 1-5" }])
|
|
189
196
|
.addJob("job1", {
|
|
190
197
|
steps: [{ name: "Do something", run: "exit 0" }],
|
|
191
198
|
});
|
|
192
|
-
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
const workflow = new
|
|
199
|
+
expect(yield workflow.compile()).toMatchSnapshot();
|
|
200
|
+
}));
|
|
201
|
+
it("supports a pretty name for the job", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
202
|
+
const workflow = new Workflow("Job with pretty name")
|
|
196
203
|
.on("push")
|
|
197
204
|
.addJob("job1", {
|
|
198
205
|
prettyName: "My pretty name",
|
|
199
206
|
steps: [{ name: "Do something", run: "exit 0" }],
|
|
200
207
|
});
|
|
201
|
-
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
const workflow = new
|
|
208
|
+
expect(yield workflow.compile()).toMatchSnapshot();
|
|
209
|
+
}));
|
|
210
|
+
it("allows permissions into jobs", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
211
|
+
const workflow = new Workflow("Job with permissions")
|
|
205
212
|
.on("push")
|
|
206
213
|
.addJob("job1", {
|
|
207
214
|
permissions: {
|
|
@@ -210,10 +217,10 @@ const workflow_1 = require("./workflow");
|
|
|
210
217
|
},
|
|
211
218
|
steps: [{ name: "Do something", run: "exit 0" }],
|
|
212
219
|
});
|
|
213
|
-
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
const workflow = new
|
|
220
|
+
expect(yield workflow.compile()).toMatchSnapshot();
|
|
221
|
+
}));
|
|
222
|
+
it("allows multiline strings", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
223
|
+
const workflow = new Workflow("Multiline strings")
|
|
217
224
|
.on("push")
|
|
218
225
|
.addJob("job1", {
|
|
219
226
|
steps: [
|
|
@@ -224,10 +231,10 @@ exit 0`,
|
|
|
224
231
|
},
|
|
225
232
|
],
|
|
226
233
|
});
|
|
227
|
-
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
const workflow = new
|
|
234
|
+
expect(yield workflow.compile()).toMatchSnapshot();
|
|
235
|
+
}));
|
|
236
|
+
it("allows concurrency groups at workflow level", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
237
|
+
const workflow = new Workflow("Concurrency at workflow level")
|
|
231
238
|
.on("push")
|
|
232
239
|
.setConcurrencyGroup({
|
|
233
240
|
groupSuffix: "${{ github.workflow }}-${{ github.ref }}",
|
|
@@ -241,6 +248,6 @@ exit 0`,
|
|
|
241
248
|
},
|
|
242
249
|
],
|
|
243
250
|
});
|
|
244
|
-
|
|
245
|
-
});
|
|
251
|
+
expect(yield workflow.compile()).toMatchSnapshot();
|
|
252
|
+
}));
|
|
246
253
|
});
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@factorialco/gat",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Write your GitHub Actions workflows using TypeScript",
|
|
5
5
|
"bin": {
|
|
6
6
|
"gat": "dist/cli.js"
|
|
7
7
|
},
|
|
8
|
+
"type": "module",
|
|
8
9
|
"main": "dist/index.js",
|
|
9
10
|
"files": [
|
|
10
11
|
"dist/**/*"
|
|
@@ -37,7 +38,8 @@
|
|
|
37
38
|
},
|
|
38
39
|
"dependencies": {
|
|
39
40
|
"js-yaml": "^4.1.0",
|
|
40
|
-
"lodash": "^4.17.21"
|
|
41
|
+
"lodash": "^4.17.21",
|
|
42
|
+
"node-fetch": "^3.3.2"
|
|
41
43
|
},
|
|
42
44
|
"repository": {
|
|
43
45
|
"type": "git",
|