@factorialco/gat 0.0.13 → 0.0.16
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 +16 -6
- package/dist/event.d.ts +1 -1
- package/dist/job.d.ts +1 -0
- package/dist/workflow.js +6 -5
- package/dist/workflow.spec.js +28 -0
- package/package.json +4 -3
package/dist/cli.js
CHANGED
|
@@ -10,21 +10,31 @@ const child_process_1 = require("child_process");
|
|
|
10
10
|
const commander_1 = require("commander");
|
|
11
11
|
const util_1 = require("util");
|
|
12
12
|
const execPromise = (0, util_1.promisify)(child_process_1.exec);
|
|
13
|
+
const writeFilePromise = (0, util_1.promisify)(fs_1.default.writeFile);
|
|
14
|
+
const parseFile = async (templateFile) => {
|
|
15
|
+
const { stdout } = await execPromise(`npx ts-node ${templateFile}`);
|
|
16
|
+
await writeFilePromise(path_1.default.join(process.cwd(), ".github", "workflows", templateFile.split("/").at(-1).replace(".ts", ".yml")), stdout);
|
|
17
|
+
};
|
|
13
18
|
const cli = new commander_1.Command();
|
|
14
19
|
cli.version("0.0.1").description("TODO");
|
|
15
20
|
cli
|
|
16
21
|
.command("build")
|
|
17
22
|
.description("TODO")
|
|
18
|
-
.
|
|
23
|
+
.argument("[file]", "TODO")
|
|
24
|
+
.action(async (file) => {
|
|
19
25
|
const folder = path_1.default.join(process.cwd(), ".github", "templates");
|
|
20
26
|
if (!fs_1.default.existsSync(path_1.default.join(folder, "..", "workflows"))) {
|
|
21
27
|
fs_1.default.mkdirSync(path_1.default.join(folder, "..", "workflows"));
|
|
22
28
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
if (file !== undefined) {
|
|
30
|
+
await parseFile(file);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
await Promise.all(fs_1.default.readdirSync(folder).map(async (templateFile) => {
|
|
34
|
+
if (!templateFile.match(/^shared$/)) {
|
|
35
|
+
await parseFile(`${path_1.default.join(folder, templateFile)}`);
|
|
36
|
+
}
|
|
37
|
+
}));
|
|
28
38
|
}
|
|
29
39
|
process.exit(0);
|
|
30
40
|
});
|
package/dist/event.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare type EventName = "push" | "pull_request" | "pull_request_review" | "workflow_run" | "workflow_dispatch" | "schedule";
|
|
1
|
+
export declare type EventName = "push" | "pull_request" | "pull_request_review" | "workflow_run" | "workflow_dispatch" | "schedule" | "pull_request_target";
|
|
2
2
|
export declare 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 : never;
|
|
3
3
|
interface PushEventOptions {
|
|
4
4
|
branches?: string[];
|
package/dist/job.d.ts
CHANGED
package/dist/workflow.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Workflow = void 0;
|
|
7
|
-
const
|
|
7
|
+
const js_yaml_1 = require("js-yaml");
|
|
8
8
|
const kebabCase_1 = __importDefault(require("lodash/kebabCase"));
|
|
9
9
|
const DEFAULT_RUNNERS = ["ubuntu-22.04"];
|
|
10
10
|
class Workflow {
|
|
@@ -53,10 +53,11 @@ class Workflow {
|
|
|
53
53
|
env: this.env.length > 0
|
|
54
54
|
? Object.fromEntries(this.env.map(({ name, value }) => [name, value]))
|
|
55
55
|
: undefined,
|
|
56
|
-
jobs: Object.fromEntries(this.jobs.map(({ name, options: { prettyName, ifExpression, runsOn, matrix, env, steps, dependsOn, services, timeout, concurrency, outputs, }, }) => [
|
|
56
|
+
jobs: Object.fromEntries(this.jobs.map(({ name, options: { prettyName, permissions, ifExpression, runsOn, matrix, env, steps, dependsOn, services, timeout, concurrency, outputs, }, }) => [
|
|
57
57
|
name,
|
|
58
58
|
{
|
|
59
59
|
name: prettyName,
|
|
60
|
+
permissions,
|
|
60
61
|
if: ifExpression,
|
|
61
62
|
"runs-on": this.assignRunner(runsOn),
|
|
62
63
|
"timeout-minutes": timeout ?? 15,
|
|
@@ -90,10 +91,10 @@ class Workflow {
|
|
|
90
91
|
},
|
|
91
92
|
])),
|
|
92
93
|
};
|
|
93
|
-
const compiled = `# Template automatically generated by gat\n# DO NOT CHANGE THIS FILE MANUALLY\n\n${(0,
|
|
94
|
-
|
|
95
|
-
aliasDuplicateObjects: false,
|
|
94
|
+
const compiled = `# Template automatically generated by gat\n# DO NOT CHANGE THIS FILE MANUALLY\n\n${(0, js_yaml_1.dump)(result, {
|
|
95
|
+
noRefs: true,
|
|
96
96
|
lineWidth: 150,
|
|
97
|
+
noCompatMode: true,
|
|
97
98
|
})}`;
|
|
98
99
|
console.log(compiled);
|
|
99
100
|
return compiled;
|
package/dist/workflow.spec.js
CHANGED
|
@@ -200,4 +200,32 @@ const workflow_1 = require("./workflow");
|
|
|
200
200
|
});
|
|
201
201
|
(0, vitest_1.expect)(workflow.compile()).toMatchSnapshot();
|
|
202
202
|
});
|
|
203
|
+
(0, vitest_1.it)("allows permissions into jobs", () => {
|
|
204
|
+
const workflow = new workflow_1.Workflow("Job with permissions")
|
|
205
|
+
.on("push")
|
|
206
|
+
.addJob("job1", {
|
|
207
|
+
permissions: {
|
|
208
|
+
contents: "read",
|
|
209
|
+
"pull-requests": "write",
|
|
210
|
+
},
|
|
211
|
+
steps: [{ name: "Do something", run: "exit 0" }],
|
|
212
|
+
});
|
|
213
|
+
(0, vitest_1.expect)(workflow.compile()).toMatchSnapshot();
|
|
214
|
+
});
|
|
215
|
+
(0, vitest_1.it)("allows multiline strings", () => {
|
|
216
|
+
const workflow = new workflow_1.Workflow("Multiline strings")
|
|
217
|
+
.on("push")
|
|
218
|
+
.addJob("job1", {
|
|
219
|
+
steps: [
|
|
220
|
+
{
|
|
221
|
+
name: "Do something",
|
|
222
|
+
run: `
|
|
223
|
+
echo foo
|
|
224
|
+
exit 0
|
|
225
|
+
`,
|
|
226
|
+
},
|
|
227
|
+
],
|
|
228
|
+
});
|
|
229
|
+
(0, vitest_1.expect)(workflow.compile()).toMatchSnapshot();
|
|
230
|
+
});
|
|
203
231
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@factorialco/gat",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"description": "TODO",
|
|
5
5
|
"bin": {
|
|
6
6
|
"gat": "dist/cli.js"
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"author": "David Morcillo <david.morcillo@factorial.co>",
|
|
24
24
|
"license": "ISC",
|
|
25
25
|
"devDependencies": {
|
|
26
|
+
"@types/js-yaml": "^4.0.5",
|
|
26
27
|
"@types/lodash": "^4.14.184",
|
|
27
28
|
"@typescript-eslint/eslint-plugin": "^5.35.1",
|
|
28
29
|
"@typescript-eslint/parser": "^5.35.1",
|
|
@@ -34,8 +35,8 @@
|
|
|
34
35
|
"vitest": "^0.18.1"
|
|
35
36
|
},
|
|
36
37
|
"dependencies": {
|
|
37
|
-
"
|
|
38
|
-
"
|
|
38
|
+
"js-yaml": "^4.1.0",
|
|
39
|
+
"lodash": "^4.17.21"
|
|
39
40
|
},
|
|
40
41
|
"repository": {
|
|
41
42
|
"type": "git",
|