Skip to content

Commit

Permalink
Semver task can update versions without writing to file
Browse files Browse the repository at this point in the history
  • Loading branch information
DavertMik committed Aug 5, 2014
1 parent 92577bb commit 1817f6d
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 48 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

#### 0.4.5

* [Semver] may accepts version as argument *2014-08-05*
* [Changelog] changed style *2014-06-27*
* [GenMarkDown] fixed formatting annotations *2014-06-27*


#### 0.4.4 06/05/2014

* Output can be disabled in all executable tasks by ->printed(false)
Expand Down
17 changes: 11 additions & 6 deletions RoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,23 @@ public function release()
$this->pharPublish();
}

/**
* Copies robo.phar to /usr/bin
*/
public function pharInstallGlobal()
{
$this->say("Sudo required, copying...");
copy('robo.phar', '/usr/bin/robo');
}

public function test($args = "")
{
return $this->taskCodecept()
->args($args)
->run();
}

public function added($addition)
public function changed($addition)
{
$this->taskChangelog()
->version(\Robo\Runner::VERSION)
Expand All @@ -40,11 +49,7 @@ public function added($addition)

public function versionBump($version = null)
{
if (!$version) {
$versionParts = explode('.', \Robo\Runner::VERSION);
$versionParts[count($versionParts)-1]++;
$version = implode('.', $versionParts);
}
if (!$version) $version = $this->taskSemVer(\Robo\Runner::VERSION)->increment();
$this->taskReplaceInFile(__DIR__.'/src/Runner.php')
->from("VERSION = '".\Robo\Runner::VERSION."'")
->to("VERSION = '".$version."'")
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"henrikbjorn/lurker" : "1.0.*@dev"
},
"require-dev": {
"codeception/codeception": "@dev",
"codeception/codeception": "*",
"codeception/verify": "*",
"codeception/aspect-mock": "*"
}
Expand Down
47 changes: 23 additions & 24 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified robo.phar
100755 → 100644
Binary file not shown.
2 changes: 1 addition & 1 deletion src/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class Runner {
use Output;

const VERSION = '0.4.4';
const VERSION = '0.4.5';
const ROBOCLASS = 'RoboFile';
const ROBOFILE = 'RoboFile.php';

Expand Down
35 changes: 19 additions & 16 deletions src/Task/Development.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ public function run()
if (empty($this->log)) {
return Result::error($this, "Changelog is empty");
}
$text = implode("\n", array_map(function ($i) { return "* $i"; }, $this->log))."\n";
$ver = "#### {$this->version} ".date('m/d/Y')."\n\n";
$text = implode("\n", array_map(function ($i) { return "* $i *".date('Y-m-d')."*"; }, $this->log))."\n";
$ver = "#### {$this->version}\n\n";
$text = $ver . $text;

if (!file_exists($this->filename)) {
Expand Down Expand Up @@ -380,7 +380,7 @@ protected function documentPropertyDocBlock(\ReflectionProperty $reflectedProper
}
}
$propertyDoc = self::indentDoc($propertyDoc, 7);
$propertyDoc = preg_replace("~@(.*?)([$\s])~", ' * `$1` $2', $propertyDoc); // format annotations
$propertyDoc = preg_replace("~^@(.*?)([$\s])~", ' * `$1` $2', $propertyDoc); // format annotations
if (is_callable($this->processPropertyDocBlock)) {
$propertyDoc = call_user_func($this->processPropertyDocBlock, $reflectedProperty, $propertyDoc);
}
Expand All @@ -398,7 +398,7 @@ protected function documentParam(\ReflectionParameter $param)
if ($param->allowsNull()) {
$text .= ' = null';
} else {
$text .= ' = '.$param->getDefaultValue();
$text .= ' = '.str_replace("\n",' ', print_r($param->getDefaultValue(), true));
}
}

Expand Down Expand Up @@ -458,7 +458,7 @@ protected function documentMethodDocBlock(\ReflectionMethod $reflectedMethod)
}

$methodDoc = self::indentDoc($methodDoc, 7);
$methodDoc = preg_replace("~@(.*?)([$\s])~", ' * `$1` $2', $methodDoc); // format annotations
$methodDoc = preg_replace("~^@(.*?) ([$\s])~m", ' * `$1` $2', $methodDoc); // format annotations
if (is_callable($this->processMethodDocBlock)) {
$methodDoc = call_user_func($this->processMethodDocBlock, $reflectedMethod, $methodDoc);
}
Expand Down Expand Up @@ -502,13 +502,19 @@ class SemVerTask implements TaskInterface
'metadata' => ''
];

public function __construct($pathToSemVer = '.semver')
public function __construct($semVerFileOrVersion = '.semver')
{
$this->path = $pathToSemVer;
if (file_exists($semVerFileOrVersion)) {
$this->path = $semVerFileOrVersion;
$version = file_get_contents($this->path);

if (file_exists($this->path)) {
$this->parse();
} elseif (preg_match('~^(\d+)\.(\d+).(\d+)~', $semVerFileOrVersion)) {
$version = $semVerFileOrVersion;
}
if (!preg_match_all(self::REGEX, implode("\n", $version), $matches)) {
throw new TaskException($this, 'Bad semver file.');
}
$this->parse($version);
}

public function __toString()
Expand Down Expand Up @@ -593,6 +599,9 @@ public function metadata($data)

public function run()
{
if (!$this->path) {
throw new TaskException($this, "No semver file specified, use __toString() to get current version");
}
$written = $this->dump();
return new Result($this, (int)($written !== false), $this->__toString());
}
Expand All @@ -604,14 +613,8 @@ protected function dump()
return file_put_contents($this->path, $semver);
}

protected function parse()
protected function parse($version)
{
$output = file_get_contents($this->path);

if (!preg_match_all(self::REGEX, implode("\n", $output), $matches)) {
throw new TaskException($this, 'Bad semver file.');
}

list(, $major, $minor, $patch, $special, $metadata) = array_map('current', $matches);
$this->version = compact('major', 'minor', 'patch', 'special', 'metadata');
}
Expand Down

0 comments on commit 1817f6d

Please sign in to comment.