Skip to content

Commit

Permalink
Merge pull request #111 from creative-commoners/pulls/1.16/unique-jobs
Browse files Browse the repository at this point in the history
FIX Remove duplicate jobs
  • Loading branch information
GuySartorelli authored Oct 15, 2024
2 parents 79d340f + 64c1bf0 commit 931a8cd
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
4 changes: 4 additions & 0 deletions job_creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,10 @@ public function createJson(string $yml): string
$matrix['include'][$i]['name'] = implode(' ', $name);
}

// ensure there are no duplicate jobs
$uniqueSerializedJobs = array_unique(array_map('serialize', $matrix['include']));
$matrix['include'] = array_values(array_map('unserialize', $uniqueSerializedJobs));

// output json, keep it on a single line so do not use pretty print
$json = json_encode($matrix, JSON_UNESCAPED_SLASHES);
// Remove indents
Expand Down
42 changes: 42 additions & 0 deletions tests/JobCreatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1949,4 +1949,46 @@ public function provideComposerInstall(): array
],
];
}

public function testDuplicateJobsRemoved(): void
{
if (!function_exists('yaml_parse')) {
$this->markTestSkipped('yaml extension is not installed');
}
$yml = implode("\n", [
$this->getGenericYml(),
<<<EOT
github_repository: 'myaccount/silverstripe-framework'
github_my_ref: '5'
parent_branch: ''
extra_jobs:
- php: 8.2
phpunit: true
phpunit_suite: fish
- php: 8.3
phpunit: true
phpunit_suite: fish
- php: 8.3
phpunit: true
phpunit_suite: fish
- php: 8.3
endtoend: true
EOT
]);
$creator = new JobCreator();
$json = json_decode($creator->createJson($yml));
$actual = [];
foreach ($json->include as $job) {
$actual[] = $job->name;
}
$expected = [
'8.1 prf-low mysql57 phpunit all',
'8.2 mariadb phpunit all',
'8.3 mysql80 phpunit all',
'8.2 mysql57 phpunit fish',
'8.3 mysql57 phpunit fish',
'8.3 mysql57 endtoend root',
];
$this->assertSame($expected, $actual);
}
}

0 comments on commit 931a8cd

Please sign in to comment.