Skip to content

Commit 9008af5

Browse files
committed
chore: Refactor workflows
1 parent aa60708 commit 9008af5

File tree

4 files changed

+55
-64
lines changed

4 files changed

+55
-64
lines changed

.github/workflows/_helpers.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { action, Job, JobConfig } from "ghats";
2+
3+
export type SetupJobConfig = Omit<JobConfig, "runsOn"> & {
4+
withoutCheckout?: boolean;
5+
withBun?: boolean;
6+
};
7+
8+
export function setupJob(id: string, config: SetupJobConfig): Job {
9+
const job = new Job(id, { runsOn: "ubuntu-latest", ...config });
10+
11+
if (!config.withoutCheckout) {
12+
job.uses(
13+
action("actions/checkout", { with: { "persist-credentials": "false" } }),
14+
);
15+
}
16+
17+
if (config.withBun) {
18+
job.uses(action("jdx/mise-action")).run("bun install --frozen-lockfile");
19+
}
20+
21+
return job;
22+
}

.github/workflows/ci.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
1-
import { action, Job, Workflow } from "ghats";
1+
import { Workflow } from "ghats";
2+
import { setupJob } from "./_helpers";
23

34
const workflow = new Workflow("CI", {
45
on: "push",
56
permissions: {},
67
});
78

89
workflow.addJob(
9-
new Job("test", {
10-
runsOn: "ubuntu-latest",
10+
setupJob("test", {
1111
permissions: { contents: "read" },
1212
timeoutMinutes: 5,
13-
})
14-
.uses(
15-
action("actions/checkout", { with: { "persist-credentials": "false" } }),
16-
)
17-
.uses(action("jdx/mise-action"))
18-
.run("bun install --frozen-lockfile")
19-
.run("bun test"),
13+
withBun: true,
14+
}).run("bun test"),
2015
);
2116

2217
export default workflow;
Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { action, Job, Workflow } from "ghats";
1+
import { action, Workflow } from "ghats";
2+
import { setupJob } from "./_helpers";
23

34
const workflow = new Workflow("GitHub Actions Lint", {
45
permissions: {},
@@ -18,58 +19,35 @@ const workflow = new Workflow("GitHub Actions Lint", {
1819
});
1920

2021
workflow.addJob(
21-
new Job("actionlint", {
22-
runsOn: "ubuntu-latest",
23-
permissions: {
24-
contents: "read",
25-
},
22+
setupJob("actionlint", {
23+
permissions: { contents: "read" },
2624
timeoutMinutes: 5,
27-
})
28-
.uses(
29-
action("actions/checkout", { with: { "persist-credentials": "false" } }),
30-
)
31-
.uses(action("koki-develop/github-actions-lint/actionlint")),
25+
}).uses(action("koki-develop/github-actions-lint/actionlint")),
3226
);
3327

3428
workflow.addJob(
35-
new Job("ghalint", {
36-
runsOn: "ubuntu-latest",
37-
permissions: {
38-
contents: "read",
39-
},
29+
setupJob("ghalint", {
30+
permissions: { contents: "read" },
4031
timeoutMinutes: 5,
41-
})
42-
.uses(
43-
action("actions/checkout", { with: { "persist-credentials": "false" } }),
44-
)
45-
.uses(
46-
action("koki-develop/github-actions-lint/ghalint", {
47-
with: {
48-
"action-path": "./.github/actions/**/action.yml",
49-
},
50-
}),
51-
),
32+
}).uses(
33+
action("koki-develop/github-actions-lint/ghalint", {
34+
with: { "action-path": "./.github/actions/**/action.yml" },
35+
}),
36+
),
5237
);
5338

5439
workflow.addJob(
55-
new Job("zizmor", {
56-
runsOn: "ubuntu-latest",
57-
permissions: {
58-
contents: "read",
59-
},
40+
setupJob("zizmor", {
41+
permissions: { contents: "read" },
6042
timeoutMinutes: 5,
61-
})
62-
.uses(
63-
action("actions/checkout", { with: { "persist-credentials": "false" } }),
64-
)
65-
.uses(
66-
action("koki-develop/github-actions-lint/zizmor", {
67-
with: {
68-
"github-token": "${{ github.token }}",
69-
persona: "auditor",
70-
},
71-
}),
72-
),
43+
}).uses(
44+
action("koki-develop/github-actions-lint/zizmor", {
45+
with: {
46+
"github-token": "${{ github.token }}",
47+
persona: "auditor",
48+
},
49+
}),
50+
),
7351
);
7452

7553
export default workflow;

.github/workflows/release-please.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { action, Job, Workflow } from "ghats";
1+
import { action, Workflow } from "ghats";
2+
import { setupJob } from "./_helpers";
23

34
const workflow = new Workflow("Release Please", {
45
permissions: {},
@@ -11,8 +12,8 @@ const workflow = new Workflow("Release Please", {
1112
},
1213
});
1314

14-
const releasePleaseJob = new Job("releasePlease", {
15-
runsOn: "ubuntu-latest",
15+
const releasePleaseJob = setupJob("releasePlease", {
16+
withoutCheckout: true,
1617
timeoutMinutes: 10,
1718
permissions: {
1819
contents: "write",
@@ -28,20 +29,15 @@ const releasePleaseJob = new Job("releasePlease", {
2829
}),
2930
);
3031

31-
const releaseJob = new Job("release", {
32-
runsOn: "ubuntu-latest",
32+
const releaseJob = setupJob("release", {
33+
withBun: true,
3334
timeoutMinutes: 10,
3435
needs: releasePleaseJob.id,
3536
if: `\${{ needs.${releasePleaseJob.id}.outputs.shouldRelease }}`,
3637
permissions: {
3738
contents: "read",
3839
},
3940
})
40-
.uses(
41-
action("actions/checkout", { with: { "persist-credentials": "false" } }),
42-
)
43-
.uses(action("jdx/mise-action"))
44-
.run("bun install --frozen-lockfile")
4541
.run("bun run build:package")
4642
.run(
4743
`

0 commit comments

Comments
 (0)