Skip to content

Commit e9d2eeb

Browse files
authored
feat(job): Support services (#50)
1 parent e8700af commit e9d2eeb

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

lib/package/job.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,34 @@ describe("Job", () => {
185185
steps: [{ run: "echo 'Hello, world!'" }],
186186
},
187187
],
188+
[
189+
new Job("with-services", {
190+
runsOn: "ubuntu-latest",
191+
services: { redis: { image: "redis:latest" } },
192+
}).run("echo 'Hello, world!'"),
193+
{
194+
"runs-on": "ubuntu-latest",
195+
services: { redis: { image: "redis:latest" } },
196+
steps: [{ run: "echo 'Hello, world!'" }],
197+
},
198+
],
199+
[
200+
new Job("with-services", {
201+
runsOn: "ubuntu-latest",
202+
services: {
203+
redis: { image: "redis:latest" },
204+
postgres: { image: "postgres:latest" },
205+
},
206+
}).run("echo 'Hello, world!'"),
207+
{
208+
"runs-on": "ubuntu-latest",
209+
services: {
210+
redis: { image: "redis:latest" },
211+
postgres: { image: "postgres:latest" },
212+
},
213+
steps: [{ run: "echo 'Hello, world!'" }],
214+
},
215+
],
188216
])("job.toJSON(%j) -> %j", (job, expected) => {
189217
expect(job.toJSON()).toEqual(expected);
190218
});

lib/package/job.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export type JobConfig = {
3030
strategy?: Strategy;
3131
continueOnError?: boolean | Expression;
3232
container?: Container;
33-
// TODO: services
33+
services?: Record<string, Container>;
3434
// TODO: uses
3535
// TODO: with
3636
// TODO: secrets
@@ -118,6 +118,15 @@ export class Job {
118118
container: containerJSON(this._config.container),
119119
}),
120120

121+
...(this._config.services != null && {
122+
services: Object.fromEntries(
123+
Object.entries(this._config.services).map(([name, service]) => [
124+
name,
125+
containerJSON(service),
126+
]),
127+
),
128+
}),
129+
121130
steps: this._steps.map((step) => stepJSON(step)),
122131
};
123132
}

0 commit comments

Comments
 (0)