Laravel/Lumen project git version getter
A helper class to get the current git version of the project., (*1)
Expects either a version
file to exist in the base_path()
of your project
containing a version string, or the git
binary to be available., (*2)
Framework version
This package works with both Laravel 4 and 5, and also Lumen., (*3)
Installation
Require it in your Laravel/Lumen project:, (*4)
composer require tremby/laravel-git-version
Optional packages
This module uses Symfony's Process component if available,
or falls back to shell_exec
otherwise.
So if your deployment environment has shell_exec
disabled,
you can work around this by installing symfony/process
., (*5)
Use
You can get the git version string with, (*6)
\Tremby\LaravelGitVersion\GitVersionHelper::getVersion()
Or you can get your app name and version number such as my-project/1.0
with, (*7)
\Tremby\LaravelGitVersion\GitVersionHelper::getNameAndVersion()
The app's name is taken from Config::get('app.name', 'app')
, so you can
configure it in your config/app.php
file or leave it as the default of app
., (*8)
Recommended usage pattern
Ensure your git tags are pushed to your servers
so that the versions are described properly., (*9)
During development and possibly in staging environments
allow the version to be determined automatically
(this is done via git describe
)., (*10)
As part of your production deployment procedure,
write a version
file (perhaps via a command like
git describe --always --tags --dirty >version
,
since this is the command this package would run otherwise).
When this version
file exists the package will use its contents
rather than executing git
, saving some processor and IO time., (*11)
Add /version
to your .gitignore
file
so your working tree stays clean and you don't accidentally commit it., (*12)
View
A view is provided which just outputs an HTML comment with the return value of
getNameAndVersion()
. I like to include this in the main layout template of the
project., (*13)
To use this, install the service provider by adding it to your config/app.php
file:, (*14)
'providers' => [
...
Tremby\LaravelGitVersion\GitVersionServiceProvider::class,
],
Then the view is available:, (*15)
@include('git-version::version-comment')