forked from consolidation/robo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RoboFile.php
189 lines (165 loc) · 5.59 KB
/
RoboFile.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?php
use Robo\Task\Development\Changelog;
use Robo\Task\Development\taskDevelopment;
use Symfony\Component\Finder\Finder;
class Robofile extends \Robo\Tasks
{
public function release()
{
$this->yell("Releasing Robo");
$this->docs();
$this->taskGitStack()
->add('-A')
->commit("auto-update")
->pull()
->push()
->run();
$this->taskGitStack()
->add('-A')
->commit("auto-update")
->pull()
->push()
->run();
$this->taskGitHubRelease(\Robo\Runner::VERSION)
->uri('Codegyre/Robo')
->askDescription()
->run();
$this->pharPublish();
$this->versionBump();
}
public function test($args = "")
{
return $this->taskCodecept()
->args($args)
->run();
}
public function changed($addition)
{
$this->taskChangelog()
->version(\Robo\Runner::VERSION)
->change($addition)
->run();
}
public function versionBump($version = null)
{
if (!$version) {
$versionParts = explode('.', \Robo\Runner::VERSION);
$versionParts[count($versionParts)-1]++;
$version = implode('.', $versionParts);
}
$this->taskReplaceInFile(__DIR__.'/src/Runner.php')
->from("VERSION = '".\Robo\Runner::VERSION."'")
->to("VERSION = '".$version."'")
->run();
}
/**
* generate docs
*/
public function docs()
{
$docs = [];
foreach (get_declared_classes() as $task) {
if (!preg_match('~Robo\\\Task.*?Task$~', $task)) continue;
$docs[basename((new ReflectionClass($task))->getFileName(),'.php')][] = $task;
}
ksort($docs);
$taskGenerator = $this->taskGenDoc('docs/tasks.md')->filterClasses(function (\ReflectionClass $r) {
return !$r->isAbstract() or $r->isTrait();
})->prepend("# Tasks");
foreach ($docs as $file => $classes) {
$taskGenerator->docClass("Robo\\Task\\$file");
foreach ($classes as $task) {
$taskGenerator->docClass($task);
}
}
$taskGenerator->filterMethods(function(\ReflectionMethod $m) {
if ($m->isConstructor() or $m->isDestructor() or $m->isStatic()) return false;
return !in_array($m->name, ['run', '', '__call', 'getCommand']) and $m->isPublic(); // methods are not documented
})->processClassSignature(function ($c) {
return "## ". preg_replace('~Task$~', '', $c->getShortName())."\n";
})->processClassDocBlock(function($c, $doc) {
return preg_replace('~@method .*?\wTask (.*?)\)~', '* `$1)` ', $doc);
})->processMethodSignature(function (\ReflectionMethod $m, $text) {
return str_replace('#### *public* ', '* `', $text) . '`';
})->processMethodDocBlock(function(\ReflectionMethod $m, $text) {
return $text ? ' ' . strtok($text, "\n") : '';
})->run();
}
public function pharBuild()
{
$packer = $this->taskPackPhar('robo.phar');
$this->taskComposerInstall()
->noDev()
->printed(false)
->run();
$files = Finder::create()->ignoreVCS(true)
->files()
->name('*.php')
->path('src')
->path('vendor')
->in(__DIR__);
foreach ($files as $file) {
$packer->addFile($file->getRelativePathname(), $file->getRealPath());
}
$packer->addFile('robo','robo')
->executable('robo')
->run();
$this->taskComposerInstall()
->printed(false)
->run();
}
public function pharInstall()
{
$this->taskExec('sudo cp')
->arg('robo.phar')
->arg('/usr/bin/robo')
->run();
}
public function pharPublish()
{
$this->pharBuild();
rename('robo.phar', 'robo-release.phar');
$this->taskGitStack()->checkout('gh-pages')->run();
rename('robo-release.phar', 'robo.phar');
$this->taskGitStack()
->add('robo.phar')
->commit('robo.phar published')
->push('origin','gh-pages')
->checkout('master')
->run();
}
public function tryWatch()
{
$this->taskWatch()->monitor(['composer.json', 'composer.lock'], function() {
$this->taskComposerUpdate()->run();
})->run();
}
public function tryInput()
{
$answer = $this->ask('how are you?');
$this->say('You are '.$answer);
$yes = $this->confirm('Do you want one more question?');
if (!$yes) return;
$lang = $this->askDefault('what is your favorite scripting language?', 'PHP');
$this->say($lang);
$pin = $this->askHidden('Ok, now tell your PIN code (it is hidden)');
$this->yell('Ha-ha, your pin code is: '.$pin);
$this->say('Bye!');
}
/**
* Test parallel execution
*/
public function tryPara()
{
$this->taskParallelExec()
->process('php ~/demos/robotests/parascript.php hey')
->process('php ~/demos/robotests/parascript.php hoy')
->process('php ~/demos/robotests/parascript.php gou')
->process('php ~/demos/robotests/parascript.php die')
->run();
}
public function optbool($opts = ['silent|s' => false])
{
if (!$opts['silent']) $this->say("Hello, world");
}
}