codeuptime / app-version-laravel
Access your application version in Laravel
Installs: 1 121
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Requires (Dev)
- orchestra/testbench: ^7.19
- phpunit/phpunit: ^9.5
README
This package makes it easy to access current app version information if your Laravel application at runtime.
This can be helpful when you want/need to:
- inlcude app version number in logs
- include app version in API responses
- show the current app version to your users
- ...
Pre-Requisites
This package relies on current version information being saved in the composer.json
or package.json
files under the version
key.
If you are not currently setting the version of your application in any of these files as part of your CI/CD workflows, you can follow this tutorial to get started: Automatic Version Tagging using Github Actions
Getting Started
Installation
composer require codeuptime/app-version-laravel
Configre App Service Provider
The package should be included in your application automatically using Laravel's package auto-discovery functionality. If this does not work, you can always add the service provider manually to your config/app.php
// 'config/app.php' <?php 'providers' => [ // Other Service Providers \CodeUptime\AppVersionLaravel\VersionServiceProvider::class ],
Usage
You can now get your application version 2 ways:
Get current version
version() // = "1.6.0" \CodeUptime\AppVersionLaravel\Version::current() // = "1.6.0"
The current version logic checks the composer.json and package.json files for the version
key in that order. As soon as a version value is found, that value is returned.
Get composer.json version
\CodeUptime\AppVersionLaravel\Version::composer() // = "1.2.0" from composer.json
Get package.json version
\CodeUptime\AppVersionLaravel\Version::package() // = "1.2.0" from package.json
Get version information from all files
\CodeUptime\AppVersionLaravel\Version::info()
this one returns a \stdClass object containing all version information
{
"composer": "1.2.0"
"package": "1.2.0"
}
Artisan Commands
There are cases where you would like to use the application version number in your scripts and automated workflows. This package provides two commands
version
This command just returns the current version string. This makes it very usable as part of your CI/CD scripts or adding this version to other build artifacts such as API docs.
php artisan version
1.6.0
version:info
This command is helpful when evaluating automation or debugging
php artisan version:info
+----------+---------+
| Source | Version |
+----------+---------+
| composer | 1.6.0 |
| package | 1.6.0 |
+----------+---------+
version:set-in-json-file --file=/path/to/some/file.json --path=path.to.some.key.in.json.object
This command sets the current version number to a key in a json file. This can be in automated CI/CD pipelines that publish OpenAPI or Swagger based documentation and you want to include the application version with your documentation bundle.
version:set-in-json-file --file={openapi.json} --path=info.version