Skip to content

Commit

Permalink
style: 2 space indent
Browse files Browse the repository at this point in the history
  • Loading branch information
joscha committed Jun 29, 2021
1 parent acd1afb commit bae2476
Show file tree
Hide file tree
Showing 38 changed files with 2,394 additions and 2,501 deletions.
24 changes: 12 additions & 12 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"extends": ["plugin:@typescript-eslint/recommended", "prettier"],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"rules": {
"@typescript-eslint/explicit-function-return-type": [
"error",
{ "allowExpressions": true }
],
"@typescript-eslint/explicit-member-accessibility": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-parameter-properties": "off"
}
"extends": ["plugin:@typescript-eslint/recommended", "prettier"],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"rules": {
"@typescript-eslint/explicit-function-return-type": [
"error",
{ "allowExpressions": true }
],
"@typescript-eslint/explicit-member-accessibility": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-parameter-properties": "off"
}
}
8 changes: 4 additions & 4 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"trailingComma": "all",
"tabWidth": 4,
"singleQuote": true,
"semi": true
"trailingComma": "all",
"tabWidth": 2,
"singleQuote": true,
"semi": true
}
28 changes: 14 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
language: node_js
node_js:
- 12
- 14
- 16
- 12
- 14
- 16
jobs:
include:
# Define the release stage that runs semantic-release
- stage: release
node_js: lts/*
# Advanced: optionally overwrite your default `script` step to skip the tests
# script: skip
deploy:
provider: script
skip_cleanup: true
script:
- npx semantic-release
include:
# Define the release stage that runs semantic-release
- stage: release
node_js: lts/*
# Advanced: optionally overwrite your default `script` step to skip the tests
# script: skip
deploy:
provider: script
skip_cleanup: true
script:
- npx semantic-release
122 changes: 60 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,33 @@ All standard Buildkite features are supported.

The main advantage of using this module is:

- Easy reuse and recombination of steps
- Defining dependencies between steps explicitly
- Wait steps are not defined explicitly and manually managed but derived from the graph, always providing the most optimized graph
- Steps can be defined conditionally via an acceptor function, allowing for completely dynamic pipelines
- The graph can be serialzed into [dot](https://www.graphviz.org/) format, allowing you to see the whole of the pipeline in one glance. Clusters denote which parts of the graph are dependendent.
- Timeouts can be defined on a per-command basis, the step will then accumulate the timeouts accordingly
- Easy reuse and recombination of steps
- Defining dependencies between steps explicitly
- Wait steps are not defined explicitly and manually managed but derived from the graph, always providing the most optimized graph
- Steps can be defined conditionally via an acceptor function, allowing for completely dynamic pipelines
- The graph can be serialzed into [dot](https://www.graphviz.org/) format, allowing you to see the whole of the pipeline in one glance. Clusters denote which parts of the graph are dependendent.
- Timeouts can be defined on a per-command basis, the step will then accumulate the timeouts accordingly

## Example in a nutshell

```ts
const install = new Command('yarn', 2);

const lint = new CommandStep([install, new Command('yarn lint', 1)]).withKey(
'lint',
'lint',
);
const test = new CommandStep([install, new Command('yarn test', 2)])
.withKey('test')
.dependsOn(lint);
.withKey('test')
.dependsOn(lint);
const build = new CommandStep([install, new Command('yarn build', 5)])
.withKey('build')
.dependsOn(lint);
.withKey('build')
.dependsOn(lint);
const integration = new CommandStep([
install,
new Command('yarn integration', 10),
install,
new Command('yarn integration', 10),
])
.withKey('integration-test')
.dependsOn(build);
.withKey('integration-test')
.dependsOn(build);

const pipeline = new Pipeline('My pipeline').add(test).add(integration);
```
Expand All @@ -44,24 +44,24 @@ will serialize to:

```yaml
steps:
- command:
- yarn
- yarn lint
timeout_in_minutes: 3
- wait: ~
- command:
- yarn
- yarn build
timeout_in_minutes: 7
- command:
- yarn
- yarn test
timeout_in_minutes: 4
- wait: ~
- command:
- yarn
- yarn integration
timeout_in_minutes: 12
- command:
- yarn
- yarn lint
timeout_in_minutes: 3
- wait: ~
- command:
- yarn
- yarn build
timeout_in_minutes: 7
- command:
- yarn
- yarn test
timeout_in_minutes: 4
- wait: ~
- command:
- yarn
- yarn integration
timeout_in_minutes: 12
```
> Did you see how the `wait` step got added for you? How cool is that, hey :)
Expand All @@ -72,41 +72,39 @@ Since version 5 we also support the [new `depends_on` syntax](https://buildkite.

```yaml
steps:
- key: lint
command:
- yarn
- yarn lint
timeout_in_minutes: 3
- key: build
depends_on:
- step: lint
command:
- yarn
- yarn build
timeout_in_minutes: 7
- key: test
depends_on:
- step: lint
command:
- yarn
- yarn test
timeout_in_minutes: 4
- key: integration-test
depends_on:
- step: build
command:
- yarn
- yarn integration
timeout_in_minutes: 12
- key: lint
command:
- yarn
- yarn lint
timeout_in_minutes: 3
- key: build
depends_on:
- step: lint
command:
- yarn
- yarn build
timeout_in_minutes: 7
- key: test
depends_on:
- step: lint
command:
- yarn
- yarn test
timeout_in_minutes: 4
- key: integration-test
depends_on:
- step: build
command:
- yarn
- yarn integration
timeout_in_minutes: 12
```

you can get this format by using a flag on the yaml serializer:

```ts
console.log(
await new YamlSerializer({ explicitDependencies: true }).serialize(
pipeline,
),
await new YamlSerializer({ explicitDependencies: true }).serialize(pipeline),
);
```

Expand Down
32 changes: 16 additions & 16 deletions examples/conditional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,37 @@ import { YamlSerializer } from '../src/serializers/yaml';
* This Conditional will accept when there is at least one changed file ending in .feature
*/
class FeatureFileChangedConditional<T extends Step> extends Conditional<T> {
accept() {
const changedFiles = execSync(
'git --no-pager diff master --name-only --no-renames',
{ encoding: 'utf8' },
).split(EOL);
for (const changedFile of changedFiles) {
if (extname(changedFile) === '.feature') {
return true;
}
}
return false;
accept() {
const changedFiles = execSync(
'git --no-pager diff master --name-only --no-renames',
{ encoding: 'utf8' },
).split(EOL);
for (const changedFile of changedFiles) {
if (extname(changedFile) === '.feature') {
return true;
}
}
return false;
}
}

const install = new Command('yarn', 2);

const lint = new CommandStep([install, new Command('yarn lint', 1)]);

const test = new CommandStep([install, new Command('yarn test', 2)]).dependsOn(
lint,
lint,
);
const build = new CommandStep([install, new Command('yarn build', 5)]);

const integration = new CommandStep([
install,
new Command('yarn integration', 10),
install,
new Command('yarn integration', 10),
]).dependsOn(build);

const pipeline = new Pipeline('My pipeline')
.add(test)
.add(new FeatureFileChangedConditional(integration));
.add(test)
.add(new FeatureFileChangedConditional(integration));

console.log(await new YamlSerializer().serialize(pipeline));

Expand Down
26 changes: 13 additions & 13 deletions examples/retry_command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@ import { Command, CommandStep, Pipeline } from '../src';
import { YamlSerializer } from '../src/serializers/yaml';

class RetryCommand extends Command {
constructor(private retries: number, command: Command) {
super(command.toString(), command.timeout * (retries + 1));
}
constructor(private retries: number, command: Command) {
super(command.toString(), command.timeout * (retries + 1));
}

protected serialize(): string {
return new Array(this.retries + 1).fill(this.command).join(' || ');
}
protected serialize(): string {
return new Array(this.retries + 1).fill(this.command).join(' || ');
}

public toString(): string {
return `${this.command} [retry = ${this.retries}]`;
}
public toString(): string {
return `${this.command} [retry = ${this.retries}]`;
}
}

const install = new Command('yarn');

const test = new CommandStep([
install,
new RetryCommand(1, new Command('yarn test-integration')),
install,
new RetryCommand(1, new Command('yarn test-integration')),
]).withKey('test');

const pipeline = new Pipeline('My pipeline').add(test);

new YamlSerializer({ explicitDependencies: true })
.serialize(pipeline)
.then(console.log);
.serialize(pipeline)
.then(console.log);
41 changes: 20 additions & 21 deletions examples/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,29 @@ import { Command, CommandStep, Pipeline } from '../src';
import { YamlSerializer } from '../src/serializers/yaml';

async function main() {
const install = new Command('yarn', 2);
const install = new Command('yarn', 2);

const lint = new CommandStep([
install,
new Command('yarn lint', 1),
]).withKey('lint');
const test = new CommandStep([install, new Command('yarn test', 2)])
.withKey('test')
.dependsOn(lint);
const build = new CommandStep([install, new Command('yarn build', 5)])
.withKey('build')
.dependsOn(lint);
const integration = new CommandStep([
install,
new Command('yarn integration', 10),
])
.withKey('integration-test')
.dependsOn(build);
const lint = new CommandStep([install, new Command('yarn lint', 1)]).withKey(
'lint',
);
const test = new CommandStep([install, new Command('yarn test', 2)])
.withKey('test')
.dependsOn(lint);
const build = new CommandStep([install, new Command('yarn build', 5)])
.withKey('build')
.dependsOn(lint);
const integration = new CommandStep([
install,
new Command('yarn integration', 10),
])
.withKey('integration-test')
.dependsOn(build);

const pipeline = new Pipeline('My pipeline').add(test).add(integration);
const pipeline = new Pipeline('My pipeline').add(test).add(integration);

console.log(await new YamlSerializer().serialize(pipeline));
// console.log(await new YamlSerializer({ explicitDependencies: true }).serialize(pipeline));
// console.log(await new DotSerializer().serialize(pipeline));
console.log(await new YamlSerializer().serialize(pipeline));
// console.log(await new YamlSerializer({ explicitDependencies: true }).serialize(pipeline));
// console.log(await new DotSerializer().serialize(pipeline));
}

main();
Loading

0 comments on commit bae2476

Please sign in to comment.