feat: 버전 표기에 branch명 같이 표기

This commit is contained in:
2021-11-26 18:44:18 +09:00
parent d50c409315
commit 7f4205601d
2 changed files with 37 additions and 4 deletions
+16 -2
View File
@@ -6,12 +6,26 @@ class VersionGitDynamic
{ {
static function getVersion() static function getVersion()
{ {
$versionTokens = [];
$command = 'git describe --long --tags'; $command = 'git describe --long --tags';
exec($command, $output); exec($command, $output);
if (is_array($output)) { if (is_array($output)) {
$output = join('', $output); $versionTokens[] = trim(join('', $output));
} }
return trim($output);
$command = 'git branch --contains HEAD';
exec($command, $output);
if (is_array($output)) {
if (count($output)) {
$output = $output[1];
$versionTokens[] = trim($output, " \t\n\r\0\x0b*");
} else {
$versionTokens[] = 'unknown';
}
}
return join('-', $versionTokens);
} }
static function getHash() static function getHash()
+21 -2
View File
@@ -7,6 +7,8 @@ set_time_limit(600);
function getVersion($target = null) function getVersion($target = null)
{ {
$versionTokens = [];
if ($target) { if ($target) {
$command = sprintf('git describe %s --long --tags', escapeshellarg($target)); $command = sprintf('git describe %s --long --tags', escapeshellarg($target));
} else { } else {
@@ -14,9 +16,26 @@ function getVersion($target = null)
} }
exec($command, $output); exec($command, $output);
if (is_array($output)) { if (is_array($output)) {
$output = join('', $output); $versionTokens[] = trim(join('', $output));
} }
return trim($output);
if ($target) {
$command = sprintf('git branch --contains %s', escapeshellarg($target));
} else {
$command = 'git branch --contains HEAD';
}
exec($command, $output);
if (is_array($output)) {
if(count($output)){
$output = $output[1];
$versionTokens[] = trim($output, " \t\n\r\0\x0b*");
}
else{
$versionTokens[] = 'unknown';
}
}
return join('-', $versionTokens);
} }
function getHash($target = 'HEAD') function getHash($target = 'HEAD')