Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Keep external jobs if they are not sink nodes #1318

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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