From fc63f4dc44ca349052a736008d638d0d8e92319a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Morcillo=20Mu=C3=B1oz?= Date: Tue, 9 Jul 2024 12:22:02 +0200 Subject: [PATCH] Accept null as concurrency property 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. --- src/__snapshots__/workflow.spec.ts.snap | 17 +++++++++++++++++ src/job.ts | 6 +++--- src/workflow.spec.ts | 16 ++++++++++++++++ src/workflow.ts | 4 ++-- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/__snapshots__/workflow.spec.ts.snap b/src/__snapshots__/workflow.spec.ts.snap index 93bcba6..f01d30a 100644 --- a/src/__snapshots__/workflow.spec.ts.snap +++ b/src/__snapshots__/workflow.spec.ts.snap @@ -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 diff --git a/src/job.ts b/src/job.ts index 5141240..da0bc37 100644 --- a/src/job.ts +++ b/src/job.ts @@ -1,7 +1,7 @@ -export interface ConcurrencyGroup { +export type ConcurrencyGroup = { groupSuffix: string; cancelPrevious: boolean; -} +}; export interface Matrix { elements: Array<{ id: string; options: Array }>; @@ -25,7 +25,7 @@ export interface JobOptions { dependsOn?: Array; services?: Record; env?: Record; - concurrency?: ConcurrencyGroup; + concurrency?: ConcurrencyGroup | null; matrix?: Matrix | string; steps: Step[]; outputs?: Record; diff --git a/src/workflow.spec.ts b/src/workflow.spec.ts index d26a52d..a94f047 100644 --- a/src/workflow.spec.ts +++ b/src/workflow.spec.ts @@ -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(); + }); }); diff --git a/src/workflow.ts b/src/workflow.ts index ff8dc32..08ab11d 100644 --- a/src/workflow.ts +++ b/src/workflow.ts @@ -79,7 +79,7 @@ export class Workflow< jobs: Array>; defaultOptions: DefaultOptions | null; env: EnvVar[]; - concurrencyGroup?: ConcurrencyGroup; + concurrencyGroup?: ConcurrencyGroup | null; constructor(public name: string) { this.events = []; @@ -111,7 +111,7 @@ export class Workflow< return this; } - setConcurrencyGroup(concurrencyGroup: ConcurrencyGroup) { + setConcurrencyGroup(concurrencyGroup: ConcurrencyGroup | null) { this.concurrencyGroup = concurrencyGroup; return this; }