From 71b813d4f968748d7a64c6f1781a27a699142b5d Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 26 Nov 2021 22:27:58 +0000 Subject: [PATCH] Define pocketmine\BUILD_NUMBER from phar metadata this way we don't have to patch the code (no idea why we were doing that anyway). --- .github/workflows/draft-release.yml | 9 +++++---- build/generate-build-info-json.php | 6 +++--- build/server-phar.php | 10 ++++++++-- src/pocketmine/PocketMine.php | 11 ++++++++--- src/pocketmine/VersionInfo.php | 1 - tests/phpstan/bootstrap.php | 1 + 6 files changed, 25 insertions(+), 13 deletions(-) diff --git a/.github/workflows/draft-release.yml b/.github/workflows/draft-release.yml index 37b743422..b70a2757f 100644 --- a/.github/workflows/draft-release.yml +++ b/.github/workflows/draft-release.yml @@ -35,11 +35,12 @@ jobs: - name: Install Composer dependencies run: composer install --no-dev --prefer-dist --no-interaction --ignore-platform-reqs - - name: Patch VersionInfo + - name: Calculate build number + id: build-number run: | BUILD_NUMBER=2000+$GITHUB_RUN_NUMBER #to stay above jenkins echo "Build number: $BUILD_NUMBER" - sed -i "s/const BUILD_NUMBER = 0/const BUILD_NUMBER = ${BUILD_NUMBER}/" src/pocketmine/VersionInfo.php + echo ::set-output name=BUILD_NUMBER::$BUILD_NUMBER - name: Minify BedrockData JSON files run: php src/pocketmine/resources/vanilla/.minify_json.php @@ -68,7 +69,7 @@ jobs: done - name: Build PocketMine-MP.phar - run: php -dphar.readonly=0 build/server-phar.php --git ${{ github.sha }} + run: php -dphar.readonly=0 build/server-phar.php --git ${{ github.sha }} --build ${{ steps.build-number.outputs.BUILD_NUMBER }} - name: Get PocketMine-MP release version id: get-pm-version @@ -79,7 +80,7 @@ jobs: echo ::set-output name=PM_VERSION_MD::$(php -r 'require "vendor/autoload.php"; echo str_replace(".", "", \pocketmine\BASE_VERSION);') - name: Generate build info - run: php build/generate-build-info-json.php ${{ github.sha }} ${{ steps.get-pm-version.outputs.PM_VERSION }} ${{ github.repository }} > build_info.json + run: php build/generate-build-info-json.php ${{ github.sha }} ${{ steps.get-pm-version.outputs.PM_VERSION }} ${{ github.repository }} ${{ steps.build-number.outputs.BUILD_NUMBER }} > build_info.json - name: Upload release artifacts uses: actions/upload-artifact@v2 diff --git a/build/generate-build-info-json.php b/build/generate-build-info-json.php index 57828c372..b1ca16fca 100644 --- a/build/generate-build-info-json.php +++ b/build/generate-build-info-json.php @@ -23,15 +23,15 @@ declare(strict_types=1); require dirname(__DIR__) . '/vendor/autoload.php'; -if(count($argv) !== 4){ - fwrite(STDERR, "required args: "); +if(count($argv) !== 5){ + fwrite(STDERR, "required args: "); exit(1); } echo json_encode([ "php_version" => sprintf("%d.%d", PHP_MAJOR_VERSION, PHP_MINOR_VERSION), "base_version" => \pocketmine\BASE_VERSION, - "build" => \pocketmine\BUILD_NUMBER, + "build" => (int) $argv[4], "is_dev" => \pocketmine\IS_DEVELOPMENT_BUILD, "channel" => \pocketmine\BUILD_CHANNEL, "git_commit" => $argv[1], diff --git a/build/server-phar.php b/build/server-phar.php index ed9200d35..462ff879c 100644 --- a/build/server-phar.php +++ b/build/server-phar.php @@ -134,13 +134,18 @@ function main() : void{ exit(1); } - $opts = getopt("", ["out:", "git:"]); + $opts = getopt("", ["out:", "git:", "build:"]); if(isset($opts["git"])){ $gitHash = $opts["git"]; }else{ $gitHash = Git::getRepositoryStatePretty(dirname(__DIR__)); echo "Git hash detected as $gitHash" . PHP_EOL; } + if(isset($opts["build"])){ + $build = (int) $opts["build"]; + }else{ + $build = 0; + } foreach(buildPhar( $opts["out"] ?? getcwd() . DIRECTORY_SEPARATOR . "PocketMine-MP.phar", dirname(__DIR__) . DIRECTORY_SEPARATOR, @@ -149,7 +154,8 @@ function main() : void{ 'vendor' ], [ - 'git' => $gitHash + 'git' => $gitHash, + 'build' => $build ], <<<'STUB' getFullVersion(true)); - $gitHash = str_repeat("00", 20); + $buildNumber = 0; if(\Phar::running(true) === ""){ $gitHash = Git::getRepositoryStatePretty(\pocketmine\PATH); @@ -225,9 +223,16 @@ JIT_WARNING if(isset($meta["git"])){ $gitHash = $meta["git"]; } + if(isset($meta["build"]) && is_int($meta["build"])){ + $buildNumber = $meta["build"]; + } } define('pocketmine\GIT_COMMIT', $gitHash); + define('pocketmine\BUILD_NUMBER', $buildNumber); + + $version = new VersionString(\pocketmine\BASE_VERSION, \pocketmine\IS_DEVELOPMENT_BUILD, \pocketmine\BUILD_NUMBER); + define('pocketmine\VERSION', $version->getFullVersion(true)); $composerGitHash = InstalledVersions::getReference('pocketmine/pocketmine-mp'); if($composerGitHash !== null){ diff --git a/src/pocketmine/VersionInfo.php b/src/pocketmine/VersionInfo.php index bc4e06c15..7c6ecba82 100644 --- a/src/pocketmine/VersionInfo.php +++ b/src/pocketmine/VersionInfo.php @@ -35,5 +35,4 @@ const _VERSION_INFO_INCLUDED = true; const NAME = "PocketMine-MP"; const BASE_VERSION = "3.25.5"; const IS_DEVELOPMENT_BUILD = true; -const BUILD_NUMBER = 0; const BUILD_CHANNEL = "stable"; diff --git a/tests/phpstan/bootstrap.php b/tests/phpstan/bootstrap.php index 7e374a27f..2969d503c 100644 --- a/tests/phpstan/bootstrap.php +++ b/tests/phpstan/bootstrap.php @@ -30,6 +30,7 @@ if(!defined('LEVELDB_ZLIB_RAW_COMPRESSION')){ define('pocketmine\COMPOSER_AUTOLOADER_PATH', dirname(__DIR__, 2) . '/vendor/autoload.php'); define('pocketmine\DATA', ''); define('pocketmine\GIT_COMMIT', str_repeat('00', 20)); +define('pocketmine\BUILD_NUMBER', 0); define('pocketmine\PLUGIN_PATH', ''); define('pocketmine\START_TIME', microtime(true)); define('pocketmine\VERSION', '9.9.9');