Skip to content

Commit

Permalink
Accept null as concurrency property
Browse files Browse the repository at this point in the history
This makes sure we are accepting null as well so users can still set a default value
for concurrency groups but also accept null values.
  • Loading branch information
beagleknight committed Jul 9, 2024
1 parent ee88ef5 commit fc63f4d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
17 changes: 17 additions & 0 deletions src/__snapshots__/workflow.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ jobs:
"
`;

exports[`Workflow > allows creating jobs with concurrency set to null 1`] = `
"# Workflow automatically generated by gat
# DO NOT CHANGE THIS FILE MANUALLY
name: Without concurrency
on:
push: null
jobs:
job1:
runs-on: ubuntu-22.04
timeout-minutes: 15
steps:
- name: Do something
run: exit 0
"
`;

exports[`Workflow > allows custom types in a workflow 1`] = `
"# Workflow automatically generated by gat
# DO NOT CHANGE THIS FILE MANUALLY
Expand Down
6 changes: 3 additions & 3 deletions src/job.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export interface ConcurrencyGroup {
export type ConcurrencyGroup = {
groupSuffix: string;
cancelPrevious: boolean;
}
};

export interface Matrix {
elements: Array<{ id: string; options: Array<string | number | boolean> }>;
Expand All @@ -25,7 +25,7 @@ export interface JobOptions<Step, RunnerDefinition, Name> {
dependsOn?: Array<Name>;
services?: Record<string, Service>;
env?: Record<string, string>;
concurrency?: ConcurrencyGroup;
concurrency?: ConcurrencyGroup | null;
matrix?: Matrix | string;
steps: Step[];
outputs?: Record<string, string>;
Expand Down
16 changes: 16 additions & 0 deletions src/workflow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,20 @@ exit 0`,
});
expect(await workflow.compile()).toMatchSnapshot();
});

it("allows creating jobs with concurrency set to null", async () => {
const workflow = new Workflow("Without concurrency")
.on("push")
.addJob("job1", {
concurrency: null,
steps: [
{
name: "Do something",
run: "exit 0",
},
],
});

expect(await workflow.compile()).toMatchSnapshot();
});
});
4 changes: 2 additions & 2 deletions src/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class Workflow<
jobs: Array<Job<JobStep, Runner, JobName>>;
defaultOptions: DefaultOptions | null;
env: EnvVar[];
concurrencyGroup?: ConcurrencyGroup;
concurrencyGroup?: ConcurrencyGroup | null;

constructor(public name: string) {
this.events = [];
Expand Down Expand Up @@ -111,7 +111,7 @@ export class Workflow<
return this;
}

setConcurrencyGroup(concurrencyGroup: ConcurrencyGroup) {
setConcurrencyGroup(concurrencyGroup: ConcurrencyGroup | null) {
this.concurrencyGroup = concurrencyGroup;
return this;
}
Expand Down

0 comments on commit fc63f4d

Please sign in to comment.