Skip to content

Instantly share code, notes, and snippets.

@dade80vr
Last active January 2, 2020 10:17
Show Gist options
  • Save dade80vr/66ca4f47e50a2b21e37bfe6214ed633e to your computer and use it in GitHub Desktop.
Save dade80vr/66ca4f47e50a2b21e37bfe6214ed633e to your computer and use it in GitHub Desktop.
[PHP] Auto git versioning by last tag + commit counter
class QuickVersioning {
/*
Auto versioning by Git TAG + COMMIT
by Davide Permunian - https://github.com/dade80vr
*/
public static function version() {
exec('git describe --abbrev=0 --tags',$last_tags);
if (count($last_tags)>0) {
$mainver = $last_tags[0];
}else{
$mainver = "v0"; #if there are no tag
}
exec('git describe --always',$version_mini_hash);
exec('git rev-list HEAD',$version_number);
exec('git log -1',$line);
$version['short'] = "<b>".$mainver."</b>.".count($version_number);
$version['medium'] = "<b>".$mainver."</b>.".count($version_number).".".$version_mini_hash[0];
$version['long'] = "<b>".$mainver."</b>.".count($version_number).".$version_mini_hash[0] (".str_replace('commit ','',$line[0]).")";
return $version;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment