diff --git a/src/__snapshots__/workflow.spec.ts.snap b/src/__snapshots__/workflow.spec.ts.snap index a28914e..b94468f 100644 --- a/src/__snapshots__/workflow.spec.ts.snap +++ b/src/__snapshots__/workflow.spec.ts.snap @@ -28,6 +28,30 @@ jobs: " `; +exports[`Workflow > allows a job matrix with max-parallel 1`] = ` +"# Workflow automatically generated by gat +# DO NOT CHANGE THIS FILE MANUALLY + +name: Matrix with max parallel +on: + push: null +jobs: + job1: + runs-on: ubuntu-22.04 + timeout-minutes: 15 + strategy: + fail-fast: false + max-parallel: 2 + matrix: + food: + - 🍕 + - 🍔 + - 🌮 + steps: + - run: echo \${{ matrix.food }} +" +`; + exports[`Workflow > allows concurrency groups at workflow level 1`] = ` "# Workflow automatically generated by gat # DO NOT CHANGE THIS FILE MANUALLY diff --git a/src/job.ts b/src/job.ts index 9655f18..6091b61 100644 --- a/src/job.ts +++ b/src/job.ts @@ -6,6 +6,7 @@ export type ConcurrencyGroup = { export interface Matrix { elements: Array<{ id: string; options: Array }>; extra?: Array>; + maxParallel?: number; } export interface Service { diff --git a/src/workflow.spec.ts b/src/workflow.spec.ts index 9d6ac5c..db6efd2 100644 --- a/src/workflow.spec.ts +++ b/src/workflow.spec.ts @@ -135,6 +135,27 @@ describe("Workflow", () => { expect(await workflow.compile()).toMatchSnapshot(); }); + it("allows a job matrix with max-parallel", async () => { + const workflow = new Workflow("Matrix with max parallel"); + workflow.on("push").addJob("job1", { + matrix: { + elements: [ + { + id: "food", + options: ["🍕", "🍔", "🌮"], + }, + ], + maxParallel: 2, + }, + steps: [ + { + run: "echo ${{ matrix.food }}", + }, + ], + }); + expect(await workflow.compile()).toMatchSnapshot(); + }); + it("allows uses steps", async () => { const workflow = new Workflow("Uses steps"); workflow diff --git a/src/workflow.ts b/src/workflow.ts index 052faf2..1d58b88 100644 --- a/src/workflow.ts +++ b/src/workflow.ts @@ -182,6 +182,10 @@ export class Workflow< strategy: matrix ? { "fail-fast": false, + "max-parallel": + typeof matrix !== "string" && matrix.maxParallel != null + ? matrix.maxParallel + : undefined, matrix: typeof matrix === "string" ? matrix