Last active
December 28, 2022 10:31
-
-
Save breadthe/ce6a815b295c485b4bd91c08a79e1bf2 to your computer and use it in GitHub Desktop.
Display app git tag & commit hash in a Laravel app
This file contains 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
// resources/views/app/version.blade.php | |
<div> | |
<span>{{ config('version.string') }}</span> | |
<span>&mdsh;</span> | |
<span>{{ config('app.env') }}</span> | |
<span>—</span> | |
<span>{{ 'Laravel ' . app()->version() }}</span> | |
<span>—</span> | |
<span>{{ app()->getLocale() }}</span> | |
<span>—</span> | |
<span>{{ 'PHP ' . PHP_VERSION }}</span> | |
</div> |
This file contains 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 | |
// config/version.php | |
// Based on this tweet by @Xewl https://twitter.com/Xewl/status/1459219464369627144 | |
$tag = exec('git describe --tags --abbrev=0'); | |
if (empty($tag)) { | |
$tag = '-.-.-'; | |
} | |
$hash = trim(exec('git log --pretty="%h" -n1 HEAD')); | |
$date = Carbon\Carbon::parse(trim(exec('git log -n1 --pretty=%ci HEAD'))); | |
return [ | |
'tag' => $tag, | |
'date' => $date, | |
'hash' => $hash, | |
'string' => sprintf('%s-%s (%s)', $tag, $hash, $date->format('d/m/y H:i')); | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment