Last active
June 15, 2018 12:14
-
-
Save joaorobertopb/e48979f1bbfa6c3afd89d20449970f27 to your computer and use it in GitHub Desktop.
Get latest git tag version with PHP.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (! function_exists('git_version')) { | |
/** | |
* Get latest git tag version. | |
* | |
* @return string | |
*/ | |
function git_version() | |
{ | |
$gitCommand = 'git describe --tags $(git rev-list --tags --max-count=1)'; | |
if (class_exists('Symfony\Component\Process\Process')) { | |
$process = (new Symfony\Component\Process\Process($gitCommand))->run(); | |
return trim($process->getOutput()); | |
} | |
return trim(exec($gitCommand)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment