Files
moko-platform/cli/version_bump.php
T
Jonathan Miller a4009aff2f
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 1s
Universal: Auto Version Bump / Version Bump (push) Successful in 5s
Platform: moko-platform CI / Gate 1: Code Quality (push) Failing after 1m2s
fix(version): proper suffix handling across entire release pipeline
Root cause: sed-based suffix injection in workflows caused cascading
issues — stable releases got -dev in zip names, updates.xml had all
channels pointing to -dev versions, version_bump preserved stale suffixes.

Changes:
- version_bump.php: always writes clean versions (no suffix), since
  version_set_platform.php handles suffix application via --stability
- version_set_platform.php: strips existing suffix before applying new
  one, preventing double-suffix bugs
- updates_xml_build.php: strips incoming suffix defensively before
  applying per-channel suffixes
- auto-bump.yml: replaced sed hack with --stability dev flag on
  version_set_platform.php call
- update-server.yml: same — uses --stability flag instead of sed
- pre-release.yml: same — strips existing suffix, uses --stability flag
- auto-release.yml: strips suffix from VERSION on main before stable
  build to prevent -dev contamination in stable releases

Authored-by: Moko Consulting

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-28 14:14:12 -05:00

206 lines
6.4 KiB
PHP

#!/usr/bin/env php
<?php
/* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
* FILE INFORMATION
* DEFGROUP: moko-platform.CLI
* INGROUP: moko-platform
* REPO: https://git.mokoconsulting.tech/MokoConsulting/moko-platform
* PATH: /cli/version_bump.php
* BRIEF: Auto-increment version — manifest.xml is canonical, cascades to all XML and MD files
*/
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';
}
$root = realpath($path) ?: $path;
// -- 1. Read version from .mokogitea/manifest.xml (canonical) --
$mokoVersion = null;
$mokoSuffix = '';
$mokoManifest = "{$root}/.mokogitea/manifest.xml";
$mokoContent = '';
if (file_exists($mokoManifest)) {
$mokoContent = file_get_contents($mokoManifest);
if (preg_match('|<version>(\d{2}\.\d{2}\.\d{2})(?:-([a-z]+))?</version>|', $mokoContent, $m)) {
$mokoVersion = $m[1];
$mokoSuffix = isset($m[2]) ? $m[2] : '';
}
}
// -- 2. Fallback: README.md --
$readmeVersion = null;
$readme = "{$root}/README.md";
$readmeContent = '';
if (file_exists($readme)) {
$readmeContent = file_get_contents($readme);
if (preg_match('/VERSION:\s*(\d{2}\.\d{2}\.\d{2})/m', $readmeContent, $m)) {
$readmeVersion = $m[1];
}
}
// -- 3. Fallback: Joomla manifest XML --
$manifestVersion = null;
$manifestSuffix = '';
$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;
}
if (preg_match('|<version>(\d{2}\.\d{2}\.\d{2})(-[a-z]+)?</version>|', $xmlContent, $xm)) {
$candidate = $xm[1];
if ($manifestVersion === null || version_compare($candidate, $manifestVersion, '>')) {
$manifestVersion = $candidate;
// Preserve the suffix from the manifest (e.g. dev, rc) — strip leading dash
$manifestSuffix = ltrim($xm[2] ?? '', '-');
}
}
}
// -- Use the highest version as base --
$baseVersion = null;
$candidates = array_filter([$mokoVersion, $readmeVersion, $manifestVersion]);
foreach ($candidates as $v) {
if ($baseVersion === null || version_compare($v, $baseVersion, '>')) {
$baseVersion = $v;
}
}
if ($baseVersion === null) {
fwrite(STDERR, "No version found in manifest.xml, README.md, or Joomla XML\n");
exit(1);
}
// -- Parse and bump --
if (!preg_match('/^(\d{2})\.(\d{2})\.(\d{2})$/', $baseVersion, $parts)) {
fwrite(STDERR, "Invalid version format: {$baseVersion}\n");
exit(1);
}
$major = (int)$parts[1];
$minor = (int)$parts[2];
$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;
default:
$patch++;
if ($patch > 99) { $minor++; $patch = 0; }
if ($minor > 99) { $major++; $minor = 0; }
break;
}
$new = sprintf('%02d.%02d.%02d', $major, $minor, $patch);
// -- Write clean version (no suffix) ------------------------------------------
// Suffixes (-dev, -alpha, -beta, -rc) are managed by version_set_platform.php
// called from CI workflows with the appropriate --stability flag. version_bump
// always writes a clean base version so the suffix layer stays consistent.
$newFull = $new;
// -- Update .mokogitea/manifest.xml (canonical — preserves suffix) --
if (file_exists($mokoManifest) && !empty($mokoContent)) {
$updated = preg_replace(
'|<version>\d{2}\.\d{2}\.\d{2}(?:-[a-z]+)?</version>|',
"<version>{$newFull}</version>",
$mokoContent,
1
);
file_put_contents($mokoManifest, $updated);
}
// -- Update README.md --
if (file_exists($readme) && !empty($readmeContent)) {
$updated = preg_replace(
'/(VERSION:\s*)\d{2}\.\d{2}\.\d{2}(?:-[a-z]+)?/m',
'${1}' . $newFull,
$readmeContent,
1
);
file_put_contents($readme, $updated);
}
// -- 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 <extension> tag (Joomla manifests)
if (strpos($content, '<extension') === false) {
continue;
}
$newContent = preg_replace(
'|<version>\d{2}\.\d{2}\.\d{2}(?:-[a-z]+)?</version>|',
"<version>{$newFull}</version>",
$content
);
if ($newContent !== $content) {
file_put_contents($xmlFile, $newContent);
$updatedFiles[] = substr($xmlFile, strlen($root) + 1);
}
}
}
if (!empty($updatedFiles)) {
fwrite(STDERR, "Updated " . count($updatedFiles) . " Joomla manifest(s): " . implode(', ', $updatedFiles) . "\n");
}
// -- Update package.json (Node.js / MCP) --
$packageJsonFile = "{$root}/package.json";
if (file_exists($packageJsonFile)) {
$pkgContent = file_get_contents($packageJsonFile);
$updatedPkg = preg_replace(
'/("version"\s*:\s*")\d{2}\.\d{2}\.\d{2}(?:-[a-z]+)?(")/m',
'${1}' . $newFull . '${2}',
$pkgContent
);
if ($updatedPkg !== $pkgContent) {
file_put_contents($packageJsonFile, $updatedPkg);
fwrite(STDERR, "Updated package.json\n");
}
}
// -- Update pyproject.toml (Python) --
$pyprojectFile = "{$root}/pyproject.toml";
if (file_exists($pyprojectFile)) {
$pyContent = file_get_contents($pyprojectFile);
$updatedPy = preg_replace(
'/^(version\s*=\s*")\d{2}\.\d{2}\.\d{2}(?:-[a-z]+)?(")/m',
'${1}' . $newFull . '${2}',
$pyContent
);
if ($updatedPy !== $pyContent) {
file_put_contents($pyprojectFile, $updatedPy);
fwrite(STDERR, "Updated pyproject.toml\n");
}
}
echo "{$old} -> {$newFull}\n";
exit(0);