diff --git a/job_creator.php b/job_creator.php index 47dbb99..d9b3946 100644 --- a/job_creator.php +++ b/job_creator.php @@ -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 diff --git a/tests/JobCreatorTest.php b/tests/JobCreatorTest.php index 47d5e35..87df123 100644 --- a/tests/JobCreatorTest.php +++ b/tests/JobCreatorTest.php @@ -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(), + <<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); + } }