From a5cd566dea69d143e2fdc4a9efb89f5499dd1560 Mon Sep 17 00:00:00 2001 From: Jonathan Miller <1+jmiller@noreply.git.mokoconsulting.tech> Date: Tue, 26 May 2026 20:12:36 +0000 Subject: [PATCH] fix: version_bump.php cascades version to all Joomla XML manifests Authored-by: Moko Consulting --- cli/version_bump.php | 144 +++++++++++++------------------------------ 1 file changed, 42 insertions(+), 102 deletions(-) diff --git a/cli/version_bump.php b/cli/version_bump.php index 661df0c..eb5d122 100644 --- a/cli/version_bump.php +++ b/cli/version_bump.php @@ -1,6 +1,5 @@ #!/usr/bin/env php * * SPDX-License-Identifier: GPL-3.0-or-later @@ -10,7 +9,7 @@ * INGROUP: moko-platform * REPO: https://git.mokoconsulting.tech/MokoConsulting/moko-platform * PATH: /cli/version_bump.php - * BRIEF: Auto-increment version — manifest.xml is canonical, also updates README.md and Joomla XML + * BRIEF: Auto-increment version — manifest.xml is canonical, cascades to all XML and MD files */ declare(strict_types=1); @@ -18,15 +17,9 @@ declare(strict_types=1); $path = '.'; $type = 'patch'; // patch | minor | major foreach ($argv as $i => $arg) { - if ($arg === '--path' && isset($argv[$i + 1])) { - $path = $argv[$i + 1]; - } - if ($arg === '--minor') { - $type = 'minor'; - } - if ($arg === '--major') { - $type = 'major'; - } + if ($arg === '--path' && isset($argv[$i + 1])) $path = $argv[$i + 1]; + if ($arg === '--minor') $type = 'minor'; + if ($arg === '--major') $type = 'major'; } $root = realpath($path) ?: $path; @@ -102,25 +95,12 @@ $patch = (int)$parts[3]; $old = sprintf('%02d.%02d.%02d', $major, $minor, $patch); switch ($type) { - case 'major': - $major++; - $minor = 0; - $patch = 0; - break; - case 'minor': - $minor++; - $patch = 0; - break; + case 'major': $major++; $minor = 0; $patch = 0; break; + case 'minor': $minor++; $patch = 0; break; default: $patch++; - if ($patch > 99) { - $minor++; - $patch = 0; - } - if ($minor > 99) { - $major++; - $minor = 0; - } + if ($patch > 99) { $minor++; $patch = 0; } + if ($minor > 99) { $major++; $minor = 0; } break; } @@ -128,34 +108,12 @@ $new = sprintf('%02d.%02d.%02d', $major, $minor, $patch); // -- Update .mokogitea/manifest.xml (canonical target) -- if (file_exists($mokoManifest) && !empty($mokoContent)) { - if (preg_match('|\d{2}\.\d{2}\.\d{2}|', $mokoContent)) { - // Replace existing version tag - $updated = preg_replace( - '|\d{2}\.\d{2}\.\d{2}|', - "{$new}", - $mokoContent, - 1 - ); - } else { - // Insert before (per schema order) or as last child of - if (strpos($mokoContent, '{$new}\$1", - $mokoContent, - 1 - ); - } elseif (strpos($mokoContent, '') !== false) { - $updated = preg_replace( - '|()|', - " {$new}\n \$1", - $mokoContent, - 1 - ); - } else { - $updated = $mokoContent; - } - } + $updated = preg_replace( + '|\d{2}\.\d{2}\.\d{2}|', + "{$new}", + $mokoContent, + 1 + ); file_put_contents($mokoManifest, $updated); } @@ -170,55 +128,37 @@ if (file_exists($readme) && !empty($readmeContent)) { file_put_contents($readme, $updated); } -// ── Update manifest XML files ──────────────────────────────────────────────── -foreach ($manifestFiles as $xmlFile) { - $xmlContent = file_get_contents($xmlFile); - if (strpos($xmlContent, '') === false) { - continue; - } - $updatedXml = preg_replace( - '|\d{2}\.\d{2}\.\d{2}(?:-[a-z]+)?|', - "{$new}", - $xmlContent - ); - if ($updatedXml !== $xmlContent) { - file_put_contents($xmlFile, $updatedXml); +// -- Cascade to ALL Joomla extension XML manifests -- +$xmlPatterns = [ + "{$root}/src/pkg_*.xml", + "{$root}/src/*.xml", + "{$root}/src/packages/*/*.xml", + "{$root}/*.xml", +]; + +$updatedFiles = []; +foreach ($xmlPatterns as $pattern) { + foreach (glob($pattern) ?: [] as $xmlFile) { + $content = file_get_contents($xmlFile); + // Only update files that have an tag (Joomla manifests) + if (strpos($content, '\d{2}\.\d{2}\.\d{2}(?:-[a-z]+)?|', + "{$new}", + $content + ); + if ($newContent !== $content) { + file_put_contents($xmlFile, $newContent); + $updatedFiles[] = substr($xmlFile, strlen($root) + 1); + } } } -// ── Update Dolibarr mod*.class.php ─────────────────────────────────────────── -$modFiles = array_merge( - glob("{$root}/src/core/modules/mod*.class.php") ?: [], - glob("{$root}/htdocs/core/modules/mod*.class.php") ?: [] -); -foreach ($modFiles as $modFile) { - $modContent = file_get_contents($modFile); - if (strpos($modContent, 'extends DolibarrModules') === false) { - continue; - } - $updatedMod = preg_replace( - '/(\$this->version\s*=\s*)[\'"][^\'"]*[\'"]/', - "\${1}'{$new}'", - $modContent - ); - if ($updatedMod !== $modContent) { - file_put_contents($modFile, $updatedMod); - } +if (!empty($updatedFiles)) { + fwrite(STDERR, "Updated " . count($updatedFiles) . " Joomla manifest(s): " . implode(', ', $updatedFiles) . "\n"); } -// ── Update composer.json ───────────────────────────────────────────────────── -$composerFile = "{$root}/composer.json"; -if (file_exists($composerFile)) { - $composerContent = file_get_contents($composerFile); - $updatedComposer = preg_replace( - '/("version"\s*:\s*")\d{2}\.\d{2}\.\d{2}(")/m', - '${1}' . $new . '${2}', - $composerContent - ); - if ($updatedComposer !== $composerContent) { - file_put_contents($composerFile, $updatedComposer); - } -} - -echo "{$old} → {$new}\n"; +echo "{$old} -> {$new}\n"; exit(0);