Skip to content

Commit

Permalink
Merge pull request #99 from creative-commoners/pulls/1.15/tag
Browse files Browse the repository at this point in the history
NEW Output endtoend_tag
  • Loading branch information
GuySartorelli authored Jul 18, 2024
2 parents afb0a39 + 9fb8b7f commit 0a147f3
Show file tree
Hide file tree
Showing 3 changed files with 429 additions and 26 deletions.
86 changes: 67 additions & 19 deletions job_creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public function createJob(int $phpIndex, array $opts): array
'endtoend' => false,
'endtoend_suite' => 'root',
'endtoend_config' => '',
'endtoend_tags' => '',
'js' => false,
'doclinting' => false,
'install_in_memory_cache_exts' => false,
Expand Down Expand Up @@ -386,6 +387,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,
Expand Down Expand Up @@ -436,27 +459,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 a @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_tags' => $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_tags' => $jobTag,
]);
}
}
}
// javascript tests
Expand Down Expand Up @@ -624,6 +669,9 @@ public function createJson(string $yml): string
if ($job['endtoend'] == 'true') {
$name[] = 'endtoend';
$name[] = $job['endtoend_suite'] ?: 'root';
if ($job['endtoend_tags']) {
$name[] = $job['endtoend_tags'];
}
}
if ($job['js'] == 'true') {
$name[] = 'js';
Expand Down
Loading

0 comments on commit 0a147f3

Please sign in to comment.