1
0
mirror of https://github.com/e107inc/e107.git synced 2025-10-28 12:16:03 +01:00

More accurate version generator in e107_make.php build script

No longer trips up on hyphens in the tagged releases
This commit is contained in:
Nick Liu
2020-07-08 14:35:39 -05:00
parent b0376d7689
commit 3fcbcd34c0
2 changed files with 22 additions and 9 deletions

View File

@@ -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 @@ class OsHelper
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);
}