{"id":13563915,"url":"https://github.com/antonioribeiro/version","last_synced_at":"2025-05-15T02:06:15.198Z","repository":{"id":27041922,"uuid":"112244465","full_name":"antonioribeiro/version","owner":"antonioribeiro","description":"Laravel App versioning","archived":false,"fork":false,"pushed_at":"2024-08-21T20:00:12.000Z","size":316,"stargazers_count":592,"open_issues_count":26,"forks_count":108,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-05-05T14:09:21.275Z","etag":null,"topics":["laravel","php","versioning"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/antonioribeiro.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-27T20:22:58.000Z","updated_at":"2025-04-04T15:14:54.000Z","dependencies_parsed_at":"2024-06-07T09:12:38.418Z","dependency_job_id":"3f66f806-0b33-4184-8cab-98480b7976d2","html_url":"https://github.com/antonioribeiro/version","commit_stats":{"total_commits":204,"total_committers":12,"mean_commits":17.0,"dds":0.08823529411764708,"last_synced_commit":"f82ce182d453ff07a2f82280ac047faac15d63fc"},"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonioribeiro%2Fversion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonioribeiro%2Fversion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonioribeiro%2Fversion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonioribeiro%2Fversion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/antonioribeiro","download_url":"https://codeload.github.com/antonioribeiro/version/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252744622,"owners_count":21797654,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","php","versioning"],"created_at":"2024-08-01T13:01:24.512Z","updated_at":"2025-05-15T02:06:15.180Z","avatar_url":"https://github.com/antonioribeiro.png","language":"PHP","funding_links":[],"categories":["PHP","Laravel Packages"],"sub_categories":[],"readme":"# Version\n### Take control over your Laravel app version\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"docs/screenshot.png\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://packagist.org/packages/pragmarx/version\"\u003e\u003cimg alt=\"Latest Stable Version\" src=\"https://img.shields.io/packagist/v/pragmarx/version.svg?style=flat-square\"\u003e\u003c/a\u003e\n    \u003ca href=\"/antonioribeiro/version/blob/master/LICENSE.md\"\u003e\u003cimg alt=\"License\" src=\"https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://scrutinizer-version.com/g/antonioribeiro/version/?branch=master\"\u003e\u003cimg alt=\"Code Quality\" src=\"https://img.shields.io/scrutinizer/g/antonioribeiro/version.svg?style=flat-square\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://scrutinizer-version.com/g/antonioribeiro/version/?branch=master\"\u003e\u003cimg alt=\"Build\" src=\"https://img.shields.io/scrutinizer/build/g/antonioribeiro/version.svg?style=flat-square\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://scrutinizer-version.com/g/antonioribeiro/version/?branch=master\"\u003e\u003cimg alt=\"Coverage\" src=\"https://img.shields.io/scrutinizer/coverage/g/antonioribeiro/version.svg?style=flat-square\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://styleci.io/repos/112244465\"\u003e\u003cimg alt=\"StyleCI\" src=\"https://styleci.io/repos/112244465/shield\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/pragmarx/version\"\u003e\u003cimg alt=\"Downloads\" src=\"https://img.shields.io/packagist/dt/pragmarx/version.svg?style=flat-square\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## Description\n\nThis package is a Laravel (5.5+) utility which helps you keep and manage your application version, increment version numbers (major, minor, patch, commit), and can also use your last commit hash.\n\n#### The end results of this package are:\n\n- Print a version on a page.\n- Print it in the console, via an Artisan command.\n\n#### Full SemVer compatibility\n\nThis package is able to parse a SemVer version:\n\n```\nv2.0.1-alpha.1227\n```\n\nAnd translate it to be used as:\n\n```\nlabel: v\nmajor: 2\nminor: 0\npatch: 1\nprerelease: alpha\nbuildmetadata: 1227\ncommit: 49ffe2\n```\n\nYou can use the format function to rewrite and show it in your app, for instance, as:\n\n```\nMyApp version 2.0.1 - alpha 1227 (commit 49ffe2)\n```\n\n#### Some use cases for those results could be: \n \n- Make sure a rollback was successful.\n- Know if an update reached all servers.\n- Check if a user is looking at the last version of your app.\n- Verify if is Travis CI testing the version it is supposed to be testing.\n- You simple love to version your stuff, and you like to see them in all your pages? That's cool too. :)\n- What's your use case? [Tell us!](https://github.com/antonioribeiro/version/issues/new) \n\n## Features\n\n### Easily control you app version using a YAML config file\n\n``` yaml\nversion: \n    current:\n        major: 1\n        minor: 0\n        patch: 0\n        format: '{$major}.{$minor}.{$patch}'\n    commit:\n        mode: number\n        number: 701036\n```\n\n### Use your git commit as your app commit hash/number\n\nConfigure it\n\n``` yaml\ncommit:\n    mode: git-local\n```\n\nAnd you may have an output like this\n\n```\nMyApp version 1.0.0 (commit a9c03f)\n```\n\nOr just use an incremental commit hash/number:\n\n``` yaml\ncommit:\n    mode: number\n    number: 701036\n```\n\nTo get\n\n```\nMyApp version 1.0.0 (commit 701036)\n```\n\n### Easily increment your version numbers, using Artisan commands\n\n``` bash\nphp artisan version:commit\n```\n\nWhich should print the new version number \n\n``` bash\nNew commit: 701037\nMyApp version 1.0.0 (commit 701037) \n```\n\nAvailable for all of them:\n\n``` bash\n$ php artisan version:major   \n$ php artisan version:minor   \n$ php artisan version:patch   \n$ php artisan version:build   \n``` \n\n### The output format is highly configurable\n\nYou can configure the :\n\n``` yaml\nformat:\n  version: \"{$major}.{$minor}.{$patch}\"\n  full: \"version {{'format.version'}} (commit {$commit})\"\n  compact: \"v{{'format.version'}}-{$commit}\"\n```\n\nThose are the results for `full` and `compact` formats\n\n```\nMyApp version 1.0.0 (commit 701037)\nMyApp v1.0.0-701037\n```\n\nIt gives you access to dynamic methods:\n\n``` php\nVersion::compact()\n```\n\nAnd should you create a new one:\n\n``` yaml\nformat:\n  awesome: \"awesome version {$major}.{$minor}.{$patch}\"\n```\n\nIt will also become callable:\n\n``` php\nVersion::awesome()\n```\n \n### A Facade is available\n\n``` php\nVersion::version() // 1.2.25\n\nVersion::commit() // 703110\n\nVersion::major() // 1\n\nVersion::minor() // 2\n\nVersion::patch() // 25\n\nVersion::format('full') // version 1.0.0 (commit 703110)\n\nVersion::full() // version 1.0.0 (commit 703110) -- dynamic method\n\nVersion::format('compact') // v.1.0.0-703110\n\nVersion::compact() // v.1.0.0-703110 -- dynamic method\n```\n\n### Instantiating it\n\nIf you prefer not to use the Façade:\n\n``` php\ndd(\n    Version::format()\n);\n```\n\nThe best ways to instantiate it are:\n\nA simple PHP object instantiation:\n\n``` php\n$version = new \\PragmaRX\\Version\\Package\\Version();\n\ndd(\n    $version-\u003eformat()\n);\n```\n\nOr to get an already instantiated Version object from the container:\n\n``` php\ndd(\n    app(\\PragmaRX\\Version\\Package\\Version::class)-\u003eformat()\n);\n```\n\nBut you have to make sure you [published the config file](/install)\n\n### A Blade directive is also ready to be used in your views\n\nYou can use this directive to render a full version format:\n\n``` php\n@version\n```\n\nOr choose the format:\n\n``` php\n@version('full')\n@version('compact')\n```\n\nYou can configure the directive name:\n\n``` yaml\nblade_directive: printversion\n```\n\nThen \n\n``` php\n@printversion('compact')\n```\n\n### Git tags\n\nYou can use your git tags as application versions, all you need is to set the version source to \"git\":\n\n``` yaml\nversion_source: git\n```\n\nAnd if you add a commit hash/number to your tags:\n\n``` bash\n$ git tag -a -f v0.1.1.3128\n```\n\nVersion will use it as your app commit hash/number\n\n### Matching other version (git tags) formats\n\nYou probably only need to change the git version matcher \n\n``` yaml\ngit:\n  ...\n  version:\n    matcher: \"/[V|v]*[ersion]*\\\\s*\\\\.*(\\\\d+)\\\\.(\\\\d+)\\\\.(\\\\d+)\\\\.*(\\\\w*)/\"\n```\n\nSo let's say you tag your releases as \n\n``` text\n2017120299\nYYYYMMDD##\n```\n\nYou can change your matcher to\n\n``` yaml\ngit:\n  version:\n    matcher: \"/(\\d{4})(\\d{2})(\\d{2})(?:\\d{2})/\"\n```\n\nAnd remove dots from your formats:\n\n``` yaml\nformat:\n  compact: \"v{$major}{$minor}{$patch}-{$commit}\"\n```\n\n### Using the current application version in your code \n\nHere's a community example on how to send the app version number when logging an exception to Bugsnag:\n\n```\n\u003c?php\n\nnamespace App\\Exceptions;\n\nuse PragmaRX\\Version\\Package\\Version;\nuse Bugsnag\\BugsnagLaravel\\Facades\\Bugsnag;\n\nclass Handler extends ExceptionHandler\n{\n    public function report(Exception $exception)\n    {\n        if ($this-\u003eshouldReport($exception)) {\n            Bugsnag::setAppVersion((new Version())-\u003eformat('version'));\n            Bugsnag::notifyException($exception);\n        }\n    }\n}\n``` \n\n### Commit Timestamp\n\nThis package also lets you absorb the last commit timestamp or store the current date to the version.yml file. This is the format in the config file:\n\n```\ntimestamp:\n  year:\n  month:\n  day:\n  hour:\n  minute:\n  second:\n  timezone:\n```\n\nTo absorb you only need to configure `mode: absorb` then execute:\n\nphp artisan version:absorb\n\nBut you can also set `mode: increment` then execute:\n\n```\nphp artisan version:timestamp\n```\n\nTo store the current date and time to the config file:\n\n``` text\n$ php artisan version:minor\nNew timestamp: 2019-09-16 18:23:03\nMyApp version 2.3.2 (commit 49ffe2)\n```\n\nAnd you can then use it to show in your app:\n\n```\nVersion::format('timestamp-full')\n```\n\n### Artisan commands\n\nThose are the commands you have at your disposal:\n\n#### version:show\n\nShow the current app version:\n\n``` text\n$ php artisan version:show\nPragmaRX version 1.0.0 (build 701031)\n\n$ php artisan version:show --format=compact\nPragmaRX v1.0.0-701031\n\n$ php artisan version:show --format=compact --suppress-app-name\nv1.0.0-701031\n```\n\n#### version:absorb\n\nYou need to set `mode: absorb`.\n\nVersion can absorb git version and commit to the config file, so you can delete the .git folder and still keep your version and commit for fast access. You have to configure `git_absorb` in your config file:\n\n``` yaml\ncommit:\n  #...  \n  git_absorb: git-local # \"false\", \"git-local\" or \"git-remote\"\n```\n\nAnd run it \n\n``` bash\n$ php artisan version:absorb\n```\n\nThe usual configuration setup to implement absorb is:\n\n``` yaml\nversion_source: config             ## must be set as config\ncurrent:\n    major: 1                       ## |\n    minor: 0                       ## | --\u003e will be changed by absorb\n    patch: 0                       ## |\n    git_absorb: git-local          ## configure to get from local or remote\ncommit:\n    mode: number                   ## must be set as number\n    number: f477c8                 ## will be changed by absorb\n    git_absorb: git-local          ## configure to get from local or remote \n```\n\n#### version:(major|minor|patch|commit)\n\nYou need to set `mode: increment`.\n\nIncrement the version item:\n\n``` text\n$ php artisan version:minor\nNew minor version: 5\nMyApp version 1.5.0 (commit 701045)\n```\n\n#### Regex Matcher\n\nThis is the current regex used to break a version string:\n\n````\n^(?P\u003clabel\u003e[v|V]*[er]*[sion]*)[\\.|\\s]*(?P\u003cmajor\u003e0|[1-9]\\d*)\\.(?P\u003cminor\u003e0|[1-9]\\d*)\\.(?P\u003cpatch\u003e0|[1-9]\\d*)(?:-(?P\u003cprerelease\u003e(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+(?P\u003cbuildmetadata\u003e[0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$\n````\n\nYou can test it online: https://regex101.com/r/Ly7O1x/42\n\n## Install\n\nVia Composer\n\n``` bash\n$ composer require pragmarx/version\n```\n\nThen publish the configuration file you'll have to:\n\n``` bash\n$ php artisan vendor:publish --provider=\"PragmaRX\\Version\\Package\\ServiceProvider\"\n```\n\nAnd you should be good to use it in your views:\n\n``` php\n@version\n```\n\nAs git versions are cached, you can tell composer to refresh your version numbers every time an update or install occur, by adding the refresh command to `post-autoload-dump`:  \n\n``` json\n\"post-autoload-dump\": [\n    ...\n    \"@php artisan version:refresh\"\n]\n```\n\n[Optional] You may also can automated this process by set inside your `.git/hooks/post-commit`. It will automatic run the command once you have make a commit.\n\n``` bash\n#!/bin/sh\n\nphp artisan version:refresh\n```\n\nIf you are using Git commits on your commit numbers, you may have to add the git repository to your .env file\n\n``` text\nVERSION_GIT_REMOTE_REPOSITORY=https://github.com/antonioribeiro/version.git\n```\n\n**If you are using `git-local` make sure the current folder is a git repository**\n\n## Minimum requirements\n\n- Laravel 5.5\n- PHP 7.0\n\n## Testing\n\n``` bash\n$ composer test\n```\n\n## Troubleshooting\n\n- If you are having trouble to install because of symfony/router (3.3/3.4) or symfony/yaml (3.3/3.4), you can try to:\n\n```\nrm -rf vendor\nrm composer.lock\ncomposer install\n```\n\n## Author\n\n[Antonio Carlos Ribeiro](http://twitter.com/iantonioribeiro)\n\n## License\n\nThis package is licensed under the MIT License - see the `LICENSE` file for details\n\n## Contributing\n\nPull requests and issues are welcome.\n\n\n\u003c!-- [![Downloads](https://img.shields.io/packagist/dt/pragmarx/version.svg?style=flat-square)](https://packagist.org/packages/pragmarx/version) --\u003e \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantonioribeiro%2Fversion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantonioribeiro%2Fversion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantonioribeiro%2Fversion/lists"}