Created
August 26, 2015 23:44
-
-
Save duellsy/74e1dd30d2dd0d68fcb3 to your computer and use it in GitHub Desktop.
Git hash creator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace Elevio\Commands; | |
use Illuminate\Console\Command; | |
use Symfony\Component\Console\Input\InputOption; | |
class GitVersion extends Command | |
{ | |
/** | |
* The console command name. | |
* | |
* @var string | |
*/ | |
protected $name = 'venturecraft:gitversion'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'Work out the version number to display and store in local file.'; | |
/** | |
* Execute the console command. | |
* | |
* @return mixed | |
*/ | |
public function fire() | |
{ | |
$version_file = app_path() . '/../elevio_version.txt'; | |
$git_hash_file = app_path() . '/../git_hash.txt'; | |
$short = exec('git rev-parse --short HEAD'); | |
$full = exec('git describe --tags'); | |
$parts = explode('-', $full); | |
$structured = 'N/A'; | |
if (strlen($parts[0])) { | |
$structured = str_replace('v', '', $parts[0]); | |
if (isset($parts[1])) { | |
$structured .= '.' . $parts[1]; | |
} else { | |
$structured .= '.0'; | |
} | |
if ($this->option('include_hash') && isset($parts[2])) { | |
$structured .= ' ' . $parts[2]; | |
} | |
} | |
file_put_contents($git_hash_file, $short); | |
file_put_contents($version_file, $structured); | |
} | |
/** | |
* Get the console command options. | |
* | |
* @return array | |
*/ | |
protected function getOptions() | |
{ | |
return array( | |
array('include_hash', null, InputOption::VALUE_NONE, 'Include commit hash', null), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment