Skip to content

Commit

Permalink
Merge pull request #67 from joscha/joscha/feat-priority
Browse files Browse the repository at this point in the history
  • Loading branch information
joscha authored Jun 29, 2021
2 parents 6b54486 + bb935a6 commit 48cf002
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 0 deletions.
82 changes: 82 additions & 0 deletions src/__tests__/__snapshots__/command.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,88 @@ exports[`buildkite-graph Steps Command plugins add plugins yaml_depends_on 1`] =
"
`;
exports[`buildkite-graph Steps Command priority default dot 1`] = `
"digraph \\"whatever\\" {
graph [ compound =true ];
subgraph cluster_0 {
graph [ color = \\"black\\" ];
\\"<noopImportant>\\" [ color = \\"grey\\" ];
\\"<noop>\\" [ color = \\"grey\\" ];
\\"<noopUnimportant>\\" [ color = \\"grey\\" ];
}
}
"
`;
exports[`buildkite-graph Steps Command priority default json 1`] = `
Object {
"steps": Array [
Object {
"command": "noopImportant",
"priority": 100,
},
Object {
"command": "noop",
},
Object {
"command": "noopUnimportant",
"priority": -100,
},
],
}
`;
exports[`buildkite-graph Steps Command priority default json_depends_on 1`] = `
Object {
"steps": Array [
Object {
"command": "noopImportant",
"key": "_0",
"priority": 100,
},
Object {
"command": "noop",
"key": "_1",
},
Object {
"command": "noopUnimportant",
"key": "_2",
"priority": -100,
},
],
}
`;
exports[`buildkite-graph Steps Command priority default structure 1`] = `
"* <noopImportant>
* <noop>
* <noopUnimportant>"
`;
exports[`buildkite-graph Steps Command priority default yaml 1`] = `
"steps:
- command: noopImportant
priority: 100
- command: noop
- command: noopUnimportant
priority: -100
"
`;
exports[`buildkite-graph Steps Command priority default yaml_depends_on 1`] = `
"steps:
- key: _0
command: noopImportant
priority: 100
- key: _1
command: noop
- key: _2
command: noopUnimportant
priority: -100
"
`;
exports[`buildkite-graph Steps Command retry dot 1`] = `
"digraph \\"whatever\\" {
graph [ compound =true ];
Expand Down
19 changes: 19 additions & 0 deletions src/__tests__/command.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,25 @@ describe('buildkite-graph', () => {
);
});

describe('priority', () => {
createTest('default', () => [
new Pipeline('whatever').add(
new CommandStep('noopImportant').withPriority(100),
new CommandStep('noop').withPriority(0),
new CommandStep('noopUnimportant').withPriority(-100),
),
]);

it('throws if not an integer', () => {
expect(() =>
new CommandStep('noop').withPriority(Infinity),
).toThrow();
expect(() =>
new CommandStep('noop').withPriority(1.234),
).toThrow();
});
});

describe('skip', () => {
createTest('value', () => [
new Pipeline('whatever').add(
Expand Down
19 changes: 19 additions & 0 deletions src/steps/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ export class CommandStep extends LabeledStep {
}
}
}
private _priority?: number;
get priority(): number | undefined {
if (this._priority === 0) {
return undefined;
}
return this._priority;
}

public readonly plugins: Plugins<this> = new PluginsImpl(this);
private _softFail: Set<ExitStatus> = new Set();
Expand Down Expand Up @@ -175,6 +182,17 @@ export class CommandStep extends LabeledStep {
return this;
}

/**
* See: https://github.com/buildkite/docs/pull/1087
*
* @param priority the relative priority of this command step; defaults to 0
*/
withPriority(priority = 0): this {
ow(priority, ow.number.integer);
this._priority = priority;
return this;
}

withParallelism(parallelism: number): this {
ow(parallelism, ow.number.integer.positive);
this._parallelism = parallelism;
Expand Down Expand Up @@ -248,6 +266,7 @@ export class CommandStep extends LabeledStep {
return {
...(await super.toJson(opts)),
command: Command[transformCommandKey](this.command),
priority: this.priority,
env,
parallelism: this.parallelism,
concurrency: this.concurrency,
Expand Down

0 comments on commit 48cf002

Please sign in to comment.