Skip to content

Commit c96226a

Browse files
committed
fix(workflow-result): merge existing needs with verify jobs instead of replacing
1 parent a27560c commit c96226a

4 files changed

Lines changed: 38 additions & 5 deletions

File tree

src/jobs/workflow-result/lifter.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
export default function (job, {jobs}) {
1+
export default function liftWorkflowResult(job, {jobs}) {
22
if (!Object.keys(jobs).includes('verify-matrix')) return job;
33

4-
return {...job, needs: ['verify', 'verify-matrix']};
4+
const requiredNeeds = ['verify', 'verify-matrix'];
5+
6+
return {...job, needs: [...new Set([...job.needs || [], ...requiredNeeds])]};
57
}

src/jobs/workflow-result/lifter.test.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,24 @@ describe('workflow-result job lifter', () => {
1010
expect(liftWorkflowResultJob(existingJobDetails, {jobs: any.simpleObject()})).toEqual(existingJobDetails);
1111
});
1212

13-
it('should make the job depend on the `verify-matrix` job if it exists', () => {
13+
it('should include the required dependencies if no existing needs are defined', () => {
1414
expect(liftWorkflowResultJob(
1515
existingJobDetails,
16-
{jobs: {...any.simpleObject(), 'verify-matrix': any.simpleObject()}}
16+
{jobs: {'verify-matrix': {}}}
1717
)).toEqual({...existingJobDetails, needs: ['verify', 'verify-matrix']});
1818
});
19+
20+
it('should update scaffolded needs to include verify-matrix', () => {
21+
expect(liftWorkflowResultJob(
22+
{...existingJobDetails, needs: ['verify']},
23+
{jobs: {'verify-matrix': {}}}
24+
)).toEqual({...existingJobDetails, needs: ['verify', 'verify-matrix']});
25+
});
26+
27+
it('should keep existing needs and append missing required dependencies', () => {
28+
expect(liftWorkflowResultJob(
29+
{...existingJobDetails, needs: ['existing-dependency']},
30+
{jobs: {'verify-matrix': {}}}
31+
)).toEqual({...existingJobDetails, needs: ['existing-dependency', 'verify', 'verify-matrix']});
32+
});
1933
});

test/integration/features/lift/result.feature

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ Feature: Overall Workflow Result
77
Then the workflow-result job exists
88
And the "workflow-result" job is unchanged
99

10+
Scenario: Existing result job with existing matrix job
11+
Given a CI workflow exists
12+
And a "verify-matrix" job exists
13+
And a "workflow-result" job exists
14+
When the project is lifted
15+
Then the workflow-result job exists
16+
And the workflow-result job keeps its existing needs and includes required dependencies
17+
1018
Scenario: No existing result job, existing verify
1119
Given a CI workflow exists
1220
And a "verify" job exists

test/integration/features/step_definitions/ci-steps.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Given('a CI workflow exists', async function () {
3838

3939
Given('a {string} job exists', async function (jobName) {
4040
const existingWorkflowContents = await loadWorkflowFile({projectRoot: this.projectRoot, name: ciWorkflowName});
41-
const job = any.simpleObject();
41+
const job = {...any.simpleObject(), needs: any.listOf(any.word)};
4242

4343
this.injectedJobs[jobName] = job;
4444

@@ -113,6 +113,15 @@ Then('the {string} job is unchanged', async function (jobName) {
113113
const {jobs} = await loadWorkflowFile({projectRoot: this.projectRoot, name: ciWorkflowName});
114114

115115
assert.deepEqual(jobs[jobName], this.injectedJobs[jobName]);
116+
assert.deepEqual(jobs[jobName].needs, this.injectedJobs[jobName].needs);
117+
});
118+
119+
Then('the workflow-result job keeps its existing needs and includes required dependencies', async function () {
120+
const {jobs} = await loadWorkflowFile({projectRoot: this.projectRoot, name: ciWorkflowName});
121+
const resultJob = jobs['workflow-result'];
122+
123+
assert.includeMembers(resultJob.needs, this.injectedJobs['workflow-result'].needs);
124+
assert.includeMembers(resultJob.needs, ['verify', 'verify-matrix']);
116125
});
117126

118127
Then('the workflow-result job depends on {string}', async function (jobName) {

0 commit comments

Comments
 (0)