From bddd8a9609e5212d4b17f1aab6281c14c1472475 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 16 Jul 2024 10:20:09 +1200 Subject: [PATCH] NEW Output endtoend_tag --- job_creator.php | 82 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 63 insertions(+), 19 deletions(-) diff --git a/job_creator.php b/job_creator.php index 08f032c..0736b50 100644 --- a/job_creator.php +++ b/job_creator.php @@ -386,6 +386,28 @@ private function doRunPhpCoverage(array $run): bool return $run['phpcoverage']; } + /** + * Recursively finds all nested files matching an extension in a directory + */ + private function getFilesMatchingExtension($dir, $extension, &$filepaths = []): array + { + $files = scandir($dir); + foreach ($files as $file) { + if (in_array($file, ['.', '..'])) { + continue; + } + if (is_dir("$dir/$file")) { + $this->getFilesMatchingExtension("$dir/$file", $extension, $filepaths); + } else { + $ext = pathinfo($file, PATHINFO_EXTENSION); + if ($ext === $extension) { + $filepaths[] = "$dir/$file"; + } + } + } + return $filepaths; + } + private function buildDynamicMatrix( array $matrix, array $run, @@ -436,27 +458,49 @@ private function buildDynamicMatrix( } // endtoend / behat if ($run['endtoend'] && file_exists('behat.yml')) { - $graphql3 = !$simpleMatrix && $cmsMajor == '4'; - $job = $this->createJob(0, [ - 'endtoend' => true, - 'endtoend_suite' => 'root', - 'composer_require_extra' => $graphql3 ? 'silverstripe/graphql:^3' : '' - ]); - // use minimum version of 7.4 for endtoend because was having apt dependency issues - // in CI when using php 7.3: - // The following packages have unmet dependencies: - // libpcre2-dev : Depends: libpcre2-8-0 (= 10.39-3+ubuntu20.04.1+deb.sury.org+2) but - // 10.40-1+ubuntu20.04.1+deb.sury.org+1 is to be installed - if ($job['php'] == '7.3') { - $job['php'] = '7.4'; - } - $matrix['include'][] = $job; - if (!$simpleMatrix && !$composerInstall) { - $matrix['include'][] = $this->createJob(3, [ - 'db' => DB_MYSQL_80, + $jobTags = []; + $filepaths = $this->getFilesMatchingExtension(getcwd(), 'feature'); + foreach ($filepaths as $filepath) { + $contents = file_get_contents($filepath); + if (preg_match('#@(job[0-9]+)#', $contents, $matches)) { + $jobTags[] = $matches[1]; + } + } + $jobTagsCount = count($jobTags); + $jobTags = array_unique($jobTags); + if ($jobTagsCount === 0) { + $jobTags = ['']; + } else { + if ($jobTagsCount !== count($filepaths)) { + throw new RuntimeException("At least one .feature files missing an @job[0-9]+ tag"); + } + } + sort($jobTags); + foreach ($jobTags as $jobTag) { + $graphql3 = !$simpleMatrix && $cmsMajor == '4'; + $job = $this->createJob(0, [ 'endtoend' => true, - 'endtoend_suite' => 'root' + 'endtoend_suite' => 'root', + 'endtoend_tag' => $jobTag, + 'composer_require_extra' => $graphql3 ? 'silverstripe/graphql:^3' : '', ]); + // use minimum version of 7.4 for endtoend because was having apt dependency issues + // in CI when using php 7.3: + // The following packages have unmet dependencies: + // libpcre2-dev : Depends: libpcre2-8-0 (= 10.39-3+ubuntu20.04.1+deb.sury.org+2) but + // 10.40-1+ubuntu20.04.1+deb.sury.org+1 is to be installed + if ($job['php'] == '7.3') { + $job['php'] = '7.4'; + } + $matrix['include'][] = $job; + if (!$simpleMatrix && !$composerInstall) { + $matrix['include'][] = $this->createJob(3, [ + 'db' => DB_MYSQL_80, + 'endtoend' => true, + 'endtoend_suite' => 'root', + 'endtoend_tag' => $jobTag, + ]); + } } } // javascript tests