From 76fc1ee0b42de4aa18060f962dd65662756570b5 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Thu, 15 Feb 2024 16:12:35 +1300 Subject: [PATCH] ENH Restrict which repos get dispatch-ci --- funcs_scripts.php | 33 +++++++++++++++++++++++++++++++++ scripts/cms-any/dispatch-ci.php | 11 +++++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/funcs_scripts.php b/funcs_scripts.php index eb25285..faed572 100644 --- a/funcs_scripts.php +++ b/funcs_scripts.php @@ -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 * @@ -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 * diff --git a/scripts/cms-any/dispatch-ci.php b/scripts/cms-any/dispatch-ci.php index ac1501c..bc94c47 100644 --- a/scripts/cms-any/dispatch-ci.php +++ b/scripts/cms-any/dispatch-ci.php @@ -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); + } }