Create wrapper around versioning library to update on builds

This commit is contained in:
Nabeel Shahzad
2018-01-06 17:00:47 -06:00
parent b8e00a3ee1
commit 94c0eb8502
4 changed files with 73 additions and 25 deletions
+2 -1
View File
@@ -19,7 +19,8 @@ if [ "$TRAVIS" = "true" ]; then
cd $TRAVIS_BUILD_DIR cd $TRAVIS_BUILD_DIR
php artisan version:show --format compact --suppress-app-name > VERSION #php artisan version:show --format compact --suppress-app-name > VERSION
php artisan phpvms:version --write > VERSION
VERSION=`cat VERSION` VERSION=`cat VERSION`
echo "Version: $VERSION" echo "Version: $VERSION"
+20 -6
View File
@@ -31,21 +31,35 @@ class BaseCommand extends Command
/** /**
* @param $cmd * @param $cmd
* @param bool $return
* @return string
*/ */
public function runCommand($cmd) public function runCommand($cmd, $return=false, $verbose=true)
{ {
if (is_array($cmd)) if (\is_array($cmd)) {
$cmd = join(' ', $cmd); $cmd = join(' ', $cmd);
}
$this->info('Running "' . $cmd . '"'); if($verbose) {
$this->info('Running "' . $cmd . '"');
}
$val = '';
$process = new Process($cmd); $process = new Process($cmd);
$process->run(function ($type, $buffer) { $process->run(function ($type, $buffer) use ($return, $val) {
if (Process::ERR === $type) { if ($return) {
echo $buffer; $val .= $buffer;
} else { } else {
echo $buffer; echo $buffer;
} }
/*if (Process::ERR === $type) {
echo $buffer;
} else {
echo $buffer;
}*/
}); });
return $val;
} }
} }
+34
View File
@@ -0,0 +1,34 @@
<?php
namespace App\Console\Commands;
use App\Console\BaseCommand;
use Symfony\Component\Yaml\Yaml;
class Version extends BaseCommand
{
protected $signature = 'phpvms:version {--write}';
/**
* Run dev related commands
* @throws \Symfony\Component\Yaml\Exception\ParseException
*/
public function handle()
{
if($this->option('write')) {
$version_file = config_path('version.yml');
$cfg = Yaml::parse(file_get_contents($version_file));
exec($cfg['git']['git-local'], $version);
$version = substr($version[0], 0, 6);
$cfg['build']['number'] = $version;
file_put_contents($version_file, Yaml::dump($cfg, 4, 2));
}
$this->call('version:show', [
'--format' => 'compact',
'--suppress-app-name' => true
]);
}
}
+17 -18
View File
@@ -1,29 +1,28 @@
version_source: config # "config", "git-local" or "git-remote" version_source: config
current: current:
major: 7 major: 7
minor: 0 minor: 0
patch: 0 patch: 0
git_absorb: git-local git_absorb: git-local
format: "{$major}.{$minor}.{$patch}" format: '{$major}.{$minor}.{$patch}'
build: build:
mode: number mode: number
number: 451e9e number: 18cb95
git_absorb: git-local git_absorb: git-local
git: git:
git-local: "git rev-parse --verify HEAD" git-local: 'git rev-parse --verify HEAD'
git-remote: "git ls-remote {$repository}" git-remote: 'git ls-remote {$repository}'
branch: "refs/heads/master" branch: refs/heads/master
repository: "{{ env('VERSION_GIT_REMOTE_REPOSITORY') }}" repository: '{{ env(''VERSION_GIT_REMOTE_REPOSITORY'') }}'
version: version:
git-local: "git describe" git-local: 'git describe'
git-remote: "git ls-remote {$repository} | grep tags/ | grep -v {} | cut -d \/ -f 3 | sort --version-sort | tail -1" git-remote: 'git ls-remote {$repository} | grep tags/ | grep -v {} | cut -d / -f 3 | sort --version-sort | tail -1'
matcher: "/[V|v]*[ersion]*\\s*\\.*(\\d+)\\.(\\d+)\\.(\\d+)\\.*(\\w*)/" matcher: '/[V|v]*[ersion]*\s*\.*(\d+)\.(\d+)\.(\d+)\.*(\w*)/'
format: format:
major: "{$major}" major: '{$major}'
minor: "{$minor}" minor: '{$minor}'
patch: "{$patch}" patch: '{$patch}'
build: "{$build}" build: '{$build}'
version: "{$major}.{$minor}.{$patch} (build {$build})" version: '{$major}.{$minor}.{$patch} (build {$build})'
full: "version {{'format.version'}}" full: 'version {{''format.version''}}'
compact: "v{$major}.{$minor}.{$patch}-{$build}" compact: 'v{$major}.{$minor}.{$patch}-{$build}'
## add as many formats as you need !!!!