diff --git a/src/__tests__/__snapshots__/command.spec.ts.snap b/src/__tests__/__snapshots__/command.spec.ts.snap index 951c7f3..1acfc32 100644 --- a/src/__tests__/__snapshots__/command.spec.ts.snap +++ b/src/__tests__/__snapshots__/command.spec.ts.snap @@ -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\\" ]; + \\"\\" [ color = \\"grey\\" ]; + \\"\\" [ color = \\"grey\\" ]; + \\"\\" [ 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`] = ` +"* +* +* " +`; + +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 ]; diff --git a/src/__tests__/command.spec.ts b/src/__tests__/command.spec.ts index cfd0f08..2f94680 100644 --- a/src/__tests__/command.spec.ts +++ b/src/__tests__/command.spec.ts @@ -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( diff --git a/src/steps/command.ts b/src/steps/command.ts index c342082..2fe5474 100644 --- a/src/steps/command.ts +++ b/src/steps/command.ts @@ -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 = new PluginsImpl(this); private _softFail: Set = new Set(); @@ -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; @@ -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,