From f2540a72ad89d393ef4587ae446ebb952fa5a672 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 26 Nov 2021 22:10:46 +0000 Subject: [PATCH] Backport improved make-release.php from PM4 --- build/make-release.php | 83 +++++++++++++++++++++++----------- src/pocketmine/VersionInfo.php | 2 +- 2 files changed, 58 insertions(+), 27 deletions(-) diff --git a/build/make-release.php b/build/make-release.php index ec6bc2f01..441e74ce2 100644 --- a/build/make-release.php +++ b/build/make-release.php @@ -24,64 +24,95 @@ declare(strict_types=1); namespace pocketmine\build\make_release; use pocketmine\utils\VersionString; -use function count; +use function array_keys; +use function array_map; use function dirname; use function fgets; use function file_get_contents; use function file_put_contents; use function fwrite; +use function getopt; +use function is_string; +use function max; use function preg_replace; use function sleep; use function sprintf; +use function str_pad; +use function strlen; use function system; use const pocketmine\BASE_VERSION; +use const pocketmine\BUILD_CHANNEL; use const STDERR; use const STDIN; +use const STDOUT; +use const STR_PAD_LEFT; require_once dirname(__DIR__) . '/vendor/autoload.php'; function replaceVersion(string $versionInfoPath, string $newVersion, bool $isDev, string $channel) : void{ $versionInfo = file_get_contents($versionInfoPath); $versionInfo = preg_replace( - $pattern = '/^const BASE_VERSION = "(\d+)\.(\d+)\.(\d+)(?:-(.*))?";$/m', - 'const BASE_VERSION = "' . $newVersion . '";', + $pattern = '/^([\t ]*public )?const BASE_VERSION = "(\d+)\.(\d+)\.(\d+)(?:-(.*))?";$/m', + '$1const BASE_VERSION = "' . $newVersion . '";', $versionInfo ); $versionInfo = preg_replace( - '/^const IS_DEVELOPMENT_BUILD = (?:true|false);$/m', - 'const IS_DEVELOPMENT_BUILD = ' . ($isDev ? 'true' : 'false') . ';', + '/^([\t ]*public )?const IS_DEVELOPMENT_BUILD = (?:true|false);$/m', + '$1const IS_DEVELOPMENT_BUILD = ' . ($isDev ? 'true' : 'false') . ';', $versionInfo ); $versionInfo = preg_replace( - '/^const BUILD_CHANNEL = ".*";$/m', - 'const BUILD_CHANNEL = "' . $channel . '";', + '/^([\t ]*public )?const BUILD_CHANNEL = ".*";$/m', + '$1const BUILD_CHANNEL = "' . $channel . '";', $versionInfo ); file_put_contents($versionInfoPath, $versionInfo); } -/** - * @param string[] $argv - * @phpstan-param list $argv - */ -function main(array $argv) : void{ - if(count($argv) < 2){ - fwrite(STDERR, "Arguments: [release version]\n"); - exit(1); +const ACCEPTED_OPTS = [ + "current" => "Version to insert and tag", + "next" => "Version to put in the file after tagging", + "channel" => "Release channel to post this build into" +]; + +function main() : void{ + $filteredOpts = []; + foreach(getopt("", ["current:", "next:", "channel:", "help"]) as $optName => $optValue){ + if($optName === "help"){ + fwrite(STDOUT, "Options:\n"); + + $maxLength = max(array_map(fn(string $str) => strlen($str), array_keys(ACCEPTED_OPTS))); + foreach(ACCEPTED_OPTS as $acceptedName => $description){ + fwrite(STDOUT, str_pad("--$acceptedName", $maxLength + 4, " ", STR_PAD_LEFT) . ": $description\n"); + } + exit(0); + } + if(!is_string($optValue)){ + fwrite(STDERR, "--$optName expects exactly 1 value\n"); + exit(1); + } + $filteredOpts[$optName] = $optValue; } - if(isset($argv[2])){ - $currentVer = new VersionString($argv[2]); + + if(isset($filteredOpts["current"])){ + $currentVer = new VersionString($filteredOpts["current"]); }else{ $currentVer = new VersionString(BASE_VERSION); } - $nextVer = new VersionString(sprintf( - "%u.%u.%u", - $currentVer->getMajor(), - $currentVer->getMinor(), - $currentVer->getPatch() + 1 - )); + if(isset($filteredOpts["next"])){ + $nextVer = new VersionString($filteredOpts["next"]); + }else{ + $nextVer = new VersionString(sprintf( + "%u.%u.%u", + $currentVer->getMajor(), + $currentVer->getMinor(), + $currentVer->getPatch() + 1 + )); + } + $channel = $filteredOpts["channel"] ?? BUILD_CHANNEL; echo "About to tag version $currentVer. Next version will be $nextVer.\n"; + echo "$currentVer will be published on release channel \"$channel\".\n"; echo "please add appropriate notes to the changelog and press enter..."; fgets(STDIN); system('git add "' . dirname(__DIR__) . '/changelogs"'); @@ -91,10 +122,10 @@ function main(array $argv) : void{ exit(1); } $versionInfoPath = dirname(__DIR__) . '/src/pocketmine/VersionInfo.php'; - replaceVersion($versionInfoPath, $currentVer->getBaseVersion(), false, $argv[1]); + replaceVersion($versionInfoPath, $currentVer->getBaseVersion(), false, $channel); system('git commit -m "Release ' . $currentVer->getBaseVersion() . '" --include "' . $versionInfoPath . '"'); system('git tag ' . $currentVer->getBaseVersion()); - replaceVersion($versionInfoPath, $nextVer->getBaseVersion(), true, ""); + replaceVersion($versionInfoPath, $nextVer->getBaseVersion(), true, $channel); system('git add "' . $versionInfoPath . '"'); system('git commit -m "' . $nextVer->getBaseVersion() . ' is next" --include "' . $versionInfoPath . '"'); echo "pushing changes in 5 seconds\n"; @@ -102,4 +133,4 @@ function main(array $argv) : void{ system('git push origin HEAD ' . $currentVer->getBaseVersion()); } -main($argv); +main(); diff --git a/src/pocketmine/VersionInfo.php b/src/pocketmine/VersionInfo.php index 05b503d48..bc4e06c15 100644 --- a/src/pocketmine/VersionInfo.php +++ b/src/pocketmine/VersionInfo.php @@ -36,4 +36,4 @@ const NAME = "PocketMine-MP"; const BASE_VERSION = "3.25.5"; const IS_DEVELOPMENT_BUILD = true; const BUILD_NUMBER = 0; -const BUILD_CHANNEL = ""; +const BUILD_CHANNEL = "stable";