c6da98289b
Update DEFGROUP and INGROUP fields across all CLI scripts to reflect the repo rename from MokoStandards to moko-platform. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
83 lines
2.1 KiB
PHP
83 lines
2.1 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/changelog_promote.php
|
|
* BRIEF: Promote [Unreleased] section in CHANGELOG.md to a versioned entry
|
|
*
|
|
* Usage:
|
|
* php changelog_promote.php --path /repo --version 04.01.00
|
|
* php changelog_promote.php --path /repo --version 04.01.00 --date 2026-05-21
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
$path = '.';
|
|
$version = null;
|
|
$date = date('Y-m-d');
|
|
|
|
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 === '--date' && isset($argv[$i + 1])) $date = $argv[$i + 1];
|
|
}
|
|
|
|
if ($version === null) {
|
|
fwrite(STDERR, "Usage: changelog_promote.php --path . --version XX.YY.ZZ [--date YYYY-MM-DD]\n");
|
|
exit(1);
|
|
}
|
|
|
|
$changelog = realpath($path) . '/CHANGELOG.md';
|
|
if (!file_exists($changelog)) {
|
|
fwrite(STDERR, "No CHANGELOG.md found at {$path}\n");
|
|
exit(1);
|
|
}
|
|
|
|
$content = file_get_contents($changelog);
|
|
|
|
// Check if [Unreleased] section exists
|
|
if (!preg_match('/## \[?Unreleased\]?/i', $content)) {
|
|
fwrite(STDERR, "No [Unreleased] section found in CHANGELOG.md\n");
|
|
exit(1);
|
|
}
|
|
|
|
// Replace [Unreleased] with versioned entry
|
|
$content = preg_replace(
|
|
'/## \[Unreleased\]/i',
|
|
"## [{$version}] --- {$date}",
|
|
$content,
|
|
1
|
|
);
|
|
$content = preg_replace(
|
|
'/## Unreleased/i',
|
|
"## [{$version}] --- {$date}",
|
|
$content,
|
|
1
|
|
);
|
|
|
|
// Insert new [Unreleased] section after the first heading line (# Changelog)
|
|
$lines = explode("\n", $content);
|
|
$inserted = false;
|
|
$result = [];
|
|
|
|
foreach ($lines as $line) {
|
|
$result[] = $line;
|
|
if (!$inserted && preg_match('/^# /', $line)) {
|
|
$result[] = '';
|
|
$result[] = '## [Unreleased]';
|
|
$result[] = '';
|
|
$inserted = true;
|
|
}
|
|
}
|
|
|
|
$content = implode("\n", $result);
|
|
file_put_contents($changelog, $content);
|
|
echo "CHANGELOG promoted: [Unreleased] -> [{$version}] --- {$date}\n";
|
|
exit(0);
|