Files
Jonathan Miller bc47944d8f
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 / CI Summary (push) Blocked by required conditions
Platform: moko-platform CI / Gate 1: Code Quality (push) Failing after 0s
Generic: Repo Health / Access control (push) Failing after 0s
Generic: Repo Health / Site Health (push) Has been skipped
Generic: Repo Health / Release configuration (push) Has been skipped
Generic: Repo Health / Scripts governance (push) Has been skipped
Generic: Repo Health / Repository health (push) Has been skipped
Platform: moko-platform CI / Gate 2: Unit Tests (8.1) (pull_request) Blocked by required conditions
Platform: moko-platform CI / Gate 2: Unit Tests (8.2) (pull_request) Blocked by required conditions
Platform: moko-platform CI / Gate 2: Unit Tests (8.3) (pull_request) Blocked by required conditions
Platform: moko-platform CI / Gate 3: Self-Health Check (pull_request) Blocked by required conditions
Platform: moko-platform CI / Gate 4: Governance (pull_request) Blocked by required conditions
Platform: moko-platform CI / CI Summary (pull_request) Blocked by required conditions
Platform: moko-platform CI / Gate 1: Code Quality (pull_request) Failing after 0s
Universal: Secret Scanning / Gitleaks Secret Scan (pull_request) Failing after 0s
Generic: Repo Health / Site Health (pull_request) Has been skipped
Generic: Repo Health / Access control (pull_request) Failing after 0s
Universal: PR Check / Branch Policy (pull_request) Successful in 1s
Generic: Repo Health / Release configuration (pull_request) Has been skipped
Generic: Repo Health / Scripts governance (pull_request) Has been skipped
Generic: Repo Health / Repository health (pull_request) Has been skipped
Universal: PR Check / Validate PR (pull_request) Successful in 4s
Universal: PR Check / Build RC Package (pull_request) Failing after 0s
Platform: moko-platform CI / Gate 5: Template Integrity (push) Has been skipped
Platform: moko-platform CI / Gate 5: Template Integrity (pull_request) Has been skipped
fix: version_read/bump handle suffixed versions and HTML-comment VERSION
Two bugs caused release-candidate pre-release builds to fail after a
development pre-release had been built:

1. XML regex only matched bare XX.YY.ZZ but not XX.YY.ZZ-dev/-rc etc.
   After a development pre-release wrote -dev suffix to manifests, the
   next pre-release could not read the version back.

2. README regex required VERSION: at line start (^\s*VERSION:) which
   does not match <!-- VERSION: 01.00.00 --> format used by some repos.

Fixes: version_read.php, version_bump.php

Authored-by: Moko Consulting
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-25 00:13:50 -05:00

115 lines
4.0 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 patch version — checks both README.md and manifest XML, uses the higher version as base
*/
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;
// ── Read version from 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];
}
}
// ── 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;
}
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;
}
}
}
// ── 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");
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);
// ── Update README.md ─────────────────────────────────────────────────────────
if (file_exists($readme) && !empty($readmeContent)) {
$updated = preg_replace(
'/(VERSION:\s*)\d{2}\.\d{2}\.\d{2}/m',
'${1}' . $new,
$readmeContent,
1
);
file_put_contents($readme, $updated);
}
echo "{$old}{$new}\n";
exit(0);