From 3fcbcd34c061f64c75c9e4992a9e9f8243272de0 Mon Sep 17 00:00:00 2001 From: Nick Liu Date: Wed, 8 Jul 2020 14:35:39 -0500 Subject: [PATCH] More accurate version generator in e107_make.php build script No longer trips up on hyphens in the tagged releases --- .github/workflows/build-release/OsHelper.php | 21 +++++++++++++++---- .github/workflows/build-release/e107_make.php | 10 ++++----- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build-release/OsHelper.php b/.github/workflows/build-release/OsHelper.php index d99d3d0719..175c39cb90 100644 --- a/.github/workflows/build-release/OsHelper.php +++ b/.github/workflows/build-release/OsHelper.php @@ -10,6 +10,8 @@ class OsHelper { + const REGEX_MATCH_GIT_DESCRIBE_TAGS = "-[0-9]+-g[0-9a-f]+"; + /** * @param string $command The command to run * @param string $stdout Reference to the STDOUT output as a string @@ -52,14 +54,25 @@ public static function runValidated($command, &$stdout = "", &$stderr = "") public static function gitVersionToPhpVersion($gitVersion, $verFileVersion = "0") { - $verFileVersion = explode(" ", $verFileVersion); + $verFileVersion = explode(" ", $verFileVersion); $verFileVersion = array_shift($verFileVersion); $version = preg_replace("/^v/", "", $gitVersion); $versionSplit = explode("-", $version); - if (count($versionSplit) > 1) + $matchGitDescribeTags = self::REGEX_MATCH_GIT_DESCRIBE_TAGS; + if (preg_match("/{$matchGitDescribeTags}$/", $version)) { - if (version_compare($verFileVersion, $versionSplit[0], '>')) $versionSplit[0] = $verFileVersion; - $versionSplit[0] .= "dev"; + $increment = 1; + if (version_compare($verFileVersion, $version, '>')) + { + $increment = 0; + $versionSplit[0] = $verFileVersion; + } + $version = implode("-", $versionSplit); + return preg_replace_callback("/(.*\.)([0-9]+)([^.]*)({$matchGitDescribeTags})$/", + function ($matches) use ($increment) + { + return $matches[1] . ($matches[2] + $increment) . "dev" . $matches[4]; + }, $version); } return implode("-", $versionSplit); } diff --git a/.github/workflows/build-release/e107_make.php b/.github/workflows/build-release/e107_make.php index 2a0abef5c1..0249b0ad7e 100644 --- a/.github/workflows/build-release/e107_make.php +++ b/.github/workflows/build-release/e107_make.php @@ -91,7 +91,7 @@ private function status($msg, $heading = false) } } - private function validateReadme() + private function validateReadme() { //check for readme files associated with configured releases foreach ($this->config['releases'] as $rel) @@ -276,7 +276,7 @@ private function createReleases() $releaseDir = "{$this->config['baseDir']}/target/{$this->config['main']['name']}/release/" . $this->releaseDir; - $this->copyCoreImage($releaseDir . "/core_image.phar"); + $this->copyCoreImage($releaseDir . "/core_image.phar"); /** * git archive -o update.zip HEAD $(git diff --name-only [id]) @@ -312,8 +312,8 @@ private function createReleases() unlink($tarfile); } // end loop - $this->status('Removing export folder', true); - $this->rmdir($this->exportDir); + $this->status('Removing export folder', true); + $this->rmdir($this->exportDir); } private function emptyExportDir() @@ -379,7 +379,7 @@ private function editVersion($dir = 'export') { $version = $this->version; - if (strpos($version, "-") !== false) + if (preg_match("/" . OsHelper::REGEX_MATCH_GIT_DESCRIBE_TAGS . "$/", $version)) { $version .= " nightly build " . date('Ymd'); }