2026-04-15 02:35:30 +00:00
|
|
|
#!/usr/bin/env php
|
|
|
|
|
<?php
|
|
|
|
|
/* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
*
|
|
|
|
|
* FILE INFORMATION
|
2026-05-21 21:33:52 -05:00
|
|
|
* DEFGROUP: moko-platform.CLI
|
|
|
|
|
* INGROUP: moko-platform
|
2026-05-11 17:01:17 -05:00
|
|
|
* REPO: https://git.mokoconsulting.tech/MokoConsulting/moko-platform
|
2026-04-15 02:35:30 +00:00
|
|
|
* PATH: /cli/version_bump.php
|
2026-05-23 22:47:49 -05:00
|
|
|
* BRIEF: Auto-increment patch version — checks both README.md and manifest XML, uses the higher version as base
|
2026-04-15 02:35:30 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
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';
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-23 22:47:49 -05:00
|
|
|
$root = realpath($path) ?: $path;
|
|
|
|
|
|
|
|
|
|
// ── Read version from README.md ──────────────────────────────────────────────
|
|
|
|
|
$readmeVersion = null;
|
|
|
|
|
$readme = "{$root}/README.md";
|
|
|
|
|
$readmeContent = '';
|
|
|
|
|
if (file_exists($readme)) {
|
|
|
|
|
$readmeContent = file_get_contents($readme);
|
2026-05-25 00:13:50 -05:00
|
|
|
if (preg_match('/VERSION:\s*(\d{2}\.\d{2}\.\d{2})/m', $readmeContent, $m)) {
|
2026-05-23 22:47:49 -05:00
|
|
|
$readmeVersion = $m[1];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ── Read version from Joomla manifest XML ────────────────────────────────────
|
|
|
|
|
$manifestVersion = null;
|
|
|
|
|
|
|
|
|
|
// Check package manifest first (pkg_*.xml), then sub-extension manifests
|
|
|
|
|
$manifestFiles = array_merge(
|
|
|
|
|
glob("{$root}/src/pkg_*.xml") ?: [],
|
|
|
|
|
glob("{$root}/src/*.xml") ?: [],
|
|
|
|
|
glob("{$root}/src/packages/*/mokowaas.xml") ?: [],
|
|
|
|
|
glob("{$root}/src/packages/*/*.xml") ?: [],
|
|
|
|
|
glob("{$root}/*.xml") ?: []
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
foreach ($manifestFiles as $xmlFile) {
|
|
|
|
|
$xmlContent = file_get_contents($xmlFile);
|
|
|
|
|
if (strpos($xmlContent, '<extension') === false && strpos($xmlContent, '<version>') === false) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2026-05-25 00:13:50 -05:00
|
|
|
if (preg_match('|<version>(\d{2}\.\d{2}\.\d{2})(?:-[a-z]+)?</version>|', $xmlContent, $xm)) {
|
2026-05-23 22:47:49 -05:00
|
|
|
$candidate = $xm[1];
|
|
|
|
|
if ($manifestVersion === null || version_compare($candidate, $manifestVersion, '>')) {
|
|
|
|
|
$manifestVersion = $candidate;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ── Use the higher version as base ───────────────────────────────────────────
|
|
|
|
|
$baseVersion = null;
|
|
|
|
|
|
|
|
|
|
if ($readmeVersion !== null && $manifestVersion !== null) {
|
|
|
|
|
$baseVersion = version_compare($manifestVersion, $readmeVersion, '>') ? $manifestVersion : $readmeVersion;
|
|
|
|
|
} elseif ($manifestVersion !== null) {
|
|
|
|
|
$baseVersion = $manifestVersion;
|
|
|
|
|
} elseif ($readmeVersion !== null) {
|
|
|
|
|
$baseVersion = $readmeVersion;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($baseVersion === null) {
|
|
|
|
|
fwrite(STDERR, "No version found in README.md or manifest XML\n");
|
2026-04-15 02:35:30 +00:00
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-23 22:47:49 -05:00
|
|
|
// ── Parse and bump ───────────────────────────────────────────────────────────
|
|
|
|
|
if (!preg_match('/^(\d{2})\.(\d{2})\.(\d{2})$/', $baseVersion, $parts)) {
|
|
|
|
|
fwrite(STDERR, "Invalid version format: {$baseVersion}\n");
|
2026-04-15 02:35:30 +00:00
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-23 22:47:49 -05:00
|
|
|
$major = (int)$parts[1];
|
|
|
|
|
$minor = (int)$parts[2];
|
|
|
|
|
$patch = (int)$parts[3];
|
2026-04-15 02:35:30 +00:00
|
|
|
$old = sprintf('%02d.%02d.%02d', $major, $minor, $patch);
|
|
|
|
|
|
|
|
|
|
switch ($type) {
|
|
|
|
|
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; }
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$new = sprintf('%02d.%02d.%02d', $major, $minor, $patch);
|
|
|
|
|
|
2026-05-23 22:47:49 -05:00
|
|
|
// ── Update README.md ─────────────────────────────────────────────────────────
|
|
|
|
|
if (file_exists($readme) && !empty($readmeContent)) {
|
|
|
|
|
$updated = preg_replace(
|
2026-05-25 00:13:50 -05:00
|
|
|
'/(VERSION:\s*)\d{2}\.\d{2}\.\d{2}/m',
|
2026-05-23 22:47:49 -05:00
|
|
|
'${1}' . $new,
|
|
|
|
|
$readmeContent,
|
|
|
|
|
1
|
|
|
|
|
);
|
|
|
|
|
file_put_contents($readme, $updated);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-15 02:35:30 +00:00
|
|
|
echo "{$old} → {$new}\n";
|
|
|
|
|
exit(0);
|