#!/usr/bin/env php * * 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/release_validate.php * BRIEF: Pre-release validation — version consistency, required files, manifest checks * * Usage: * php release_validate.php --path /repo --version 04.01.00 * php release_validate.php --path /repo --version 04.01.00 --platform joomla --output-summary * * Options: * --path Repository root (default: .) * --version Expected version string (required) * --platform joomla|dolibarr|generic (default: joomla) * --output-summary Write markdown table to $GITHUB_STEP_SUMMARY */ declare(strict_types=1); $path = '.'; $version = null; $platform = 'joomla'; $outputSummary = false; 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 === '--platform' && isset($argv[$i + 1])) $platform = $argv[$i + 1]; if ($arg === '--output-summary') $outputSummary = true; } if ($version === null) { fwrite(STDERR, "Usage: release_validate.php --path . --version XX.YY.ZZ [--platform joomla]\n"); exit(1); } $root = realpath($path) ?: $path; $pass = 0; $fail = 0; $warn = 0; $results = []; function addResult(string $check, string $status, string $details): void { global $pass, $fail, $warn, $results; $results[] = ['check' => $check, 'status' => $status, 'details' => $details]; if ($status === 'PASS') $pass++; elseif ($status === 'FAIL') $fail++; elseif ($status === 'WARN') $warn++; } // 1. README.md exists and contains VERSION if (!file_exists("{$root}/README.md")) { addResult('README.md', 'FAIL', 'Not found'); } else { $readme = file_get_contents("{$root}/README.md"); if (preg_match('/VERSION:\s*' . preg_quote($version, '/') . '/', $readme) || strpos($readme, $version) !== false) { addResult('README.md version', 'PASS', "`{$version}` found"); } else { addResult('README.md version', 'FAIL', "`{$version}` not found in README.md"); } } // 2. CHANGELOG.md exists with matching section if (!file_exists("{$root}/CHANGELOG.md")) { addResult('CHANGELOG.md', 'WARN', 'Not found'); } else { $cl = file_get_contents("{$root}/CHANGELOG.md"); if (preg_match('/^##\s.*' . preg_quote($version, '/') . '/m', $cl)) { addResult('CHANGELOG.md version', 'PASS', "Section for `{$version}` found"); } else { addResult('CHANGELOG.md version', 'WARN', "No section header for `{$version}`"); } } // 3. LICENSE file exists $licenseFound = false; foreach (['LICENSE', 'LICENSE.md', 'LICENSE.txt', 'COPYING'] as $lf) { if (file_exists("{$root}/{$lf}")) { $licenseFound = true; break; } } addResult('LICENSE', $licenseFound ? 'PASS' : 'FAIL', $licenseFound ? 'Found' : 'Not found'); // 4. Platform-specific checks if ($platform === 'joomla') { // Find XML manifest $manifest = null; $searchDirs = ["{$root}/src", $root]; foreach ($searchDirs as $dir) { if (!is_dir($dir)) continue; foreach (glob("{$dir}/*.xml") as $xmlFile) { $content = file_get_contents($xmlFile); if (strpos($content, '([^<]+)<\/version>/', file_get_contents($manifest), $m)) { $mVer = trim($m[1]); if ($mVer === $version) { addResult('Manifest version', 'PASS', "`{$mVer}` matches"); } else { addResult('Manifest version', 'FAIL', "`{$mVer}` != `{$version}`"); } } else { addResult('Manifest version', 'FAIL', 'No tag in manifest'); } } // updates.xml if (!file_exists("{$root}/updates.xml")) { addResult('updates.xml', 'WARN', 'Not found'); } else { $ux = file_get_contents("{$root}/updates.xml"); if (preg_match('/' . preg_quote($version, '/') . '<\/version>/', $ux)) { addResult('updates.xml version', 'PASS', "`{$version}` found"); } else { addResult('updates.xml version', 'FAIL', "`{$version}` not in updates.xml"); } } } elseif ($platform === 'dolibarr') { $modFile = null; foreach (['src', 'htdocs'] as $sd) { $pattern = "{$root}/{$sd}/mod*.class.php"; $matches = glob($pattern); if (!empty($matches)) { $modFile = $matches[0]; break; } } if ($modFile === null) { addResult('Dolibarr mod file', 'FAIL', 'No mod*.class.php found'); } else { $mc = file_get_contents($modFile); if (preg_match("/\\\$this->version\s*=\s*'" . preg_quote($version, '/') . "'/", $mc)) { addResult('Dolibarr version', 'PASS', "`{$version}` matches"); } else { addResult('Dolibarr version', 'FAIL', "`{$version}` not found in " . basename($modFile)); } } } // 5. composer.json version (if present) if (file_exists("{$root}/composer.json")) { $composer = json_decode(file_get_contents("{$root}/composer.json"), true); if (isset($composer['version'])) { if ($composer['version'] === $version) { addResult('composer.json version', 'PASS', "`{$version}` matches"); } else { addResult('composer.json version', 'WARN', "`{$composer['version']}` != `{$version}`"); } } } // Output $table = "| Check | Result | Details |\n|-------|--------|--------|\n"; foreach ($results as $r) { $table .= "| {$r['check']} | {$r['status']} | {$r['details']} |\n"; } $table .= "\n**Validation: {$pass} passed, {$fail} failed, {$warn} warnings**\n"; echo $table; if ($outputSummary) { $summaryFile = getenv('GITHUB_STEP_SUMMARY'); if ($summaryFile) { file_put_contents($summaryFile, "### Pre-Release Validation\n\n{$table}\n", FILE_APPEND); } } exit($fail > 0 ? 1 : 0);