Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
joscha committed Jun 30, 2019
1 parent 74da8d0 commit 9382e21
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 36 deletions.
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
root = true

[*]
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
49 changes: 49 additions & 0 deletions src/__tests__/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,46 @@ Object {
Object {
"command": "web/bin/buildkite/run_web_step.sh build editor",
"label": "Build Editor",
"plugins": undefined,
},
Object {
"command": "web/bin/buildkite/run_web_step.sh test editor",
"label": "Test Editor",
"plugins": undefined,
},
Object {
"continue_on_failure": undefined,
"wait": null,
},
Object {
"label": "Annotate failures",
"plugins": Array [
Object {
"bugcrowd/test-summary#v1.5.0": Object {
"inputs": Array [
Object {
"artifact_path": "web/target/htmllint-*.txt",
"label": ":htmllint: HTML lint",
"type": "oneline",
},
],
},
},
Object {
"detect-clowns#v1.0.0": null,
},
],
},
Object {
"command": "web/bin/buildkite/run_web_step.sh deploy-report coverage editor",
"label": "Upload coverage",
"plugins": undefined,
},
Object {
"command": "web/bin/buildkite/run_web_step.sh run-integration-tests local editor chrome",
"label": "Integration tests",
"parallelism": 8,
"plugins": undefined,
},
Object {
"continue_on_failure": undefined,
Expand All @@ -29,10 +56,12 @@ Object {
"command": "web/bin/buildkite/run_web_step.sh run-integration-tests saucelabs editor safari",
"label": ":saucelabs: Integration tests",
"parallelism": 8,
"plugins": undefined,
},
Object {
"command": "web/bin/buildkite/run_web_step.sh run-visual-regression editor",
"label": "Visreg baseline update",
"plugins": undefined,
},
Object {
"continue_on_failure": undefined,
Expand All @@ -41,6 +70,7 @@ Object {
Object {
"command": "web/bin/buildkite/run_web_step.sh copy-to-deploy-bucket editor",
"label": "Copy to deploy bucket",
"plugins": undefined,
},
Object {
"continue_on_failure": undefined,
Expand All @@ -49,6 +79,7 @@ Object {
Object {
"command": "production/test/jobs/advance_branch.sh \\"checkpoint/web/green/editor\\"",
"label": "Update checkpoint",
"plugins": undefined,
},
Object {
"build": Object {
Expand Down Expand Up @@ -82,6 +113,7 @@ Object {
Object {
"command": "buildkite/deploy_web.sh",
"label": "Deploy",
"plugins": undefined,
},
],
}
Expand All @@ -95,6 +127,16 @@ steps:
- label: Test Editor
command: web/bin/buildkite/run_web_step.sh test editor
- wait: ~
- label: Annotate failures
plugins:
- 'bugcrowd/test-summary#v1.5.0':
inputs:
- label: ':htmllint: HTML lint'
artifact_path: web/target/htmllint-*.txt
type: oneline
- 'detect-clowns#v1.0.0': ~
- label: Upload coverage
command: web/bin/buildkite/run_web_step.sh deploy-report coverage editor
- label: Integration tests
command: >-
web/bin/buildkite/run_web_step.sh run-integration-tests local editor
Expand Down Expand Up @@ -148,6 +190,8 @@ subgraph cluster_0 {
subgraph cluster_1 {
graph [ color = \\"black\\" ];
\\"Annotate failures\\" [ color = \\"grey\\" ];
\\"Upload coverage\\" [ color = \\"grey\\" ];
\\"Integration tests\\" [ color = \\"grey\\" ];
}
Expand All @@ -169,6 +213,9 @@ subgraph cluster_4 {
\\"Deploy to usertesting\\" [ color = \\"grey\\" ];
}
\\"Test Editor\\";
\\"Annotate failures\\";
\\"Upload coverage\\";
\\"Build Editor\\";
\\"Integration tests\\";
\\":saucelabs: Integration tests\\";
Expand All @@ -178,6 +225,8 @@ subgraph cluster_4 {
\\"Deploy to tech\\";
\\"web-deploy\\" [ shape =Msquare ];
\\"Deploy to usertesting\\";
\\"Test Editor\\" -> \\"Annotate failures\\" [ ltail = \\"cluster_0\\", lhead = \\"cluster_1\\" ];
\\"Test Editor\\" -> \\"Upload coverage\\" [ ltail = \\"cluster_0\\", lhead = \\"cluster_1\\" ];
\\"Build Editor\\" -> \\"Integration tests\\" [ ltail = \\"cluster_0\\", lhead = \\"cluster_1\\" ];
\\"Integration tests\\" -> \\":saucelabs: Integration tests\\" [ ltail = \\"cluster_1\\", lhead = \\"cluster_2\\" ];
\\"Integration tests\\" -> \\"Visreg baseline update\\" [ ltail = \\"cluster_1\\", lhead = \\"cluster_2\\" ];
Expand Down
38 changes: 27 additions & 11 deletions src/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Entity, Step, TriggerStep } from '../';
import { Entity, Step, TriggerStep, Plugin } from '../';
import { JsonSerializer } from '../serializers/json';
import { YamlSerializer } from '../serializers/yaml';
import { DotSerializer } from '../serializers/dot';
Expand All @@ -21,13 +21,29 @@ describe('buildkite-graph', () => {
'web/bin/buildkite/run_web_step.sh test editor',
'Test Editor',
);
/*
const annotateFailuresStep = new AlwaysExecutedStep('annotate failures')
.dependsOn(testEditorStep);
const deployCoverageReportStep = new AlwaysExecutedStep('web/bin/buildkite/run_web_step.sh deploy-report coverage editor')
.dependsOn(testEditorStep);
*/

const annotateFailuresStep = new Step(
new Plugin('bugcrowd/test-summary#v1.5.0', {
inputs: [
{
label: ':htmllint: HTML lint',
artifact_path: 'web/target/htmllint-*.txt',
type: 'oneline',
},
],
}),

'Annotate failures',
).plugins
.add(new Plugin('detect-clowns#v1.0.0'))
.alwaysExecute()
.dependsOn(testEditorStep);

const deployCoverageReportStep = new Step(
'web/bin/buildkite/run_web_step.sh deploy-report coverage editor',
'Upload coverage',
).dependsOn(testEditorStep);

const integrationTestStep = new Step(
'web/bin/buildkite/run_web_step.sh run-integration-tests local editor chrome',
'Integration tests',
Expand All @@ -49,7 +65,7 @@ describe('buildkite-graph', () => {
'Visreg baseline update',
).dependsOn(integrationTestStep);

/*
/*
const annotateCucumberFailuresStep = new AlwaysExecutedStep('web/bin/buildkite/run_web_step.sh annotate-cucumber-failed-cases')
.dependsOn(integrationTestStep)
.dependsOn(saucelabsIntegrationTestStep);
Expand Down Expand Up @@ -88,8 +104,8 @@ describe('buildkite-graph', () => {
const webBuildEditor = new Entity('web-build-editor')
.add(buildEditorStep)
.add(testEditorStep)
// .add(annotateFailuresStep)
// .add(deployCoverageReportStep)
.add(annotateFailuresStep)
.add(deployCoverageReportStep)
.add(integrationTestStep)
.add(saucelabsIntegrationTestStep)
.add(visregBaselineUpdateStep)
Expand Down
88 changes: 63 additions & 25 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,22 @@ abstract class DefaultStep implements BaseStep {
this.dependencies.add(step);
return this;
}

@Exclude()
public always: boolean = false;

alwaysExecute() {
this.always = true;
return this;
}
}

type Wait = {
wait: null;
continue_on_failure?: true;
};
@Exclude()
abstract class Chainable<T> {
constructor(protected readonly parent: T) {
this.parent = parent;
}
}

class WaitStep implements BaseStep {
// TODO: Omit this when not true once
Expand All @@ -45,20 +55,51 @@ class WaitStep implements BaseStep {
}
}

type Default = {
label?: string;
command: string | string[];
parallelism?: number;
};
interface Plugins<T> {
add(plugin: Plugin): T;
}

function transformPlugins(value: PluginsImpl<any>) {
if (!value.plugins.length) {
return undefined;
}

return value.plugins.map(plugin => {
return {
[plugin.pluginNameOrPath]: plugin.configuration || null,
};
});
}

@Exclude()
class PluginsImpl<T> extends Chainable<T> implements Plugins<T> {
public plugins: Plugin[] = [];

add(plugin: Plugin) {
this.plugins.push(plugin);
return this.parent;
}
}

export class Step extends DefaultStep {
public parallelism?: number;

public readonly command: string | string[];
public readonly command?: string | string[];

@Transform(transformPlugins)
public readonly plugins: Plugins<this> = new PluginsImpl(this);

constructor(command: string | string[], public readonly label?: string) {
constructor(plugin: Plugin, label?: string);
constructor(command: string, label?: string);
constructor(commands: string[], label?: string);
constructor(
command: string | string[] | Plugin,
public readonly label?: string,
) {
super();
if (typeof command === 'string') {
if (command instanceof Plugin) {
this.plugins.add(command);
} else if (typeof command === 'string') {
ow(command, ow.string.not.empty);
this.command = command;
} else {
Expand All @@ -79,11 +120,6 @@ export class Step extends DefaultStep {
}
}

type Trigger = {
trigger: string;
build?: Build;
};

class Build {
public readonly env: Env<TriggerStep>;
constructor(triggerStep: TriggerStep) {
Expand Down Expand Up @@ -122,17 +158,10 @@ interface Env<T> {
}

@Exclude()
class EnvImpl<T> implements Env<T> {
@Exclude()
private readonly parent: T;

class EnvImpl<T> extends Chainable<T> implements Env<T> {
@Expose({ name: 'env' })
public readonly vars: Map<string, Primitive> = new Map();

constructor(parent: T) {
this.parent = parent;
}

set(name: string, value: Primitive): T {
this.vars.set(name, value);
return this.parent;
Expand Down Expand Up @@ -208,3 +237,12 @@ export function stortedWithBlocks(e: Entity) {
}
return allSteps;
}

export class Plugin {
constructor(
public readonly pluginNameOrPath: string,
public readonly configuration?: object,
) {
ow(pluginNameOrPath, ow.string.not.empty);
}
}

0 comments on commit 9382e21

Please sign in to comment.