Increase my php laravel project version with every git commit and show in footer

Viewed 1989

I would like to show the version/build in my PHP Laravel project footer in a variable from Git.

I need someway to automatically store, update, commit the build version every time any of my developers do a Git commit using SourceTree/Bitbucket.

It is fine if something is already built into Git and if I can pull this straight from git and use that within my webpage PHP footer. It can be something simple and just reflect a string + timestamp to the second on every commit.

I do not know the best way or anyway to really do this and did not find any information that helped me.

1 Answers

This is usually built using git describe.

See for instance tremby/laravel-git-version

A helper class to get the current git version of the project.

composer require tremby/laravel-git-version
\Tremby\LaravelGitVersion\GitVersionHelper::getVersion()

The GitVersionHelper.php does use:

    // Get version string from git
    $output = shell_exec('git describe --always --tags --dirty');
Related