refactor(cli): migrate 64 legacy scripts to CliFramework (#235)
Platform: moko-platform CI / Gate 2: Unit Tests (8.1) (push) Blocked by required conditions
Platform: moko-platform CI / Gate 2: Unit Tests (8.2) (push) Blocked by required conditions
Platform: moko-platform CI / Gate 2: Unit Tests (8.3) (push) Blocked by required conditions
Platform: moko-platform CI / Gate 3: Self-Health Check (push) Blocked by required conditions
Platform: moko-platform CI / Gate 4: Governance (push) Blocked by required conditions
Platform: moko-platform CI / Gate 5: Template Integrity (push) Blocked by required conditions
Platform: moko-platform CI / CI Summary (push) Blocked by required conditions
Generic: Repo Health / Release configuration (push) Blocked by required conditions
Generic: Repo Health / Scripts governance (push) Blocked by required conditions
Generic: Repo Health / Repository health (push) Blocked by required conditions
Generic: Repo Health / Site Health (push) Has been skipped
Generic: Repo Health / Access control (push) Successful in 2s
Platform: moko-platform CI / Gate 1: Code Quality (push) Failing after 36s
Platform: moko-platform CI / Gate 2: Unit Tests (8.1) (push) Blocked by required conditions
Platform: moko-platform CI / Gate 2: Unit Tests (8.2) (push) Blocked by required conditions
Platform: moko-platform CI / Gate 2: Unit Tests (8.3) (push) Blocked by required conditions
Platform: moko-platform CI / Gate 3: Self-Health Check (push) Blocked by required conditions
Platform: moko-platform CI / Gate 4: Governance (push) Blocked by required conditions
Platform: moko-platform CI / Gate 5: Template Integrity (push) Blocked by required conditions
Platform: moko-platform CI / CI Summary (push) Blocked by required conditions
Generic: Repo Health / Release configuration (push) Blocked by required conditions
Generic: Repo Health / Scripts governance (push) Blocked by required conditions
Generic: Repo Health / Repository health (push) Blocked by required conditions
Generic: Repo Health / Site Health (push) Has been skipped
Generic: Repo Health / Access control (push) Successful in 2s
Platform: moko-platform CI / Gate 1: Code Quality (push) Failing after 36s
Wrap all CLI tools in cli/, automation/, maintenance/, deploy/, and release/ in classes extending CliFramework. Replaces manual $argv parsing with configure()/addArgument(), moves logic into run(): int, and converts fwrite(STDERR,...) to $this->log(). Two CLIApp subclasses (generate_dolibarr_version_txt, generate_joomla_update_xml) converted to extend CliFramework directly. Every script now gets free --help, --verbose, --quiet, --dry-run, --json, --no-color, banners, coloured logging, and progress bars. Authored-by: Moko Consulting Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+152
-142
@@ -10,163 +10,173 @@
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/moko-platform
|
||||
* PATH: /cli/version_set_platform.php
|
||||
* BRIEF: Set version in platform-specific files (Dolibarr $this->version, Joomla <version>)
|
||||
*
|
||||
* Usage:
|
||||
* php version_set_platform.php --path . --version 04.01.00
|
||||
* php version_set_platform.php --path . --version 04.01.00 --stability alpha
|
||||
*
|
||||
* When --stability is set to anything other than "stable", the suffix is
|
||||
* appended to the version (e.g. 04.01.00-dev, 04.01.00-alpha, 04.01.00-rc).
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
$path = '.';
|
||||
$version = null;
|
||||
$branch = null;
|
||||
$stability = 'stable';
|
||||
require_once __DIR__ . '/../lib/Enterprise/CliFramework.php';
|
||||
|
||||
foreach ($argv as $i => $arg) {
|
||||
if ($arg === '--path' && isset($argv[$i + 1])) $path = $argv[$i + 1];
|
||||
if ($arg === '--version' && isset($argv[$i + 1])) $version = $argv[$i + 1];
|
||||
if ($arg === '--branch' && isset($argv[$i + 1])) $branch = $argv[$i + 1];
|
||||
if ($arg === '--stability' && isset($argv[$i + 1])) $stability = $argv[$i + 1];
|
||||
}
|
||||
use MokoEnterprise\CliFramework;
|
||||
|
||||
// Auto-detect branch from git or GitHub env
|
||||
if ($branch === null) {
|
||||
$branch = trim((string) @shell_exec('git rev-parse --abbrev-ref HEAD 2>/dev/null'));
|
||||
if (empty($branch) || $branch === 'HEAD') {
|
||||
$branch = getenv('GITHUB_REF_NAME') ?: 'main';
|
||||
class VersionSetPlatformCli extends CliFramework
|
||||
{
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setDescription('Set version in platform-specific files (Dolibarr $this->version, Joomla <version>)');
|
||||
$this->addArgument('--path', 'Repository root path', '.');
|
||||
$this->addArgument('--version', 'Version string XX.YY.ZZ', '');
|
||||
$this->addArgument('--branch', 'Git branch name', '');
|
||||
$this->addArgument('--stability', 'Stability level (stable, dev, alpha, beta, rc)', 'stable');
|
||||
}
|
||||
}
|
||||
|
||||
if ($version === null) {
|
||||
fwrite(STDERR, "Usage: version_set_platform.php --path . --version 04.01.00 [--stability dev]\n");
|
||||
exit(1);
|
||||
}
|
||||
protected function run(): int
|
||||
{
|
||||
$path = $this->getArgument('--path');
|
||||
$version = $this->getArgument('--version');
|
||||
$branch = $this->getArgument('--branch');
|
||||
$stability = $this->getArgument('--stability');
|
||||
|
||||
// Strip any existing suffix(es) before applying the correct one
|
||||
$version = preg_replace('/(-(dev|alpha|beta|rc))+$/', '', $version);
|
||||
|
||||
// Append stability suffix for non-stable releases
|
||||
$stabilitySuffixMap = [
|
||||
'stable' => '',
|
||||
'development' => '-dev',
|
||||
'dev' => '-dev',
|
||||
'alpha' => '-alpha',
|
||||
'beta' => '-beta',
|
||||
'rc' => '-rc',
|
||||
'release-candidate' => '-rc',
|
||||
];
|
||||
$suffix = $stabilitySuffixMap[$stability] ?? '';
|
||||
if ($suffix !== '' && !str_ends_with($version, $suffix)) {
|
||||
$version .= $suffix;
|
||||
echo "Version with stability suffix: {$version}\n";
|
||||
}
|
||||
|
||||
$root = realpath($path) ?: $path;
|
||||
|
||||
// Detect platform — check manifest.xml first, then legacy .mokostandards
|
||||
$platform = '';
|
||||
|
||||
// New format: .mokogitea/manifest.xml (XML with <platform> tag)
|
||||
$manifestXml = "{$root}/.mokogitea/manifest.xml";
|
||||
if (file_exists($manifestXml)) {
|
||||
$xml = @simplexml_load_file($manifestXml);
|
||||
if ($xml && isset($xml->governance->platform)) {
|
||||
$platform = (string) $xml->governance->platform;
|
||||
}
|
||||
}
|
||||
|
||||
// Legacy: .mokostandards YAML file
|
||||
if (empty($platform)) {
|
||||
$mokoStandards = "{$root}/.github/.mokostandards";
|
||||
if (!file_exists($mokoStandards)) {
|
||||
$mokoStandards = "{$root}/.mokogitea/.mokostandards";
|
||||
}
|
||||
if (!file_exists($mokoStandards)) {
|
||||
$mokoStandards = "{$root}/.mokostandards";
|
||||
}
|
||||
if (file_exists($mokoStandards)) {
|
||||
$content = file_get_contents($mokoStandards);
|
||||
if (preg_match('/^platform:\s*(.+)/m', $content, $m)) {
|
||||
$platform = trim($m[1], " \t\n\r\"'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$changed = 0;
|
||||
|
||||
// Dolibarr: $this->version + $this->url_last_version in mod*.class.php
|
||||
if ($platform === 'crm-module') {
|
||||
$pattern = "{$root}/src/core/modules/mod*.class.php";
|
||||
foreach (glob($pattern) ?: [] as $file) {
|
||||
$content = file_get_contents($file);
|
||||
|
||||
// Set $this->version
|
||||
$updated = preg_replace(
|
||||
'/(\$this->version\s*=\s*)[\'"][^\'"]*[\'"]/',
|
||||
"\${1}'{$version}'",
|
||||
$content
|
||||
);
|
||||
|
||||
// Rewrite $this->url_last_version to point to current branch
|
||||
if (preg_match('/\$this->url_last_version\s*=\s*[\'"]([^\'"]+)[\'"]/', $updated, $urlMatch)) {
|
||||
$oldUrl = $urlMatch[1];
|
||||
// Replace the branch segment: .../BRANCH/update.txt
|
||||
$newUrl = preg_replace(
|
||||
'#(raw\.githubusercontent\.com/[^/]+/[^/]+/)[^/]+(/update\.json)#',
|
||||
"\${1}{$branch}\${2}",
|
||||
$oldUrl
|
||||
);
|
||||
if ($newUrl !== $oldUrl) {
|
||||
$updated = str_replace($oldUrl, $newUrl, $updated);
|
||||
echo "Dolibarr: url_last_version → {$branch}/update.txt\n";
|
||||
// Auto-detect branch from git or GitHub env
|
||||
if ($branch === '') {
|
||||
$branch = trim((string) @shell_exec('git rev-parse --abbrev-ref HEAD 2>/dev/null'));
|
||||
if (empty($branch) || $branch === 'HEAD') {
|
||||
$branch = getenv('GITHUB_REF_NAME') ?: 'main';
|
||||
}
|
||||
}
|
||||
|
||||
if ($updated !== $content) {
|
||||
file_put_contents($file, $updated);
|
||||
echo "Dolibarr: " . basename($file) . " → version={$version}, branch={$branch}\n";
|
||||
$changed++;
|
||||
if ($version === '') {
|
||||
$this->log('ERROR', 'Usage: version_set_platform.php --path . --version 04.01.00 [--stability dev]');
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Joomla: <version> in XML manifests (top-level + sub-packages)
|
||||
if (in_array($platform, ['waas-component', 'joomla'], true)) {
|
||||
$xmlFiles = array_merge(
|
||||
glob("{$root}/src/*.xml") ?: [],
|
||||
glob("{$root}/src/packages/*/*.xml") ?: [],
|
||||
glob("{$root}/*.xml") ?: []
|
||||
);
|
||||
if (empty($xmlFiles)) {
|
||||
$xmlFiles = glob("{$root}/*.xml") ?: [];
|
||||
}
|
||||
foreach ($xmlFiles as $file) {
|
||||
$content = file_get_contents($file);
|
||||
if (!str_contains($content, '<extension')) continue;
|
||||
$updated = preg_replace(
|
||||
'|<version>[^<]*</version>|',
|
||||
"<version>{$version}</version>",
|
||||
$content
|
||||
);
|
||||
if ($updated !== null && $updated !== $content) {
|
||||
file_put_contents($file, $updated);
|
||||
$relPath = str_replace($root . '/', '', $file);
|
||||
echo "Joomla: {$relPath} → {$version}\n";
|
||||
$changed++;
|
||||
// Strip any existing suffix(es) before applying the correct one
|
||||
$version = preg_replace('/(-(dev|alpha|beta|rc))+$/', '', $version);
|
||||
|
||||
// Append stability suffix for non-stable releases
|
||||
$stabilitySuffixMap = [
|
||||
'stable' => '',
|
||||
'development' => '-dev',
|
||||
'dev' => '-dev',
|
||||
'alpha' => '-alpha',
|
||||
'beta' => '-beta',
|
||||
'rc' => '-rc',
|
||||
'release-candidate' => '-rc',
|
||||
];
|
||||
$suffix = $stabilitySuffixMap[$stability] ?? '';
|
||||
if ($suffix !== '' && !str_ends_with($version, $suffix)) {
|
||||
$version .= $suffix;
|
||||
echo "Version with stability suffix: {$version}\n";
|
||||
}
|
||||
|
||||
$root = realpath($path) ?: $path;
|
||||
|
||||
// Detect platform — check manifest.xml first, then legacy .mokostandards
|
||||
$platform = '';
|
||||
|
||||
// New format: .mokogitea/manifest.xml (XML with <platform> tag)
|
||||
$manifestXml = "{$root}/.mokogitea/manifest.xml";
|
||||
if (file_exists($manifestXml)) {
|
||||
$xml = @simplexml_load_file($manifestXml);
|
||||
if ($xml && isset($xml->governance->platform)) {
|
||||
$platform = (string) $xml->governance->platform;
|
||||
}
|
||||
}
|
||||
|
||||
// Legacy: .mokostandards YAML file
|
||||
if (empty($platform)) {
|
||||
$mokoStandards = "{$root}/.github/.mokostandards";
|
||||
if (!file_exists($mokoStandards)) {
|
||||
$mokoStandards = "{$root}/.mokogitea/manifest.xml";
|
||||
}
|
||||
if (!file_exists($mokoStandards)) {
|
||||
$mokoStandards = "{$root}/.mokostandards";
|
||||
}
|
||||
if (file_exists($mokoStandards)) {
|
||||
$content = file_get_contents($mokoStandards);
|
||||
if (preg_match('/^platform:\s*(.+)/m', $content, $m)) {
|
||||
$platform = trim($m[1], " \t\n\r\"'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$changed = 0;
|
||||
|
||||
// Dolibarr: $this->version + $this->url_last_version in mod*.class.php
|
||||
if ($platform === 'crm-module') {
|
||||
$pattern = "{$root}/src/core/modules/mod*.class.php";
|
||||
foreach (glob($pattern) ?: [] as $file) {
|
||||
$content = file_get_contents($file);
|
||||
|
||||
// Set $this->version
|
||||
$updated = preg_replace(
|
||||
'/(\$this->version\s*=\s*)[\'"][^\'"]*[\'"]/',
|
||||
"\${1}'{$version}'",
|
||||
$content
|
||||
);
|
||||
|
||||
// Rewrite $this->url_last_version to point to current branch
|
||||
if (preg_match('/\$this->url_last_version\s*=\s*[\'"]([^\'"]+)[\'"]/', $updated, $urlMatch)) {
|
||||
$oldUrl = $urlMatch[1];
|
||||
// Replace the branch segment: .../BRANCH/update.txt
|
||||
$newUrl = preg_replace(
|
||||
'#(raw\.githubusercontent\.com/[^/]+/[^/]+/)[^/]+(/update\.json)#',
|
||||
"\${1}{$branch}\${2}",
|
||||
$oldUrl
|
||||
);
|
||||
if ($newUrl !== $oldUrl) {
|
||||
$updated = str_replace($oldUrl, $newUrl, $updated);
|
||||
echo "Dolibarr: url_last_version → {$branch}/update.txt\n";
|
||||
}
|
||||
}
|
||||
|
||||
if ($updated !== $content) {
|
||||
file_put_contents($file, $updated);
|
||||
echo "Dolibarr: " . basename($file) . " → version={$version}, branch={$branch}\n";
|
||||
$changed++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Joomla: <version> in XML manifests (top-level + sub-packages)
|
||||
if (in_array($platform, ['waas-component', 'joomla'], true)) {
|
||||
$xmlFiles = array_merge(
|
||||
glob("{$root}/src/*.xml") ?: [],
|
||||
glob("{$root}/src/packages/*/*.xml") ?: [],
|
||||
glob("{$root}/*.xml") ?: []
|
||||
);
|
||||
if (empty($xmlFiles)) {
|
||||
$xmlFiles = glob("{$root}/*.xml") ?: [];
|
||||
}
|
||||
foreach ($xmlFiles as $file) {
|
||||
$content = file_get_contents($file);
|
||||
if (!str_contains($content, '<extension')) {
|
||||
continue;
|
||||
}
|
||||
$updated = preg_replace(
|
||||
'|<version>[^<]*</version>|',
|
||||
"<version>{$version}</version>",
|
||||
$content
|
||||
);
|
||||
if ($updated !== null && $updated !== $content) {
|
||||
file_put_contents($file, $updated);
|
||||
$relPath = str_replace($root . '/', '', $file);
|
||||
echo "Joomla: {$relPath} → {$version}\n";
|
||||
$changed++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($changed === 0) {
|
||||
if (empty($platform)) {
|
||||
echo "No .mokostandards file — skipping platform version set\n";
|
||||
} else {
|
||||
echo "No platform-specific version files found for {$platform}\n";
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if ($changed === 0) {
|
||||
if (empty($platform)) {
|
||||
echo "No .mokostandards file — skipping platform version set\n";
|
||||
} else {
|
||||
echo "No platform-specific version files found for {$platform}\n";
|
||||
}
|
||||
}
|
||||
|
||||
exit(0);
|
||||
$app = new VersionSetPlatformCli();
|
||||
exit($app->execute());
|
||||
|
||||
Reference in New Issue
Block a user