Skip to content

Commit c8df6e3

Browse files
authored
fix(job): Fix runsOn type (#52)
* chore: Implement runsOnJSON * fix(job): Fix runsOn type
1 parent 2135308 commit c8df6e3

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

lib/internal/runs-on.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { describe, expect, test } from "bun:test";
2+
import type { RunsOn } from "../package/runs-on";
3+
import { runsOnJSON } from "./runs-on";
4+
5+
describe("runsOnJSON", () => {
6+
test.each<[RunsOn, ReturnType<typeof runsOnJSON>]>([
7+
["ubuntu-latest", "ubuntu-latest"],
8+
[
9+
["ubuntu-latest", "macos-latest"],
10+
["ubuntu-latest", "macos-latest"],
11+
],
12+
[{ group: "group" }, { group: "group" }],
13+
[
14+
{ group: "group", labels: ["label1", "label2"] },
15+
{ group: "group", labels: ["label1", "label2"] },
16+
],
17+
])("runsOnJSON(%j) -> %j", (runsOn, expected) => {
18+
expect(runsOnJSON(runsOn)).toEqual(expected);
19+
});
20+
});

lib/internal/runs-on.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { RunsOn } from "../package/runs-on";
2+
3+
export function runsOnJSON(
4+
runsOn: RunsOn,
5+
): string | string[] | Record<string, unknown> {
6+
if (typeof runsOn === "string") return runsOn;
7+
if (Array.isArray(runsOn)) return runsOn;
8+
9+
return {
10+
group: runsOn.group,
11+
...(runsOn.labels != null && { labels: runsOn.labels }),
12+
};
13+
}

lib/package/job.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type { Env } from "./env";
1313
import type { Environment } from "./environment";
1414
import type { Expression } from "./expression";
1515
import { type Permissions } from "./permissions";
16+
import type { RunsOn } from "./runs-on";
1617
import { type RunStep, type Step, type UsesStep } from "./step";
1718
import type { Strategy } from "./strategy";
1819

@@ -26,7 +27,7 @@ type JobConfigBase = {
2627
};
2728

2829
export type NormalJobConfig = JobConfigBase & {
29-
runsOn: string; // TODO: fix
30+
runsOn: RunsOn;
3031
environment?: Environment;
3132
outputs?: Record<string, string>;
3233
env?: Env;

lib/package/runs-on.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export type RunsOn =
2+
| string
3+
| string[]
4+
| {
5+
group: string;
6+
labels?: string | string[];
7+
};

0 commit comments

Comments
 (0)