Skip to content

Commit

Permalink
feat: 🎸 allow passing multiple dependencies to .dependsOn
Browse files Browse the repository at this point in the history
Closes: #7
  • Loading branch information
joscha committed Sep 24, 2019
1 parent 90e53d9 commit 96ba630
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 4 deletions.
58 changes: 58 additions & 0 deletions src/__tests__/__snapshots__/command.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,32 @@ subgraph cluster_1 {
"
`;

exports[`buildkite-graph Steps dependencies step dependency dot 2`] = `
"digraph \\"whatever\\" {
graph [ compound =true ];
subgraph cluster_0 {
graph [ color = \\"black\\" ];
\\"<a>\\" [ color = \\"grey\\" ];
\\"<b>\\" [ color = \\"grey\\" ];
\\"<c>\\" [ color = \\"grey\\" ];
}
subgraph cluster_1 {
graph [ color = \\"black\\" ];
\\"<d>\\" [ color = \\"grey\\" ];
}
\\"<c>\\";
\\"<d>\\";
\\"<b>\\";
\\"<a>\\";
\\"<c>\\" -> \\"<d>\\" [ ltail = \\"cluster_0\\", lhead = \\"cluster_1\\" ];
\\"<b>\\" -> \\"<d>\\" [ ltail = \\"cluster_0\\", lhead = \\"cluster_1\\" ];
\\"<a>\\" -> \\"<d>\\" [ ltail = \\"cluster_0\\", lhead = \\"cluster_1\\" ];
}
"
`;

exports[`buildkite-graph Steps dependencies step dependency json 1`] = `
Object {
"steps": Array [
Expand All @@ -1259,10 +1285,42 @@ Object {
}
`;

exports[`buildkite-graph Steps dependencies step dependency json 2`] = `
Object {
"steps": Array [
Object {
"command": "a",
},
Object {
"command": "b",
},
Object {
"command": "c",
},
Object {
"wait": null,
},
Object {
"command": "d",
},
],
}
`;

exports[`buildkite-graph Steps dependencies step dependency yaml 1`] = `
"steps:
- command: a
- wait: ~
- command: b
"
`;

exports[`buildkite-graph Steps dependencies step dependency yaml 2`] = `
"steps:
- command: a
- command: b
- command: c
- wait: ~
- command: d
"
`;
11 changes: 9 additions & 2 deletions src/__tests__/command.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ import { createTest } from './helpers';
describe('buildkite-graph', () => {
describe('Steps', () => {
describe('dependencies', () => {
createTest('step dependency', () =>
createTest('step dependency', () => [
new Pipeline('whatever').add(
new CommandStep('b').dependsOn(new CommandStep('a')),
),
);
new Pipeline('whatever').add(
new CommandStep('d').dependsOn(
new CommandStep('a'),
new CommandStep('b'),
new CommandStep('c'),
),
),
]);
createTest('can depend on itself to produce wait', () => {
const c = new CommandStep('c');
return new Pipeline('whatever').add(
Expand Down
10 changes: 8 additions & 2 deletions src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ export abstract class Step implements BaseStep {
@Exclude()
public readonly dependencies: Set<Step> = new Set();

dependsOn(step: Step): this {
this.dependencies.add(step);
dependsOn(...steps: Step[]): this {
ow(steps, ow.array.ofType(ow.object.nonEmpty));
// iterate in reverse so if dependencies are not added to the graph, yet
// they will be added in the order they are given as dependencies
for (let i = steps.length; i > 0; i--) {
const step = steps[i - 1];
this.dependencies.add(step);
}
return this;
}

Expand Down

0 comments on commit 96ba630

Please sign in to comment.