From 3a9f2a0f64fdd47f9e1f423ada5f01bda2c4c5c0 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 9 Aug 2023 14:01:12 +1200 Subject: [PATCH] NEW Add merge-ups --- .github/workflows/ci.yml | 10 +++--- composer.json | 7 +++-- funcs_scripts.php | 18 +++++++++-- funcs_utils.php | 49 ++++++++++++++++++++++++++--- scripts/cms-any/editorconfig.php | 4 ++- scripts/cms5/merge-ups.php | 54 ++++++++++++++++++++++++++++++++ update_command.php | 3 ++ 7 files changed, 129 insertions(+), 16 deletions(-) create mode 100644 scripts/cms5/merge-ups.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 46090ea..830067f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,10 +17,10 @@ jobs: - name: Install PHP uses: shivammathur/setup-php@1a18b2267f80291a81ca1d33e7c851fe09e7dfc4 # v2.22.0 with: - php-version: 7.4 - - - name: Install PHPUnit - run: wget https://phar.phpunit.de/phpunit-9.5.phar + php-version: 8.1 + + - name: Composer install + run: composer install --prefer-dist --no-progress --no-suggest --ansi --no-interaction --no-scripts --no-plugins --optimize-autoloader - name: PHPUnit - run: php phpunit-9.5.phar --verbose --colors=always + run: vendor/bin/phpunit --verbose --colors=always diff --git a/composer.json b/composer.json index aee3979..88b0f89 100644 --- a/composer.json +++ b/composer.json @@ -1,10 +1,11 @@ { "require": { - "php": ">=7.4", + "php": ">=8.1", "symfony/console": "^6.3", - "symfony/process": "^6.3" + "symfony/process": "^6.3", + "panlatent/cron-expression-descriptor": "^1" }, "require-dev": { - "phpunit/phpunit": "^9.5" + "phpunit/phpunit": "^9.6" } } diff --git a/funcs_scripts.php b/funcs_scripts.php index 7735e1c..3cc728a 100644 --- a/funcs_scripts.php +++ b/funcs_scripts.php @@ -108,14 +108,26 @@ function rename_file_if_exists($oldFilename, $newFilename) function module_is_recipe() { global $MODULE_DIR; - if (strpos('/recipe-', $MODULE_DIR) !== false - || strpos('/silverstripe-installer', $MODULE_DIR) !== false + if (strpos($MODULE_DIR, '/recipe-') !== false + || strpos($MODULE_DIR, '/silverstripe-installer') !== false ) { return true; } return false; } +/** + * Determine if the module being processed is gha-* + * + * Example usage: + * module_is_gha() + */ +function module_is_gha() +{ + global $MODULE_DIR; + return strpos($MODULE_DIR, '/gha-') !== false; +} + /** * Determine if the module being processed is one of the modules in a list * @@ -132,7 +144,7 @@ function module_is_one_of($repos) if (!is_string($repo)) { error('repo is not a string'); } - if (strpos("/$repo", $MODULE_DIR) !== false) { + if (strpos($MODULE_DIR, "/$repo") !== false) { return true; } } diff --git a/funcs_utils.php b/funcs_utils.php index 1306dfd..166925e 100644 --- a/funcs_utils.php +++ b/funcs_utils.php @@ -34,7 +34,7 @@ function write_file($path, $contents) } $dirname = dirname($path); if (!file_exists($dirname)) { - error("Directory $dirname does not exist"); + mkdir($dirname, 0775, true); } $contents = trim($contents) . "\n"; file_put_contents($path, $contents); @@ -67,7 +67,38 @@ function supported_modules($cmsMajor) 'account' => explode('/', $ghrepo)[0], 'repo' => explode('/', $ghrepo)[1], 'cloneUrl' => "git@github.com:$ghrepo.git", - 'branch' => max($module['branches'] ?: [-1]) + ]; + } + return $modules; +} + +/** + * Hardcoded list of unsupported modules to standardise + * + * This will only be included if the $cmsMajor is the CURRENT_CMS_MAJOR + */ +function extra_modules() +{ + $ghrepos = [ + 'silverstripe/gha-auto-tag', + 'silverstripe/gha-ci', + 'silverstripe/gha-dispatch-ci', + 'silverstripe/gha-generate-matrix', + 'silverstripe/gha-keepalive', + 'silverstripe/gha-issue', + 'silverstripe/gha-pull-request', + 'silverstripe/gha-run-tests', + 'silverstripe/gha-merge-up', + 'silverstripe/gha-tag-release', + 'silverstripe/gha-update-js', + ]; + $modules = []; + foreach ($ghrepos as $ghrepo) { + $modules[] = [ + 'ghrepo' => $ghrepo, + 'account' => explode('/', $ghrepo)[0], + 'repo' => explode('/', $ghrepo)[1], + 'cloneUrl' => "git@github.com:$ghrepo.git", ]; } return $modules; @@ -265,12 +296,22 @@ function branch_to_checkout($branches, $currentBranch, $currentBranchCmsMajor, $ return (string) $branchToCheckout; } +/** + * Uses composer.json to workout the current branch cms major version + * + * If composer.json does not exist then it's assumed to be CURRENT_CMS_MAJOR + */ function current_branch_cms_major( // this param is only used for unit testing string $composerJson = '' ) { - // read __composer.json of the current branch - $contents = $composerJson ?: read_file('composer.json'); + if ($composerJson) { + $contents = $composerJson; + } elseif (check_file_exists('composer.json')) { + $contents = read_file('composer.json'); + } else { + return CURRENT_CMS_MAJOR; + } $json = json_decode($contents); if (is_null($json)) { diff --git a/scripts/cms-any/editorconfig.php b/scripts/cms-any/editorconfig.php index d3ee8fa..62c4934 100644 --- a/scripts/cms-any/editorconfig.php +++ b/scripts/cms-any/editorconfig.php @@ -34,4 +34,6 @@ insert_final_newline = false EOT; -write_file_if_not_exist('.editorconfig', $contents); +if (!module_is_gha()) { + write_file_if_not_exist('.editorconfig', $contents); +} diff --git a/scripts/cms5/merge-ups.php b/scripts/cms5/merge-ups.php new file mode 100644 index 0000000..ce7970f --- /dev/null +++ b/scripts/cms5/merge-ups.php @@ -0,0 +1,54 @@ +getOption('only')) { $only = explode(',', $input->getOption('only')); $modules = array_filter($modules, function ($module) use ($only) {