forked from kvz/system_daemon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.php
executable file
·360 lines (312 loc) · 11.2 KB
/
release.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
#!/usr/bin/php
<?php
error_reporting(E_ALL ^ E_DEPRECATED);
/**
* print_r shortcut
*/
function pr() {
$args = func_get_args();
if (php_sapi_name() !=='cli') {
echo '<pre>'."\n";
}
foreach($args as $arg) {
print_r($arg);
}
if (php_sapi_name() !=='cli') {
echo '</pre>'."\n";
}
}
/**
* print_r & die shortcut
*/
function prd() {
$args = func_get_args();
call_user_func_array('pr', $args);
die();
}
if (!defined('DIR_EGGSHELL')) {
$file = 'EggShell.php';
$lookIn = array(
(@$_ENV['HOME'] ? @$_ENV['HOME'] : '/home/kevin').'/workspace/eggshell/',
'/truecode/eggshell/',
dirname(__FILE__).'/vendors/eggshell/',
);
foreach($lookIn as $dir) {
if (is_dir($dir) && file_exists($dir.$file)) {
define('DIR_EGGSHELL', $dir);
break;
}
}
if (!defined('DIR_EGGSHELL')) {
trigger_error($file.' not found in either: '.implode(', ', $lookIn), E_USER_ERROR);
}
}
require_once DIR_EGGSHELL.$file;
if (!defined('DIR_SCM')) {
$file = 'Scm.php';
$lookIn = array(
(@$_ENV['HOME'] ? @$_ENV['HOME'] : '/home/kevin').'/workspace/scm/',
'/truecode/scm/',
dirname(__FILE__).'/vendors/scm/',
);
foreach($lookIn as $dir) {
if (is_dir($dir) && file_exists($dir.$file)) {
define('DIR_SCM', $dir);
break;
}
}
if (!defined('DIR_SCM')) {
trigger_error($file.' not found in either: '.implode(', ', $lookIn), E_USER_ERROR);
}
}
require_once DIR_SCM.$file;
if (!include('PEAR/PackageFileManager2.php')) {
die('Please: pear install -f PEAR_PackageFileManager-2');
}
Class Release extends EggShell {
public $apiStability;
public $apiVersion;
public $version;
public $dir;
public $name;
public $Pack;
public $Scm;
/**
* Contstructor. Options are passed to every Class contstructor
* and hence available troughout the entire system.
*
* To avoid collission, That's why they're prefixed with scope.
*
* @param array $options
*/
public function __construct($options = array()) {
$this->className = get_class($this);
// Take care of recursion when there are ++++ levels of inheritance
parent::__construct($options);
// Get direct parent defined options
$parentVars = @get_class_vars(@get_parent_class(__CLASS__));
// Override with own defined options
$this->_options = $this->merge((array)@$parentVars['_options'], $this->_options);
// Override with own instance options
$this->_options = $this->merge($this->_options, $options);
$this->dir = $this->_options['app-root'];
$this->name = $this->_options['package-name'];
PEAR::setErrorHandling(PEAR_ERROR_DIE);
$this->Pack = new PEAR_PackageFileManager2();
$this->Scm = new Scm($this->dir);
if (!$this->Scm->scm) {
$this->err('Could not establish SCM');
}
}
public function setVersion($version) {
$this->version = $version;
// Own starts here
if (!$this->version || false === strpos($this->version, 'v')) {
return $this->err('Need to specify a release like: v0.9.2-beta');
}
if (count($parts = explode('-', $this->version)) > 1) {
$this->apiStability = $parts[1];
} else {
$this->apiStability = 'stable';
}
$this->apiVersion = str_replace('v', '', $parts[0]);
}
public function changelog() {
$after = $this->_tagBefore($this->version);
$scmOptions = array(
'duplicates' => false,
'onewords' => false,
'after' => $after,
'until' => 'HEAD',
);
$logs = $this->Scm->logs($scmOptions);
$cl = '';
foreach($logs as $log) {
if (@$log['verbose'] > 0) {
continue;
}
#$cl .= ' * ' . $log['date'] . ' | '.str_pad($log['weight'], 3, ' ', STR_PAD_LEFT) . ' | '. $log['comment']."\n";
$cl .= ' * ' . $log['comment']."\n";
}
file_put_contents($this->dir.'/docs/CHANGELOG', $cl);
echo $cl;
}
protected function _tagBefore($leadTag = null) {
if ($leadTag === null) {
$leadTag = $this->version;
}
$tags = $this->Scm->tags();
// Use last tag as starting point
$after = end($tags);
foreach ($tags as $i=>$tag) {
if ($tag === $leadTag) {
// Tag already exist? Use tag before That, as starting point
if (isset($tags[($i-1)])) {
$after = $tags[($i-1)];
} else {
$after = null;
}
break;
}
}
return $after;
}
protected function _histFile($file, $commit, $losefirstline = false) {
$buf = $this->Scm->getFile($file, $commit);
if ($losefirstline) {
$lines = explode("\n", $buf);
array_shift($lines);
$buf = join("\n", $lines);
}
return $buf;
}
public function updateXML($tag, $firsttime = false) {
$opts = $this->_opts($tag);
$e = $this->Pack->setOptions($opts);
// Oddly enough, this is a PHP source code package...
$this->Pack->setPackageType('php');
// Package name, summary and longer description
$this->Pack->setPackage($this->name);
$this->Pack->setSummary($opts['summary']);
$this->Pack->setDescription($opts['description']);
// The channel where this package is hosted. Since we're installing from a local
// downloaded file rather than a channel we'll pretend it's from PEAR.
$this->Pack->setChannel('pear.php.net');
foreach ($opts['maintainers'] as $line) {
list($role, $nick, $mname, $email, $active) = explode(',', $line);
if ($firsttime) $this->Pack->addMaintainer($role, $nick, $mname, $email, $active);
}
$this->Pack->setNotes($opts['notes']);
// Add any known dependencies such as PHP version, extensions, PEAR installer
if ($firsttime) $this->Pack->setPhpDep('5.1.2'); // spl_autoload_register
if ($firsttime) $this->Pack->setPearinstallerDep('1.4.0');
//if ($firsttime) $this->Pack->addDependency('pcntl', '', 'has', 'ext', true);
//if ($firsttime) $this->Pack->addDependency('posix', '', 'has', 'ext', true);
$this->Pack->setOSInstallCondition('(*ix|*ux|darwin*|*BSD|SunOS*)');
if ($firsttime) $this->Pack->addPackageDepWithChannel('optional', 'Log', 'pear.php.net', '1.0');
// Other info, like the Lead Developers. license, version details
// and stability type
$this->Pack->setLicense('New BSD License',
'http://opensource.org/licenses/bsd-license.php');
$this->Pack->setAPIVersion($this->apiVersion);
$this->Pack->setAPIStability($this->apiStability);
$this->Pack->setReleaseVersion($this->apiVersion);
$this->Pack->setReleaseStability($this->apiStability);
// Add this as a release, and generate XML content
$this->Pack->addRelease();
$this->Pack->generateContents();
if (@$this->_options['debug']) {
return $this->Pack->debugPackageFile();
} else {
return $this->Pack->writePackageFile();
}
}
protected function _opts($tag) {
$summary = $this->_histFile('docs/SUMMARY', $tag);
$description = $this->_histFile('docs/DESCRIPTION', $tag);
$notes = $this->_histFile('docs/NOTES', $tag, true);
$notes = $this->name.' ' . $tag . ' ' . "\n".$notes;
$maintainers = explode("\n", $this->read($this->dir.'/docs/MAINTAINERS'));
$options = array(
'package' => $this->name,
'summary' => $summary,
'maintainers' => $maintainers,
'version' => $this->apiVersion,
'state' => $this->apiStability,
'description' => $description,
'notes' => $notes,
'filelistgenerator' => 'file',
'ignore' => array(
'package2.php',
'package.php',
'package.xml',
'catalog.xml',
'*.tgz',
'.svn',
'.git',
'test.php',
'release.php',
'gitty*',
'.project',
'nbproject/',
'vendors/',
'docs',
'tools/',
),
'simpleoutput' => true,
'clearcontents' => true,
'baseinstalldir' => '/',
'packagedirectory' => $this->dir,
'packagefile' => 'package.xml',
'dir_roles' => array(
'docs' => 'doc',
'examples' => 'doc',
'tests' => 'test',
'data' => 'data',
),
'roles' => array(
'*' => 'php',
),
);
return $options;
}
public function bake($sleep = true) {
$this->changelog();
// if ($sleep) {
// $this->info('Press CTRL+C Now! if you didn\'t make a bullet list in docs/NOTES');
// sleep(5);
// }
// Make tag now so updateXML can find it
// just don't push yet
$this->exe('cd %s && git commit -am "Preparing to release %s" ', $this->dir, $this->version);
$this->Scm->makeTag($this->version, 'HEAD', 'Released new version', false);
@unlink($this->dir.'/package.xml');
$firsttime = true;
$tags = $this->Scm->tags();
usort($tags, 'version_compare');
foreach($tags as $tag) {
$this->updateXML($tag, $firsttime);
$firsttime = false;
}
$this->exe('cd %s && pear package && mv *.tgz ./packages/', $this->dir);
$this->exe('cd %s && git add ./packages/*.tgz', $this->dir);
$this->exe('cd %s && git commit -am "Releasing %s" ', $this->dir, $this->version);
// Overwrite full tag && push
$this->Scm->makeTag($this->version, 'HEAD', 'Released new version', true);
}
}
$Release = new Release(array(
'package-name' => 'System_Daemon',
'log-file' => '/var/log/release.log',
'log-file-level' => 'info',
'app-root' => dirname(__FILE__),
));
switch(@$argv[1]) {
case 'changelog':
$Release->{$argv[1]}();
break;
case 'bake':
// @todo remove false
$Release->setVersion(@$argv[2]);
$Release->{$argv[1]}();
break;
default:
if (@$argv[2] === 'all') {
$tags = $Release->Scm->tags();
} else {
$tags = (array)(@$argv[2]);
}
if (!count($tags)) {
$Release->err('No tags specified?');
exit(1);
}
foreach ($tags as $tag) {
$Release->setVersion($tag);
if (!method_exists($Release, @$argv[1])) {
$Release->err('Method %s does not exist', @$argv[1]);
} else {
$Release->{$argv[1]}();
}
}
break;
}