From 2709fab5fc5e9abcde69f9159eb7565c8e55e079 Mon Sep 17 00:00:00 2001 From: Thorarinn Sigurdsson Date: Wed, 18 Nov 2020 11:48:52 +0100 Subject: [PATCH] fix(enterprise): add workflowError event This new event is necessary to correctly handle failed workflows when combined with the `when` modifier. Also streamlined the module version included in task outputs in event payloads. --- core/src/commands/run/workflow.ts | 1 + core/src/events.ts | 5 +++++ core/test/unit/src/commands/run/workflow.ts | 2 ++ 3 files changed, 8 insertions(+) diff --git a/core/src/commands/run/workflow.ts b/core/src/commands/run/workflow.ts index 87e2324841..41b4069b0b 100644 --- a/core/src/commands/run/workflow.ts +++ b/core/src/commands/run/workflow.ts @@ -189,6 +189,7 @@ export class RunWorkflowCommand extends Command { if (size(stepErrors) > 0) { printResult({ startedAt, log: outerLog, workflow, success: false }) + garden.events.emit("workflowError", {}) return { result, errors: flatten(Object.values(stepErrors)) } } diff --git a/core/src/events.ts b/core/src/events.ts index 66c2085373..e23544fa92 100644 --- a/core/src/events.ts +++ b/core/src/events.ts @@ -66,6 +66,9 @@ export function toGraphResultEventPayload(result: GraphResult): GraphResultEvent const payload = omit(result, "dependencyResults") if (result.output) { payload.output = omit(result.output, "dependencyResults", "log", "buildLog") + if (result.output.version) { + payload.output.version = result.output.version.versionString || null + } } return payload } @@ -160,6 +163,7 @@ export interface Events extends LoggerEvents { // Workflow events workflowRunning: {} workflowComplete: {} + workflowError: {} workflowStepProcessing: { index: number } @@ -204,6 +208,7 @@ export const eventNames: EventName[] = [ "serviceStatus", "workflowRunning", "workflowComplete", + "workflowError", "workflowStepProcessing", "workflowStepSkipped", "workflowStepError", diff --git a/core/test/unit/src/commands/run/workflow.ts b/core/test/unit/src/commands/run/workflow.ts index 7c17d843ce..c61dc4e9be 100644 --- a/core/test/unit/src/commands/run/workflow.ts +++ b/core/test/unit/src/commands/run/workflow.ts @@ -323,6 +323,7 @@ describe("RunWorkflowCommand", () => { expect(we[2].name).to.eql("workflowStepError") expect(we[2].payload.index).to.eql(0) expect(we[2].payload.durationMsec).to.gte(0) + expect(we[3].name).to.eql("workflowError") }) it("should write a file with string data ahead of the run, before resolving providers", async () => { @@ -713,6 +714,7 @@ function getWorkflowEvents(garden: TestGarden) { const eventNames = [ "workflowRunning", "workflowComplete", + "workflowError", "workflowStepProcessing", "workflowStepSkipped", "workflowStepError",