I'm writing a Symfony Console PHP application which takes a version number in the constructor.
$app = new Application('myapp', '1.0');
I've already found that it's easy to forget to bump the version number when making a new git tag release. How can I do this dynamically/automatically?
Aside from here on SO, I searched packagist pretty deeply because I thought for sure this was a common thing, but wasn't able to turn up anything.
I thought at first to write a function that would do something like this:
chdir(__DIR__);
shell_exec('git describe --abbrev=0 --tags');
But because I globally require this CLI app with composer, it doesn't have the git repository with the source code.
My next idea is that I know I can at least get it from composer
composer global show myname/mypackage
But this spits out a ton of information and there's no option that I'm aware of to just show the version number. I feel like filtering through all this with something like regex might be overkill. Is there any better way?