From bca3e35e927a0a2cf1278c581ac595a9e517f3f9 Mon Sep 17 00:00:00 2001 From: Ming-Hay <157658916+minghay@users.noreply.github.com> Date: Tue, 24 Dec 2024 14:55:21 -0800 Subject: [PATCH] fix: Keep external jobs if they are not sink nodes (#1318) --- app/components/pipeline/workflow/util.js | 29 +++++++++++++++-- .../components/pipeline/workflow/util-test.js | 32 +++++++++++++++++++ 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/app/components/pipeline/workflow/util.js b/app/components/pipeline/workflow/util.js index e162d9e79..f19953b08 100644 --- a/app/components/pipeline/workflow/util.js +++ b/app/components/pipeline/workflow/util.js @@ -12,16 +12,39 @@ export const getDisplayJobNameLength = userSettings => { }; /** - * Filters the workflow graph by removing nodes that start with 'sd@' (i.e., triggers external pipelines) + * Filters the workflow graph by removing nodes that start with 'sd@' (i.e., triggers external pipelines) and are the last job in the chain * @param workflowGraph {{nodes: Array, edges: Array}} The workflow graph to filter */ export const getFilteredGraph = workflowGraph => { + const externalJobPrefix = 'sd@'; + + if ( + workflowGraph.nodes.filter(node => node.name.startsWith(externalJobPrefix)) + .length === 0 + ) { + return workflowGraph; + } + + const externalJobsToKeep = new Set(); + + workflowGraph.edges.forEach(edge => { + if (edge.src.startsWith(externalJobPrefix)) { + externalJobsToKeep.add(edge.src); + } + }); + const nodes = workflowGraph.nodes.filter(node => { - return !node.name.startsWith('sd@'); + return ( + !node.name.startsWith(externalJobPrefix) || + externalJobsToKeep.has(node.name) + ); }); const edges = workflowGraph.edges.filter(edge => { - return !edge.dest.startsWith('sd@'); + return ( + !edge.dest.startsWith(externalJobPrefix) || + externalJobsToKeep.has(edge.dest) + ); }); return { nodes, edges }; diff --git a/tests/unit/components/pipeline/workflow/util-test.js b/tests/unit/components/pipeline/workflow/util-test.js index f416597f9..1bc4cacbf 100644 --- a/tests/unit/components/pipeline/workflow/util-test.js +++ b/tests/unit/components/pipeline/workflow/util-test.js @@ -20,6 +20,19 @@ module('Unit | Component | pipeline/workflow/util', function () { ); }); + test('getFilteredGraph returns original graph if there are no external jobs', function (assert) { + assert.deepEqual( + getFilteredGraph({ + nodes: [{ name: 'main' }, { name: 'build' }], + edges: [{ src: 'main', dest: 'build' }] + }), + { + nodes: [{ name: 'main' }, { name: 'build' }], + edges: [{ src: 'main', dest: 'build' }] + } + ); + }); + test('getFilteredGraph removes nodes that trigger external pipelines', function (assert) { assert.deepEqual( getFilteredGraph({ @@ -36,6 +49,25 @@ module('Unit | Component | pipeline/workflow/util', function () { ); }); + test('getFilteredGraph keeps external pipeline nodes in the middle of the graph', function (assert) { + assert.deepEqual( + getFilteredGraph({ + nodes: [{ name: 'sd@123' }, { name: 'main' }, { name: 'build' }], + edges: [ + { src: 'main', dest: 'sd@123' }, + { src: 'sd@123', dest: 'build' } + ] + }), + { + nodes: [{ name: 'sd@123' }, { name: 'main' }, { name: 'build' }], + edges: [ + { src: 'main', dest: 'sd@123' }, + { src: 'sd@123', dest: 'build' } + ] + } + ); + }); + test('getWorkflowGraph returns filtered workflow graph', function (assert) { const workflowGraph = { nodes: [{ name: 'sd@123' }, { name: 'main' }, { name: 'build' }],