phpvms/app/Console/Commands/Version.php

65 lines
1.6 KiB
PHP
Raw Normal View History

<?php
namespace App\Console\Commands;
use App\Console\Command;
use Symfony\Component\Yaml\Yaml;
/**
* Class Version
*/
class Version extends Command
{
protected $signature = 'phpvms:version {--write} {--base-only}';
/**
* Create the version number that gets written out
2018-08-27 00:40:04 +08:00
*
* @param mixed $cfg
2018-08-27 02:51:47 +08:00
*
2018-08-27 02:50:08 +08:00
* @return bool|string
*/
protected function createVersionNumber($cfg)
{
exec($cfg['git']['git-local'], $version);
$version = substr($version[0], 0, $cfg['build']['length']);
2018-08-27 00:40:04 +08:00
// prefix with the date in YYMMDD format
$date = date('ymd');
$version = $date.'-'.$version;
return $version;
}
/**
* Run dev related commands
2018-08-27 00:40:04 +08:00
*
* @throws \Symfony\Component\Yaml\Exception\ParseException
*/
public function handle()
{
$version_file = config_path('version.yml');
$cfg = Yaml::parse(file_get_contents($version_file));
2018-08-27 00:40:04 +08:00
// Get the current build id
2018-03-08 00:24:29 +08:00
$build_number = $this->createVersionNumber($cfg);
$cfg['build']['number'] = $build_number;
$c = $cfg['current'];
$version = "v{$c['major']}.{$c['minor']}.{$c['patch']}-{$build_number}";
if ($this->option('write')) {
file_put_contents($version_file, Yaml::dump($cfg, 4, 2));
}
2018-08-27 00:40:04 +08:00
// Only show the major.minor.patch version
if ($this->option('base-only')) {
$version = 'v'.$cfg['current']['major'].'.'
.$cfg['current']['minor'].'.'
.$cfg['current']['patch'];
}
2018-08-27 00:40:04 +08:00
echo $version."\n";
}
}