forked from FreePBX/devtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_tags.php
executable file
·95 lines (89 loc) · 2.95 KB
/
add_tags.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
#!/usr/bin/env php
<?php
require_once('libraries/freepbx.php');
$help = array();
$help[] = array('--directory', 'Directory Location of modules root, always assumed to be ../freepbx from this location');
$help[] = array('--remote', 'The Remote GIT Repository name, Default is origin');
$longopts = array(
'directory::',
'remote',
);
$vars = getopt('d::,r', $longopts);
//if help was requested, show help and exit
if (isset($vars['help'])) {
freepbx::showHelp('Package.php',$help);
exit(0);
}
//determine if we have a .freepbxconfig file in our home directory with
//settings, and setting them as $vars
$freepbx_conf = freepbx::getFreePBXConfig();
if (is_array($freepbx_conf) && !empty($freepbx_conf)) {
foreach($freepbx_conf as $key => $value) {
if (isset($value) && $value != '') {
$vars[$key] = $value;
}
}
}
$vars['directory'] = !empty($vars['directory']) ? $vars['directory'] : dirname(dirname(__FILE__)) . '/freepbx';
$vars['remote'] = (isset($vars['remote'])) ? $vars['remote'] : 'origin';
$modules = glob($vars['directory'].'/*', GLOB_ONLYDIR);
foreach($modules as $mod_dir) {
freepbx::outn("Attempting to open module ".basename($mod_dir)."...");
try {
$repo = Git::open($mod_dir);
freepbx::out("Done");
} catch (Exception $e) {
freepbx::out($e->getMessage());
freepbx::out("Module " . $module . " will not be tagged!");
continue;
}
freepbx::outn("\tFetching remote changes (not applying)...");
$stash = $repo->fetch();
freepbx::out("Done");
$stash = $repo->add_stash();
if(!empty($stash)) {
freepbx::out("\tStashing Uncommited changes..Done");
}
$o = $repo->log_search($greps=array('Module package script', 'Module publish script'), '%h%x09%an%x09%ad%x09%s');
foreach($o as $log) {
$parts = explode("\t",$log);
if(!empty($parts[3]) && preg_match('/(\d*\.\d*)/',$parts[3],$out)
&& version_compare($out[1],'2.10','ge') && version_compare($out[1],'2.13','lt')
&& preg_match('/('.$out[1].'\S*)/',$parts[3],$out)) {
$tag = str_replace(']','',$out[1]);
$tag = str_replace('.tgz','',$tag);
if(!$repo->tag_exist('release/'.$tag)) {
freepbx::outn("\t\tAdding Tag " .$tag." at ".$parts[0]."...");
//add a tag at this point in time
try {
$repo->add_tag('release/'.$tag,null,$parts[0]);
} catch (Exception $e) {
freepbx::out($e->getMessage());
freepbx::out("Module " . $module . " will not be tagged!");
continue;
}
freepbx::out("Done");
}
}
}
try {
$repo->push($vars['remote'], $repo->active_branch());
} catch (Exception $e) {
freepbx::out($e->getMessage());
freepbx::out("Module " . $module . " will not be tagged!");
continue;
}
freepbx::out("Done");
if(!empty($stash)) {
freepbx::outn("\tRestoring Uncommited changes...");
try {
$repo->apply_stash();
$repo->drop_stash();
} catch (Exception $e) {
freepbx::out("Failed to restore stash!, Please check your directory");
freepbx::out("Module " . $module . " will not be tagged!");
continue;
}
freepbx::out("Done");
}
}