Skip to content

Commit

Permalink
ENH Restrict which repos get dispatch-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Feb 15, 2024
1 parent 1eaf525 commit 76fc1ee
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
33 changes: 33 additions & 0 deletions funcs_scripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,28 @@ function is_module()
return in_array($json->type, $moduleTypes);
}

/**
* Determine if the module being processed is a composer plugin
*
* Example usage:
* is_composer_plugin()
*/
function is_composer_plugin()
{
if (!check_file_exists('composer.json')) {
return false;
}

$contents = read_file('composer.json');
$json = json_decode($contents);
if (is_null($json)) {
$lastError = json_last_error();
error("Could not parse from composer.json - last error was $lastError");
}

return $json->type === 'composer-plugin';
}

/**
* Determine if the module being processed is a theme
*
Expand Down Expand Up @@ -216,6 +238,17 @@ function is_gha_repository()
return !is_module() && strpos($MODULE_DIR, '/gha-') !== false;
}

/**
* Determine if the module being processed should include a dispatch-ci.yml file
*
* Example usage:
* should_use_dispatch_ci()
*/
function should_use_dispatch_ci()
{
return (is_module() || is_composer_plugin()) && !is_docs() && !is_gha_repository();
}

/**
* Return the module name without the account e.g. silverstripe/silverstripe-admin with return silverstripe-admin
*
Expand Down
11 changes: 9 additions & 2 deletions scripts/cms-any/dispatch-ci.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
uses: silverstripe/gha-dispatch-ci@v1
EOT;

if (check_file_exists('.github/workflows/ci.yml')) {
write_file_even_if_exists('.github/workflows/dispatch-ci.yml', $content);
$dispatchCiPath = '.github/workflows/dispatch-ci.yml';
$ciPath = '.github/workflows/ci.yml';

if (is_gha_repository() || is_docs()) {
delete_file_if_exists($dispatchCiPath);
} else {
if (check_file_exists($ciPath)) {
write_file_even_if_exists($dispatchCiPath, $content);
}
}

0 comments on commit 76fc1ee

Please sign in to comment.