#!/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_notes.php * BRIEF: Extract release notes from CHANGELOG.md for a given version */ declare(strict_types=1); require_once __DIR__ . '/../lib/Enterprise/CliFramework.php'; use MokoEnterprise\CliFramework; class ReleaseNotesCli extends CliFramework { protected function configure(): void { $this->setDescription('Extract release notes from CHANGELOG.md for a given version'); $this->addArgument('--path', 'Repository root path', '.'); $this->addArgument('--version', 'Version to extract notes for', ''); } protected function run(): int { $path = $this->getArgument('--path'); $version = $this->getArgument('--version') ?: null; if ($version === null || $version === '') { // 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 || $version === '') { $this->log('ERROR', 'Usage: release_notes.php --path . --version XX.YY.ZZ'); return 1; } $changelog = realpath($path) . '/CHANGELOG.md'; if (!file_exists($changelog)) { echo "Release {$version}\n"; return 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; } if ($capturing) { $notes[] = $line; } } $result = trim(implode("\n", $notes)); echo $result ?: "Release {$version}"; echo "\n"; return 0; } } $app = new ReleaseNotesCli(); exit($app->execute());