Get thg latest git tag + latest commit date and hash and use it as a laravel app version
Based on TALL Stack Tips
config/version.php
<?php
use Symfony\Component\Yaml\Yaml;
//get the created tag from git
$tag = exec('git describe --tags --abbrev=0');
// defaults to -.-.- if no tag is found
if (empty($tag)) {
$tag = '-.-.-';
}
//get the commit hash
$hash = trim(exec('git log --pretty="%h" -n1 HEAD'));
//get the last commit date
$date = Carbon\Carbon::parse(trim(exec('git log -n1 --pretty=%ci HEAD')))->setTimezone('+03:00');
// available in the app as version.tag, version.hash, version.date or version.string
$array = [
'tag' => $tag,
'date' => $date->format('y-m-d H:i:s'),
'hash' => $hash,
'string' => sprintf('%s-%s (%s)', $tag, $hash, $date->format('d/m/y H:i')),
];
$yaml = Yaml::dump($array);
file_put_contents('../version.yml', $yaml);
return Yaml::parseFile('../version.yml');
usage
config('version')