-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathpackage_all.php
More file actions
executable file
·155 lines (134 loc) · 4.55 KB
/
package_all.php
File metadata and controls
executable file
·155 lines (134 loc) · 4.55 KB
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
#!/usr/bin/env php
<?php
/**
* Copyright 2013 by Schmooze Com, Inc.
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* @author bryan.walters => schmoozecom ! com
*
* options:
* run with --help for options
*
*/
require_once('libraries/freepbx.php');
//get cli opts
$longopts = array(
'version:',
'directory:',
'help::'
);
$vars = getopt('d:v:h::', $longopts);
$helpArray = array(
array('--help', 'Show this menu and exit'),
array('--version', 'release/15.0'),
array('--directory', 'Directory Location of modules root, always assumed to be ../freepbx from this location')
);
//if help was requested, show help and exit
if (isset($vars['h'])) {
freepbx::out(freepbx::showHelp(basename(__FILE__), $helpArray, true));
exit(0);
}
if(isset($vars['help'])) {
freepbx::out(freepbx::showHelp(basename(__FILE__), $helpArray));
exit(0);
}
//setup some other settings
$vars['directory'] = !empty($vars['directory']) ? $vars['directory'] : dirname(dirname(__FILE__)) . '/freepbx';
$vars['version'] = !empty($vars['version']) ? $vars['version'] : (!empty($vars['v']) ? $vars['v'] : '');
if(empty($vars['version'])) {
freepbx::out("Must Define Version!");
exit();
}
$allmods = glob($vars['directory'].'/*', GLOB_ONLYDIR);
foreach($allmods as $mod) {
$modules[] = str_replace($vars['directory'] . '/', '', $mod);
}
//display our log on a per module basis, based on the last tag
foreach($modules as $module) {
$moddir = $vars['directory'].'/'.$module;
if (!file_exists($moddir)) {
freepbx::out('Module '.$module.' does not exist in path: '.$vars['directory']);
exit(1);
} else {
try {
$repo = Git::open($moddir);
} catch(\Exception $e) {
freepbx::out('Not a valid path: '.$vars['directory'].'/'.$module);
continue;
}
$repo->fetch();
$branches = $repo->list_remote_branches();
freepbx::out('================================== ' . $module . ' START =========================================');
if(in_array('origin/release/'.$vars['version'],$branches,true)) {
$status = $repo->status();
if(empty($status)) {
freepbx::out('Found '.$vars['version'].' in this module');
$repo->checkout('release/'.$vars['version']);
$repo->pull('origin','release/'.$vars['version']);
if(needsPublish($moddir)) {
freepbx::out('Needs to be published');
$supported = freepbx::check_xml_file($moddir)[2]['version'];
if($supported !== $vars['version']) {
freepbx::out('Supported version needs to be updated');
$xml = simplexml_load_file($moddir . '/module.xml');
$xml->supported->version = $vars['version'];
$xml = trim(preg_replace('/^\<\?xml.*?\?\>/', '', $xml->asXML()));
file_put_contents($moddir . '/module.xml', $xml);
}
system(__DIR__.'/package.php -m '.$module.' --skipunittests --publish --bump');
} else {
freepbx::out('Nothing to publish');
}
} else {
freepbx::out('There are working changes in this module. Cant switch branches');
print_r($status);
}
} else {
freepbx::out($vars['version'].' does not exist in this module');
}
freepbx::out('================================== ' . $module . ' STOP =========================================');
}
}
/**
* Check Log
*
* This function finds that last tag for the current release and shows you
* any changes between them
*
* @param The git module directory
* @return String of `git log` output
*/
function needsPublish($moddir) {
$repo = Git::open($moddir);
$ltags = $repo->list_tags();
if ($ltags === false) {
return 'No Tags found!';
}
list($rawname, $ver, $supported) = freepbx::check_xml_file($moddir);
//Get current module version
preg_match('/(\d*\.\d*)\./i',$ver,$matches);
$rver = $matches[1];
//cycle through the tags and create a new array with relavant tags
$tagArray = array();
foreach ($ltags as $tag) {
if(preg_match('/release\/(.*)/i',$tag,$matches) && (strpos($matches[1],$rver) !== false)) {
$tagArray[] = $matches[1];
}
}
if (!empty($tagArray)) {
usort($tagArray,"freepbx::version_compare_freepbx");
$htag = array_pop($tagArray);
$tagref = $repo->show_ref_tag($htag);
$out = $repo->log($tagref,'HEAD');
return !empty($out);
}
return true;
}