Skip to content

Commit 845d5c9

Browse files
authored
feat(job): Support concurrency (#36)
1 parent a314e14 commit 845d5c9

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/package/job.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,28 @@ describe("Job", () => {
8484
steps: [{ run: "echo 'Hello, world!'" }],
8585
},
8686
],
87+
[
88+
new Job("test", {
89+
runsOn: "ubuntu-latest",
90+
concurrency: "group-name",
91+
}).run("echo 'Hello, world!'"),
92+
{
93+
"runs-on": "ubuntu-latest",
94+
concurrency: "group-name",
95+
steps: [{ run: "echo 'Hello, world!'" }],
96+
},
97+
],
98+
[
99+
new Job("test", {
100+
runsOn: "ubuntu-latest",
101+
concurrency: { group: "group-name", cancelInProgress: true },
102+
}).run("echo 'Hello, world!'"),
103+
{
104+
"runs-on": "ubuntu-latest",
105+
concurrency: { group: "group-name", "cancel-in-progress": true },
106+
steps: [{ run: "echo 'Hello, world!'" }],
107+
},
108+
],
87109
])("job.toJSON(%j) -> %j", (job, expected) => {
88110
expect(job.toJSON()).toEqual(expected);
89111
});

lib/package/job.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { concurrencyJSON } from "../internal/concurrency";
12
import { permissionsJSON } from "../internal/permissions";
23
import { stepJSON } from "../internal/step";
4+
import { type Concurrency } from "./concurrency";
35
import type { Expression } from "./expression";
46
import { type Permissions } from "./permissions";
57
import { type RunStep, type Step, type UsesStep } from "./step";
@@ -12,7 +14,7 @@ export type JobConfig = {
1214
needs?: string | string[];
1315
if?: string | boolean | number;
1416
// TODO: environment
15-
// TODO: concurrency
17+
concurrency?: Concurrency;
1618
// TODO: outputs
1719
// TODO: env
1820
// TODO: defaults
@@ -81,6 +83,10 @@ export class Job {
8183

8284
...(this._config.if != null && { if: this._config.if }),
8385

86+
...(this._config.concurrency != null && {
87+
concurrency: concurrencyJSON(this._config.concurrency),
88+
}),
89+
8490
steps: this._steps.map((step) => stepJSON(step)),
8591
};
8692
}

0 commit comments

Comments
 (0)