Skip to content

Commit

Permalink
fix: Keep external jobs if they are not sink nodes (#1318)
Browse files Browse the repository at this point in the history
  • Loading branch information
minghay authored Dec 24, 2024
1 parent f7adf01 commit bca3e35
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
29 changes: 26 additions & 3 deletions app/components/pipeline/workflow/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
32 changes: 32 additions & 0 deletions tests/unit/components/pipeline/workflow/util-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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' }],
Expand Down

0 comments on commit bca3e35

Please sign in to comment.