#!/usr/bin/env php * * SPDX-License-Identifier: GPL-3.0-or-later * * FILE INFORMATION * DEFGROUP: MokoStandards.CLI * INGROUP: MokoStandards * REPO: https://git.mokoconsulting.tech/MokoConsulting/moko-platform * PATH: /cli/release_notes.php * BRIEF: Extract release notes from CHANGELOG.md for a given version */ declare(strict_types=1); $path = '.'; $version = null; 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 ($version === null) { // Read from README.md $readme = realpath($path) . '/README.md'; if (file_exists($readme)) { $content = file_get_contents($readme); if (preg_match('/^\s*VERSION:\s*(\d{2}\.\d{2}\.\d{2})/m', $content, $m)) { $version = $m[1]; } } } if ($version === null) { fwrite(STDERR, "Usage: release_notes.php --path . --version XX.YY.ZZ\n"); exit(1); } $changelog = realpath($path) . '/CHANGELOG.md'; if (!file_exists($changelog)) { echo "Release {$version}\n"; exit(0); } $lines = file($changelog, FILE_IGNORE_NEW_LINES); $notes = []; $capturing = false; foreach ($lines as $line) { if (preg_match('/^##\s.*' . preg_quote($version, '/') . '/', $line)) { $capturing = true; continue; } if ($capturing && preg_match('/^## /', $line)) { break; // Next version heading — stop } if ($capturing) { $notes[] = $line; } } $result = trim(implode("\n", $notes)); echo $result ?: "Release {$version}"; echo "\n"; exit(0);