2022-09-05 08:33:08 +02:00
|
|
|
#!/usr/bin/env php -qC
|
2009-06-01 13:53:03 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2014-04-19 12:43:02 +02:00
|
|
|
* EGroupware - checkout, build and release archives, build Debian and rpm packages
|
2009-06-01 13:53:03 +02:00
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @author RalfBecker@outdoor-training.de
|
2019-02-25 10:46:06 +01:00
|
|
|
* @copyright (c) 2009-19 by Ralf Becker <rb@egroupware.org>
|
2009-06-01 13:53:03 +02:00
|
|
|
*/
|
|
|
|
|
2013-09-10 19:29:58 +02:00
|
|
|
if (php_sapi_name() !== 'cli') // security precaution: forbit calling setup-cli as web-page
|
2009-06-01 13:53:03 +02:00
|
|
|
{
|
2011-06-05 12:30:30 +02:00
|
|
|
die('<h1>checkout-build-archives.php must NOT be called as web-page --> exiting !!!</h1>');
|
2009-06-01 13:53:03 +02:00
|
|
|
}
|
2010-05-25 22:26:52 +02:00
|
|
|
date_default_timezone_set('Europe/Berlin'); // to get ride of 5.3 warnings
|
2009-06-01 13:53:03 +02:00
|
|
|
|
|
|
|
$verbose = 0;
|
|
|
|
$config = array(
|
2019-08-06 14:38:32 +02:00
|
|
|
'packagename' => 'egroupware-docker',
|
2022-09-20 13:42:38 +02:00
|
|
|
'version' => '22.1',
|
2016-05-25 15:07:03 +02:00
|
|
|
'packaging' => date('Ymd'), // '20160520'
|
|
|
|
'branch' => 'master', // checked out branch
|
|
|
|
'tag' => '$version.$packaging', // name of tag
|
2022-09-20 13:42:38 +02:00
|
|
|
'checkoutdir' => '~/epl-22.1-checkout', //realpath(__DIR__.'/../..'),
|
|
|
|
'egw_buildroot' => '/tmp/build_root/epl_22.1_buildroot',
|
|
|
|
'sourcedir' => '~/download/archives/egroupware-22.1',
|
2019-07-16 10:46:59 +02:00
|
|
|
/* svn-config no longer used
|
2016-05-25 15:07:03 +02:00
|
|
|
'svntag' => 'tags/$version.$packaging',
|
2014-04-19 12:43:02 +02:00
|
|
|
'svnbase' => 'svn+ssh://svn@dev.egroupware.org/egroupware',
|
|
|
|
'stylitebase' => 'svn+ssh://stylite@svn.stylite.de/stylite',
|
2016-05-25 15:07:03 +02:00
|
|
|
'svnbranch' => 'branches/16.1', //'trunk', // 'branches/1.6' or 'tags/1.6.001'
|
2014-04-19 12:43:02 +02:00
|
|
|
'svnalias' => 'aliases/default-ssh', // default alias
|
2020-05-25 15:05:58 +02:00
|
|
|
'extra' => array('$stylitebase/$svnbranch/stylite', '$stylitebase/$svnbranch/esyncpro'), //'$stylitebase/trunk/archive'),//, '$stylitebase/$svnbranch/groups'), //,'svn+ssh://stylite@svn.stylite.de/stylite/trunk/eventmgr'),
|
2016-05-25 15:07:03 +02:00
|
|
|
*/
|
2019-09-17 10:47:20 +02:00
|
|
|
// create an extra archive for given apps
|
2021-03-16 08:30:34 +01:00
|
|
|
'extra' => array('functions' => array('stylite'), 'esyncpro', 'policy', 'webauthn', 'kanban',
|
2016-05-25 15:07:03 +02:00
|
|
|
// these apps are placed in egroupware-epl-contrib archive
|
2019-07-16 10:46:59 +02:00
|
|
|
//'contrib' => array('phpgwapi', 'etemplate', 'jdots', 'phpbrain', 'wiki', 'sitemgr')
|
|
|
|
),
|
2014-04-19 12:43:02 +02:00
|
|
|
'aliasdir' => 'egroupware', // directory created by the alias
|
2016-05-27 11:51:57 +02:00
|
|
|
'types' => array('tar.bz2','tar.gz','zip','all.tar.bz2'),
|
|
|
|
// add given extra-apps or (uncompressed!) archives to above all.tar.bz2 archive
|
2019-07-16 10:46:59 +02:00
|
|
|
'all-add' => array('contrib'),
|
2015-01-21 11:08:16 +01:00
|
|
|
// diverse binaries we need
|
|
|
|
'svn' => trim(`which svn`),
|
2019-07-16 15:30:40 +02:00
|
|
|
'tar' => trim(`which gnutar` ?: `which tar`), // tar on MacOS does not support --owner or --group
|
2015-01-21 11:08:16 +01:00
|
|
|
'mv' => trim(`which mv`),
|
2016-05-25 15:07:03 +02:00
|
|
|
'rm' => trim(`which rm`),
|
2015-01-21 11:08:16 +01:00
|
|
|
'zip' => trim(`which zip`),
|
2016-05-27 12:21:52 +02:00
|
|
|
'bzip2' => trim(`which bzip2`),
|
2015-01-21 11:08:16 +01:00
|
|
|
'clamscan' => trim(`which clamscan`),
|
|
|
|
'freshclam' => trim(`which freshclam`),
|
2016-05-25 15:07:03 +02:00
|
|
|
'git' => trim(`which git`),
|
2015-01-21 11:08:16 +01:00
|
|
|
'gpg' => trim(`which gpg`),
|
|
|
|
'editor' => trim(`which vi`),
|
2021-03-29 15:07:44 +02:00
|
|
|
'rsync' => trim(`which rsync`).' --progress -e ssh --exclude "*-stylite-*" --exclude "*-esyncpro-*" --exclude "*-policy-*" --exclude "*-webauthn-*" --exclude "*-kanban-*"',
|
2019-02-25 10:46:06 +01:00
|
|
|
'composer' => trim(`which composer.phar`),
|
2016-06-04 11:03:04 +02:00
|
|
|
'after-checkout' => 'rm -rf */source */templates/*/source',
|
2017-10-21 13:39:05 +02:00
|
|
|
'packager' => 'build@egroupware.org',
|
2019-07-16 10:46:59 +02:00
|
|
|
'obs' => '~/build.opensuse.org/server:eGroupWare:trunk/egroupware-docker',
|
2014-04-19 16:15:29 +02:00
|
|
|
'obs_package_alias' => '', // name used in obs package, if different from packagename
|
2014-04-19 12:43:02 +02:00
|
|
|
'changelog' => false, // eg. '* 1. Zeile\n* 2. Zeile' for debian.changes
|
2017-10-21 13:39:05 +02:00
|
|
|
'changelog_packager' => 'Ralf Becker <rb@egroupware.org>',
|
2016-05-25 15:07:03 +02:00
|
|
|
'editchangelog' => '* ',
|
|
|
|
//'sfuser' => 'ralfbecker',
|
|
|
|
//'release' => '$sfuser,egroupware@frs.sourceforge.net:/home/frs/project/e/eg/egroupware/eGroupware-$version/eGroupware-$version.$packaging/',
|
2016-06-06 17:14:02 +02:00
|
|
|
// what gets uploaded with upload
|
2020-05-25 13:34:05 +02:00
|
|
|
'upload' => '$sourcedir/*$packagename-$version.$packaging*',
|
2016-01-26 13:48:14 +01:00
|
|
|
'copychangelog' => '$sourcedir/README', //'$sfuser,egroupware@frs.sourceforge.net:/home/frs/project/e/eg/egroupware/README',
|
2009-06-01 13:53:03 +02:00
|
|
|
'skip' => array(),
|
2019-07-16 15:30:40 +02:00
|
|
|
'run' => array('checkout','editchangelog','tag','copy','virusscan','create','sign',/*'obs',*/'copychangelog','release'),
|
2011-06-05 12:30:30 +02:00
|
|
|
'patchCmd' => '# run cmd after copy eg. "cd $egw_buildroot; patch -p1 /path/to/patch"',
|
2016-05-25 15:07:03 +02:00
|
|
|
'github_user' => 'ralfbecker', // Github user for following token
|
|
|
|
'github_token' => '', // Github repo personal access token from above user
|
2009-06-01 13:53:03 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
// process config from command line
|
|
|
|
$argv = $_SERVER['argv'];
|
|
|
|
$prog = array_shift($argv);
|
|
|
|
|
|
|
|
while(($arg = array_shift($argv)))
|
|
|
|
{
|
|
|
|
if ($arg == '-v' || $arg == '--verbose')
|
|
|
|
{
|
|
|
|
++$verbose;
|
|
|
|
}
|
|
|
|
elseif($arg == '-h' || $arg == '--help')
|
|
|
|
{
|
2016-06-04 11:03:04 +02:00
|
|
|
if (in_array('editchangelog', $config['skip']) || !in_array('editchangelog', $config['run']))
|
|
|
|
{
|
|
|
|
$config['changelog'] = parse_current_changelog(true);
|
|
|
|
}
|
2009-06-01 13:53:03 +02:00
|
|
|
usage();
|
|
|
|
}
|
|
|
|
elseif(substr($arg,0,2) == '--' && isset($config[$name=substr($arg,2)]))
|
|
|
|
{
|
|
|
|
$value = array_shift($argv);
|
|
|
|
switch($name)
|
|
|
|
{
|
|
|
|
case 'extra': // stored as array and allow to add/delete items with +/- prefix
|
|
|
|
case 'types':
|
|
|
|
case 'skip':
|
|
|
|
case 'run':
|
2016-06-04 11:03:04 +02:00
|
|
|
case 'types':
|
|
|
|
case 'add-all':
|
|
|
|
case 'modules':
|
|
|
|
$op = '=';
|
|
|
|
if (in_array($value[0], array('+', '-')))
|
2009-06-01 13:53:03 +02:00
|
|
|
{
|
2016-06-04 11:03:04 +02:00
|
|
|
$op = $value[0];
|
|
|
|
$value = substr($value, 1);
|
2009-06-01 13:53:03 +02:00
|
|
|
}
|
2016-06-04 11:03:04 +02:00
|
|
|
if (in_array($value[0], array('[', '{')) && ($json = json_decode($value, true)))
|
2009-06-01 13:53:03 +02:00
|
|
|
{
|
2016-06-04 11:03:04 +02:00
|
|
|
$value = $json;
|
2009-06-01 13:53:03 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-04 11:03:04 +02:00
|
|
|
$value = array_unique(preg_split('/[ ,]+/', $value));
|
|
|
|
}
|
|
|
|
switch($op)
|
|
|
|
{
|
|
|
|
case '+':
|
|
|
|
$config[$name] = array_unique(array_merge($config[$name], $value));
|
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
$config[$name] = array_diff($config[$name], $value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$config[$name] = $value;
|
2009-06-01 13:53:03 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-05-25 22:26:52 +02:00
|
|
|
case 'svntag':
|
2016-05-25 15:07:03 +02:00
|
|
|
case 'tag':
|
2014-04-19 12:43:02 +02:00
|
|
|
case 'release':
|
|
|
|
case 'copychangelog':
|
2010-05-25 22:26:52 +02:00
|
|
|
$config[$name] = $value;
|
2015-01-21 11:08:16 +01:00
|
|
|
if ($value) array_unshift($config['run'],$name);
|
2010-05-25 22:26:52 +02:00
|
|
|
break;
|
2011-06-05 12:30:30 +02:00
|
|
|
|
2016-05-25 15:07:03 +02:00
|
|
|
case 'editchangelog':
|
2010-08-08 15:13:03 +02:00
|
|
|
$config[$name] = $value ? $value : true;
|
2016-05-25 15:07:03 +02:00
|
|
|
if (!in_array('editchangelog',$config['run']))
|
2010-08-08 15:13:03 +02:00
|
|
|
{
|
2016-05-25 15:07:03 +02:00
|
|
|
array_unshift($config['run'],'editchangelog');
|
2010-08-08 15:13:03 +02:00
|
|
|
}
|
|
|
|
break;
|
2010-05-25 22:26:52 +02:00
|
|
|
|
2010-03-05 16:09:13 +01:00
|
|
|
case 'obs':
|
|
|
|
if (!is_dir($value))
|
|
|
|
{
|
|
|
|
usage("Path '$value' not found!");
|
|
|
|
}
|
|
|
|
if (!in_array('obs',$config['run'])) $config['run'][] = 'obs';
|
|
|
|
// fall through
|
2009-06-01 13:53:03 +02:00
|
|
|
default:
|
|
|
|
$config[$name] = $value;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
usage("Unknown argument '$arg'!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($verbose > 1)
|
|
|
|
{
|
2016-06-04 11:03:04 +02:00
|
|
|
echo "Using following config:\n".json_encode($config, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES)."\n\n";
|
2009-06-01 13:53:03 +02:00
|
|
|
}
|
2019-07-16 10:46:59 +02:00
|
|
|
// translate everything, so we dont have in each and every place
|
|
|
|
foreach(array_keys($config) as $name)
|
|
|
|
{
|
|
|
|
$config[$name] = config_translate($name);
|
|
|
|
}
|
2009-06-01 13:53:03 +02:00
|
|
|
$svn = $config['svn'];
|
|
|
|
|
2016-06-04 11:03:04 +02:00
|
|
|
$run = array_diff($config['run'],$config['skip']);
|
|
|
|
|
|
|
|
// if we dont edit the changelog, set packaging from changelog
|
|
|
|
if (!in_array('editchangelog', $run))
|
|
|
|
{
|
|
|
|
parse_current_changelog(true);
|
|
|
|
}
|
|
|
|
foreach($run as $func)
|
2009-06-01 13:53:03 +02:00
|
|
|
{
|
2014-04-19 12:43:02 +02:00
|
|
|
chdir(dirname(__FILE__)); // make relative filenames work, if other command changes dir
|
2010-08-08 15:13:03 +02:00
|
|
|
call_user_func('do_'.$func);
|
|
|
|
}
|
|
|
|
|
2016-05-25 15:07:03 +02:00
|
|
|
/**
|
|
|
|
* Read changelog for given branch from (last) tag or given revision from svn
|
|
|
|
*
|
|
|
|
* @param string $_path relativ path to repo starting with $config['aliasdir']
|
|
|
|
* @param string $log_pattern =null a preg regular expression or start of line a log message must match, to be returned
|
|
|
|
* if regular perl regular expression given only first expression in brackets \\1 is used,
|
|
|
|
* for a start of line match, only the first line is used, otherwise whole message is used
|
|
|
|
* @param string& $last_tag =null from which tag on to query logs
|
|
|
|
* @param string $prefix ='* ' prefix, which if not presend should be added to all log messages
|
|
|
|
* @return string with changelog
|
|
|
|
*/
|
|
|
|
function get_changelog_from_git($_path, $log_pattern=null, &$last_tag=null, $prefix='* ')
|
|
|
|
{
|
|
|
|
//echo __FUNCTION__."('$branch_url','$log_pattern','$revision','$prefix')\n";
|
|
|
|
global $config;
|
|
|
|
|
2017-10-21 14:17:20 +02:00
|
|
|
$changelog = '';
|
2016-05-25 15:07:03 +02:00
|
|
|
$path = str_replace($config['aliasdir'], $config['checkoutdir'], $_path);
|
|
|
|
if (!file_exists($path) || !is_dir($path) || !file_exists($path.'/.git'))
|
|
|
|
{
|
|
|
|
throw new Exception("$path is not a git repository!");
|
|
|
|
}
|
|
|
|
if (empty($last_tag))
|
|
|
|
{
|
|
|
|
$last_tag = get_last_git_tag();
|
|
|
|
}
|
2017-10-21 14:17:20 +02:00
|
|
|
if (!empty($last_tag))
|
2016-05-25 15:07:03 +02:00
|
|
|
{
|
2017-10-21 14:17:20 +02:00
|
|
|
$cmd = $config['git'].' log '.escapeshellarg($last_tag.'..HEAD');
|
|
|
|
if (getcwd() != $path) $cmd = 'cd '.$path.'; '.$cmd;
|
|
|
|
$output = null;
|
|
|
|
run_cmd($cmd, $output);
|
|
|
|
|
|
|
|
foreach($output as $line)
|
2016-05-25 15:07:03 +02:00
|
|
|
{
|
2017-10-21 14:17:20 +02:00
|
|
|
if (substr($line, 0, 4) == " " && ($msg = _match_log_pattern(substr($line, 4), $log_pattern, $prefix)))
|
|
|
|
{
|
|
|
|
$changelog .= $msg."\n";
|
|
|
|
}
|
2016-05-25 15:07:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $changelog;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-07-16 10:46:59 +02:00
|
|
|
* Get module path (starting with $config['aliasdir']) per repo
|
2016-05-25 15:07:03 +02:00
|
|
|
*
|
|
|
|
* @return array with $repro_url => $path => $url, eg. array(
|
|
|
|
* "git@github.com:EGroupware/egroupware.git" => array(
|
|
|
|
* "egroupware" => "git@github.com:EGroupware/egroupware.git"),
|
|
|
|
* "git@github.com:EGroupware/tracker.git" => array(
|
|
|
|
* "egroupware/tracker" => "git@github.com:EGroupware/tracker.git"),
|
2019-02-25 10:46:06 +01:00
|
|
|
* "git@github.com:EGroupware/epl" => array(
|
|
|
|
* "egroupware/stylite" => git@github.com:EGroupware/epl"),
|
2016-05-25 15:07:03 +02:00
|
|
|
*/
|
|
|
|
function get_modules_per_repo()
|
|
|
|
{
|
|
|
|
global $config, $verbose;
|
|
|
|
|
2019-07-16 10:46:59 +02:00
|
|
|
if ($verbose) echo "Get modules from checkoutdir $config[checkoutdir]\n";
|
2016-05-25 15:07:03 +02:00
|
|
|
|
2019-07-16 10:46:59 +02:00
|
|
|
$checkoutdir = config_translate('checkoutdir');
|
|
|
|
if (!is_dir($checkoutdir))
|
2016-05-25 15:07:03 +02:00
|
|
|
{
|
2019-07-16 10:46:59 +02:00
|
|
|
throw new Exception("checkout directory '$checkoutdir does NOT exists or is NO directory!");
|
2016-05-25 15:07:03 +02:00
|
|
|
}
|
|
|
|
$modules = array();
|
2019-02-25 10:46:06 +01:00
|
|
|
foreach(scandir($config['checkoutdir']) as $module)
|
2016-05-25 15:07:03 +02:00
|
|
|
{
|
2019-07-16 10:46:59 +02:00
|
|
|
if ($module === '..' || !file_exists($checkoutdir.'/'.$module.'/.git'))
|
2016-05-25 15:07:03 +02:00
|
|
|
{
|
2019-02-25 10:46:06 +01:00
|
|
|
continue;
|
2016-05-25 15:07:03 +02:00
|
|
|
}
|
2019-02-25 10:46:06 +01:00
|
|
|
$output = $matches = null;
|
2019-07-16 10:46:59 +02:00
|
|
|
run_cmd($cmd='cd '.$checkoutdir.'/'.$module.'; '.$config['git'].' remote -v', $output);
|
2019-02-25 10:46:06 +01:00
|
|
|
if (!preg_match('/^origin\s+(.*)\s+\(push\)$/m', implode("\n", $output), $matches))
|
2016-05-25 15:07:03 +02:00
|
|
|
{
|
2019-02-25 10:46:06 +01:00
|
|
|
throw new Exception("Could not parse output of ".implode("\n", $output));
|
2016-05-25 15:07:03 +02:00
|
|
|
}
|
2019-02-25 10:46:06 +01:00
|
|
|
$repo = $matches[1];
|
|
|
|
$modules[$repo][$config['aliasdir'].($module !== '.' ? '/'.$module : '')] = $repo;
|
2016-05-25 15:07:03 +02:00
|
|
|
}
|
|
|
|
if ($verbose) print_r($modules);
|
|
|
|
return $modules;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get commit of last git tag matching a given pattern
|
|
|
|
*
|
|
|
|
* @return string name of last tag matching $config['version'].'.*'
|
|
|
|
*/
|
|
|
|
function get_last_git_tag()
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
if (!is_dir($config['checkoutdir']))
|
|
|
|
{
|
|
|
|
throw new Exception("checkout directory '{$config['checkoutdir']} does NOT exists or is NO directory!");
|
|
|
|
}
|
|
|
|
chdir($config['checkoutdir']);
|
|
|
|
|
|
|
|
$cmd = $config['git'].' tag -l '.escapeshellarg($config['version'].'.*');
|
|
|
|
$output = null;
|
|
|
|
run_cmd($cmd, $output);
|
2017-10-21 14:17:20 +02:00
|
|
|
array_shift($output);
|
2016-05-25 15:07:03 +02:00
|
|
|
|
|
|
|
return trim(array_pop($output));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checkout or update EGroupware
|
|
|
|
*
|
|
|
|
* Ensures an existing checkout is from the correct branch! Otherwise it get's deleted
|
|
|
|
*/
|
|
|
|
function do_checkout()
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
echo "Starting checkout/update\n";
|
|
|
|
if (!file_exists($config['checkoutdir']))
|
|
|
|
{
|
|
|
|
$cmd = $config['git'].' clone '.(!empty($config['branch']) ? ' -b '.$config['branch'] : '').
|
|
|
|
' git@github.com:EGroupware/egroupware.git '.$config['checkoutdir'];
|
|
|
|
run_cmd($cmd);
|
|
|
|
}
|
|
|
|
elseif (!is_dir($config['checkoutdir']) || !is_writable($config['checkoutdir']))
|
|
|
|
{
|
2019-02-25 10:46:06 +01:00
|
|
|
throw new Exception("checkout directory '{$config['checkoutdir']} exists and is NO directory or NOT writable!");
|
2016-05-25 15:07:03 +02:00
|
|
|
}
|
|
|
|
chdir($config['checkoutdir']);
|
|
|
|
|
2019-02-25 10:46:06 +01:00
|
|
|
run_cmd('./install-cli.php --ignore-platform-reqs --no-dev');
|
2016-05-25 15:07:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a tag using mr in svn or git for current checked out branch
|
|
|
|
*/
|
|
|
|
function do_tag()
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
if (!is_dir($config['checkoutdir']))
|
|
|
|
{
|
|
|
|
throw new Exception("checkout directory '{$config['checkoutdir']} does NOT exists or is NO directory!");
|
|
|
|
}
|
|
|
|
chdir($config['checkoutdir']);
|
|
|
|
|
|
|
|
$config['tag'] = config_translate('tag'); // allow to use config vars like $version in tag
|
|
|
|
|
|
|
|
if (empty($config['tag'])) return; // otherwise we copy everything in svn root!
|
|
|
|
|
2019-02-25 10:46:06 +01:00
|
|
|
echo "Creating tag and pushing $config[tag]\n";
|
2016-05-25 15:07:03 +02:00
|
|
|
|
2019-02-25 10:46:06 +01:00
|
|
|
run_cmd('./install-cli.php --git tag -f '.escapeshellarg($config['tag']).' -m '.escapeshellarg('Creating '.$config['tag']));
|
|
|
|
|
|
|
|
// push tags in all apps (not main-dir!)
|
|
|
|
run_cmd('./install-cli.php --git-apps push -f origin '.escapeshellarg($config['tag']));
|
|
|
|
|
|
|
|
// checkout tag, update composer.{json,lock}, move tag to include them
|
|
|
|
run_cmd($config['git'].' checkout '.$config['tag']);
|
|
|
|
update_composer_json_version($config['tag']);
|
|
|
|
// might require more then one run, as pushed tags need to be picked up by packagist
|
|
|
|
$output = $ret = null;
|
2021-09-23 10:51:22 +02:00
|
|
|
$timeout = 30;
|
2022-04-06 13:10:35 +02:00
|
|
|
$try = 0;
|
|
|
|
$cmd = $config['composer'].' update --ignore-platform-reqs --no-dev --prefer-source egroupware/\*';
|
2021-09-23 10:51:22 +02:00
|
|
|
while(run_cmd($cmd, $output, 2))
|
2019-02-25 10:46:06 +01:00
|
|
|
{
|
2021-09-23 10:51:22 +02:00
|
|
|
++$try;
|
|
|
|
error_log("$try. retry in $timeout seconds ...");
|
2019-02-25 10:46:06 +01:00
|
|
|
sleep($timeout);
|
|
|
|
}
|
|
|
|
run_cmd($config['git'].' commit -m '.escapeshellarg('Updating dependencies for '.$config['tag']).' composer.{json,lock}');
|
|
|
|
run_cmd($config['git'].' tag -f '.escapeshellarg($config['tag']).' -m '.escapeshellarg('Creating '.$config['tag']));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update composer.json with version number (or add it after "name" if not yet there)
|
|
|
|
*
|
|
|
|
* @param string $version
|
|
|
|
* @throws Exception on error
|
|
|
|
*/
|
|
|
|
function update_composer_json_version($version)
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
if (!($json = file_get_contents($path=$config['checkoutdir'].'/composer.json')))
|
|
|
|
{
|
|
|
|
throw new Exception("Can NOT read $path to update with new version!");
|
|
|
|
}
|
|
|
|
if (preg_match('/"version":\s*"[^"]+"/', $json))
|
|
|
|
{
|
|
|
|
$json = preg_replace('/"version":\s*"[^"]+"/', '"version": "'.$version.'"', $json);
|
|
|
|
}
|
|
|
|
elseif (preg_replace('/^(\s*)"name":\s*"[^"]+",$/m', $json))
|
|
|
|
{
|
|
|
|
$json = preg_replace('/^(\s*)"name":\s*"[^"]+",$/m', '$0'."\n".'$1"version": "'.$version.'",', $json);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new Exception("Failed to add new version to $path!");
|
|
|
|
}
|
|
|
|
if (!file_put_contents($path, $json))
|
|
|
|
{
|
|
|
|
throw new Exception("Can NOT update $path with new version!");
|
|
|
|
}
|
2016-05-25 15:07:03 +02:00
|
|
|
}
|
|
|
|
|
2014-04-19 12:43:02 +02:00
|
|
|
/**
|
|
|
|
* Release sources by rsync'ing them to a distribution / download directory
|
|
|
|
*/
|
|
|
|
function do_release()
|
|
|
|
{
|
|
|
|
global $config,$verbose;
|
|
|
|
|
2019-02-25 10:46:06 +01:00
|
|
|
// push local changes to Github incl. tag (tags of apps are already pushed by do_tag)
|
2016-05-25 15:07:03 +02:00
|
|
|
if ($verbose) echo "Pushing changes and tags\n";
|
|
|
|
chdir($config['checkoutdir']);
|
2019-07-16 15:30:40 +02:00
|
|
|
// gives error "fatal: you are not on a branch" run_cmd($config['git'].' push');
|
2016-05-25 15:07:03 +02:00
|
|
|
$tag = config_translate('tag');
|
2019-02-25 10:46:06 +01:00
|
|
|
run_cmd($config['git'].' push -f origin '.$tag);
|
|
|
|
// checkout release-branch again (we are on the tag!)
|
2020-05-25 13:34:05 +02:00
|
|
|
run_cmd($config['git'].' checkout '.$config['branch']);
|
2016-05-25 15:07:03 +02:00
|
|
|
|
2019-07-16 15:30:40 +02:00
|
|
|
if (!empty($config['github_user']) || empty($config['github_token']))
|
|
|
|
{
|
|
|
|
echo "GitHub token for '$config[github_user]': ";
|
|
|
|
$config['github_token'] = readline();
|
|
|
|
}
|
2016-05-25 15:07:03 +02:00
|
|
|
if (empty($config['github_user']) || empty($config['github_token']))
|
|
|
|
{
|
|
|
|
throw new Exception("No personal Github user or access token specified (--github_token)!");
|
|
|
|
}
|
|
|
|
if (empty($config['changelog']))
|
|
|
|
{
|
|
|
|
$config['changelog'] = parse_current_changelog();
|
|
|
|
}
|
|
|
|
$data = array(
|
|
|
|
'tag_name' => $tag,
|
|
|
|
'name' => $tag,
|
|
|
|
'target_commitish' => $config['branch'],
|
|
|
|
'body' => $config['changelog'],
|
2019-07-16 10:46:59 +02:00
|
|
|
'draft' => false,
|
|
|
|
'prerelease' => true, // create as prerelease first, as we need it for testing
|
2016-05-25 15:07:03 +02:00
|
|
|
);
|
|
|
|
$response = github_api("/repos/EGroupware/egroupware/releases", $data);
|
2016-06-06 17:14:02 +02:00
|
|
|
$config['upload_url'] = preg_replace('/{\?[^}]+}$/', '', $response['upload_url']); // remove {?name,label} template
|
2016-05-25 15:07:03 +02:00
|
|
|
|
2016-06-06 17:14:02 +02:00
|
|
|
do_upload();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Upload archives
|
|
|
|
*/
|
|
|
|
function do_upload()
|
|
|
|
{
|
|
|
|
global $config,$verbose;
|
|
|
|
|
|
|
|
if (empty($config['upload_url']))
|
|
|
|
{
|
|
|
|
$response = github_api("/repos/EGroupware/egroupware/releases", array(), 'GET');
|
|
|
|
$config['upload_url'] = preg_replace('/{\?[^}]+}$/', '', $response[0]['upload_url']); // remove {?name,label} template
|
|
|
|
}
|
|
|
|
|
|
|
|
$archives = config_translate('upload');
|
2016-06-06 17:24:44 +02:00
|
|
|
echo "Uploading $archives to $config[upload_url]\n";
|
2016-05-25 15:07:03 +02:00
|
|
|
|
2016-06-06 17:24:44 +02:00
|
|
|
foreach(glob($archives, GLOB_BRACE) as $path)
|
2016-05-25 15:07:03 +02:00
|
|
|
{
|
|
|
|
$label = null;
|
|
|
|
if (substr($path, -4) == '.zip')
|
|
|
|
{
|
|
|
|
$content_type = 'application/zip';
|
|
|
|
}
|
|
|
|
elseif(substr($path, -7) == '.tar.gz')
|
|
|
|
{
|
|
|
|
$content_type = 'application/x-gzip';
|
|
|
|
}
|
|
|
|
elseif(substr($path, -8) == '.tar.bz2')
|
|
|
|
{
|
|
|
|
$content_type = 'application/x-bzip2';
|
|
|
|
}
|
|
|
|
elseif(substr($path, -8) == '.txt.asc')
|
|
|
|
{
|
|
|
|
$content_type = 'text/plain';
|
|
|
|
$label = 'Signed hashes of downloads';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2016-06-06 17:14:02 +02:00
|
|
|
if ($verbose) echo "Uploading $path as $content_type\n";
|
2016-05-25 15:07:03 +02:00
|
|
|
$name = basename($path);
|
2016-06-06 17:14:02 +02:00
|
|
|
github_api($config['upload_url'], array(
|
2016-05-25 15:07:03 +02:00
|
|
|
'name' => $name,
|
|
|
|
'label' => isset($label) ? $label : $name,
|
|
|
|
), 'FILE', $path, $content_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($config['release']))
|
|
|
|
{
|
|
|
|
$target = config_translate('release'); // allow to use config vars like $svnbranch in module
|
|
|
|
$cmd = $config['rsync'].' '.$archives.' '.$target;
|
|
|
|
if ($verbose) echo $cmd."\n";
|
|
|
|
passthru($cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sending a Github API request
|
|
|
|
*
|
|
|
|
* @param string $_url url of just path where to send request to (https://api.github.com is added automatic)
|
|
|
|
* @param string|array $data payload, array get automatic added as get-parameter or json_encoded for POST
|
|
|
|
* @param string $method ='POST'
|
|
|
|
* @param string $upload =null path of file to upload, payload for request with $method='FILE'
|
|
|
|
* @param string $content_type =null
|
|
|
|
* @throws Exception
|
|
|
|
* @return array with response
|
|
|
|
*/
|
|
|
|
function github_api($_url, $data, $method='POST', $upload=null, $content_type=null)
|
|
|
|
{
|
|
|
|
global $config, $verbose;
|
|
|
|
|
|
|
|
$url = $_url[0] == '/' ? 'https://api.github.com'.$_url : $_url;
|
|
|
|
$c = curl_init();
|
|
|
|
curl_setopt($c, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
|
|
|
curl_setopt($c, CURLOPT_USERPWD, $config['github_user'].':'.$config['github_token']);
|
|
|
|
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
curl_setopt($c, CURLOPT_USERAGENT, basename(__FILE__));
|
|
|
|
curl_setopt($c, CURLOPT_TIMEOUT, 240);
|
|
|
|
curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
|
|
|
|
|
|
|
|
switch($method)
|
|
|
|
{
|
|
|
|
case 'POST':
|
|
|
|
curl_setopt($c, CURLOPT_POST, true);
|
|
|
|
if (is_array($data)) $data = json_encode($data, JSON_FORCE_OBJECT);
|
|
|
|
curl_setopt($c, CURLOPT_POSTFIELDS, $data);
|
|
|
|
break;
|
|
|
|
case 'GET':
|
|
|
|
if(count($data)) $url .= '?' . http_build_query($data);
|
|
|
|
break;
|
|
|
|
case 'FILE':
|
|
|
|
curl_setopt($c, CURLOPT_HTTPHEADER, array("Content-type: $content_type"));
|
|
|
|
curl_setopt($c, CURLOPT_POST, true);
|
|
|
|
curl_setopt($c, CURLOPT_POSTFIELDS, file_get_contents($upload));
|
|
|
|
if(count($data)) $url .= '?' . http_build_query($data);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new Exception(__FUNCTION__.": Unknown/unimplemented method=$method!");
|
|
|
|
}
|
|
|
|
curl_setopt($c, CURLOPT_URL, $url);
|
|
|
|
|
|
|
|
if (is_string($data)) $short_data = strlen($data) > 100 ? substr($data, 0, 100).' ...' : $data;
|
|
|
|
if ($verbose) echo "Sending $method request to $url ".(isset($short_data)&&$method!='GET'?$short_data:'')."\n";
|
|
|
|
|
|
|
|
if (($response = curl_exec($c)) === false)
|
|
|
|
{
|
|
|
|
// run failed request again to display response including headers
|
|
|
|
curl_setopt($c, CURLOPT_HEADER, true);
|
|
|
|
curl_setopt($c, CURLOPT_RETURNTRANSFER, false);
|
|
|
|
curl_exec($c);
|
|
|
|
throw new Exception("$method request to $url failed ".(isset($short_data)&&$method!='GET'?$short_data:''));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($verbose) echo (strlen($response) > 200 ? substr($response, 0, 200).' ...' : $response)."\n";
|
|
|
|
|
|
|
|
curl_close($c);
|
|
|
|
|
|
|
|
return json_decode($response, true);
|
2015-01-21 11:08:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetch a config value allowing to use config vars like $svnbranch in it
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @param string $value =null value to use, default $config[$name]
|
|
|
|
*/
|
|
|
|
function config_translate($name, $value=null)
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
if (!isset($value)) $value = $config[$name];
|
2019-07-16 10:46:59 +02:00
|
|
|
if (is_string($value) && (strpos($value, '$') !== false || substr($value, 0, 2) === '~/'))
|
2014-04-19 12:43:02 +02:00
|
|
|
{
|
2019-07-16 10:46:59 +02:00
|
|
|
$translate = ['~/' => getenv('HOME').'/'];
|
2015-01-21 11:08:16 +01:00
|
|
|
foreach($config as $n => $val)
|
2014-04-19 16:15:29 +02:00
|
|
|
{
|
2015-01-21 11:08:16 +01:00
|
|
|
if (is_string($val)) $translate['$'.$n] = $val;
|
2014-04-19 16:15:29 +02:00
|
|
|
}
|
2015-01-21 11:08:16 +01:00
|
|
|
$value = strtr($value, $translate);
|
2014-04-19 12:43:02 +02:00
|
|
|
}
|
2015-01-21 11:08:16 +01:00
|
|
|
return $value;
|
2014-04-19 12:43:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy changelog by rsync'ing it to a distribution / download directory
|
|
|
|
*/
|
|
|
|
function do_copychangelog()
|
|
|
|
{
|
2015-01-21 11:08:16 +01:00
|
|
|
global $config;
|
2014-04-19 12:43:02 +02:00
|
|
|
|
|
|
|
$changelog = __DIR__.'/debian.changes';
|
2015-01-21 11:08:16 +01:00
|
|
|
$cmd = $config['rsync'].' '.$changelog.' '.config_translate('copychangelog');
|
2014-04-19 12:43:02 +02:00
|
|
|
passthru($cmd);
|
|
|
|
}
|
|
|
|
|
2010-08-08 15:13:03 +02:00
|
|
|
/**
|
2016-05-25 15:07:03 +02:00
|
|
|
* Query changelog and let user edit it
|
2010-08-08 15:13:03 +02:00
|
|
|
*/
|
2016-05-25 15:07:03 +02:00
|
|
|
function do_editchangelog()
|
2010-08-08 15:13:03 +02:00
|
|
|
{
|
2015-01-21 11:08:16 +01:00
|
|
|
global $config,$svn;
|
2010-08-08 15:13:03 +02:00
|
|
|
|
2016-05-25 15:07:03 +02:00
|
|
|
echo "Querying changelog from Git/SVN\n";
|
2010-08-08 15:13:03 +02:00
|
|
|
if (!isset($config['modules']))
|
|
|
|
{
|
2016-05-25 15:07:03 +02:00
|
|
|
$config['modules'] = get_modules_per_repo();
|
2010-08-08 15:13:03 +02:00
|
|
|
}
|
|
|
|
// query changelog per repo
|
|
|
|
$changelog = '';
|
2016-06-02 16:46:36 +02:00
|
|
|
$last_tag = null;
|
2016-05-25 15:07:03 +02:00
|
|
|
foreach($config['modules'] as $branch_url => $modules)
|
2010-08-08 15:13:03 +02:00
|
|
|
{
|
2016-06-02 16:46:36 +02:00
|
|
|
$revision = null;
|
2016-05-25 15:07:03 +02:00
|
|
|
if (substr($branch_url, -4) == '.git')
|
2010-08-08 15:13:03 +02:00
|
|
|
{
|
2022-09-05 08:42:13 +02:00
|
|
|
$path = key($modules);
|
2016-05-25 15:07:03 +02:00
|
|
|
$changelog .= get_changelog_from_git($path, $config['editchangelog'], $last_tag);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$changelog .= get_changelog_from_svn($branch_url, $config['editchangelog'], $revision);
|
2010-08-08 15:13:03 +02:00
|
|
|
}
|
|
|
|
}
|
2017-10-21 14:17:20 +02:00
|
|
|
if (empty($changelog))
|
|
|
|
{
|
|
|
|
$changelog = "Could not query changelog for $config[version], eg. no last tag found!\n";
|
|
|
|
}
|
2010-08-08 15:13:03 +02:00
|
|
|
$logfile = tempnam('/tmp','checkout-build-archives');
|
|
|
|
file_put_contents($logfile,$changelog);
|
|
|
|
$cmd = $config['editor'].' '.escapeshellarg($logfile);
|
|
|
|
passthru($cmd);
|
2014-04-19 12:43:02 +02:00
|
|
|
$config['changelog'] = file_get_contents($logfile);
|
2010-08-10 09:36:19 +02:00
|
|
|
// remove trailing newlines
|
|
|
|
while (substr($config['changelog'],-1) == "\n")
|
|
|
|
{
|
|
|
|
$config['changelog'] = substr($config['changelog'],0,-1);
|
|
|
|
}
|
2010-08-08 15:13:03 +02:00
|
|
|
// allow user to abort, by deleting the changelog
|
2014-04-19 12:43:02 +02:00
|
|
|
if (strlen($config['changelog']) <= 2)
|
2010-08-08 15:13:03 +02:00
|
|
|
{
|
|
|
|
die("\nChangelog must not be empty --> aborting\n\n");
|
|
|
|
}
|
2014-04-19 12:43:02 +02:00
|
|
|
// commit changelog
|
2016-05-25 15:07:03 +02:00
|
|
|
$changelog = $config['checkoutdir'].'/doc/rpm-build/debian.changes';
|
|
|
|
if (!file_exists($changelog))
|
|
|
|
{
|
|
|
|
throw new Exception("Changelog '$changelog' not found!");
|
|
|
|
}
|
|
|
|
file_put_contents($changelog, update_changelog(file_get_contents($changelog)));
|
2017-02-02 10:36:22 +01:00
|
|
|
|
|
|
|
update_api_setup($api_setup=$config['checkoutdir'].'/api/setup/setup.inc.php');
|
|
|
|
|
2016-05-25 15:07:03 +02:00
|
|
|
if (file_exists($config['checkoutdir'].'/.git'))
|
|
|
|
{
|
2017-02-02 10:36:22 +01:00
|
|
|
$cmd = $config['git']." commit -m 'Changelog for $config[version].$config[packaging]' ".$changelog.' '.$api_setup;
|
2016-05-25 15:07:03 +02:00
|
|
|
}
|
|
|
|
else
|
2014-04-19 12:43:02 +02:00
|
|
|
{
|
2017-02-02 10:36:22 +01:00
|
|
|
$cmd = $svn." commit -m 'Changelog for $config[version].$config[packaging]' ".$changelog.' '.$api_setup;
|
2014-04-19 12:43:02 +02:00
|
|
|
}
|
2016-05-25 15:07:03 +02:00
|
|
|
run_cmd($cmd);
|
|
|
|
|
2014-04-19 12:43:02 +02:00
|
|
|
// update obs changelogs (so all changlogs are updated in case of a later error and changelog step can be skiped)
|
|
|
|
do_obs(true); // true: only update debian.changes in obs checkouts
|
2010-08-08 15:13:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read changelog for given branch from (last) tag or given revision from svn
|
2011-06-05 12:30:30 +02:00
|
|
|
*
|
2015-01-21 11:08:16 +01:00
|
|
|
* @param string $branch_url ='svn+ssh://svn@svn.stylite.de/egroupware/branches/Stylite-EPL-10.1'
|
|
|
|
* @param string $log_pattern =null a preg regular expression or start of line a log message must match, to be returned
|
2010-08-08 15:13:03 +02:00
|
|
|
* if regular perl regular expression given only first expression in brackets \\1 is used,
|
|
|
|
* for a start of line match, only the first line is used, otherwise whole message is used
|
2016-06-02 13:51:57 +02:00
|
|
|
* @param string& $revision =null from which to HEAD the log should be retrieved, default search revision of latest tag in ^/tags
|
2015-01-21 11:08:16 +01:00
|
|
|
* @param string $prefix ='* ' prefix, which if not presend should be added to all log messages
|
2016-05-25 15:07:03 +02:00
|
|
|
* @return string with changelog
|
2010-08-08 15:13:03 +02:00
|
|
|
*/
|
2015-01-21 11:08:16 +01:00
|
|
|
function get_changelog_from_svn($branch_url, $log_pattern=null, &$revision=null, $prefix='* ')
|
2010-08-08 15:13:03 +02:00
|
|
|
{
|
|
|
|
//echo __FUNCTION__."('$branch_url','$log_pattern','$revision','$prefix')\n";
|
|
|
|
global $config,$verbose,$svn;
|
2011-06-05 12:30:30 +02:00
|
|
|
|
2010-08-08 15:13:03 +02:00
|
|
|
if (is_null($revision))
|
|
|
|
{
|
2014-04-19 13:18:24 +02:00
|
|
|
list($tags_url,$branch) = preg_split('#/(branches/|trunk)#',$branch_url);
|
|
|
|
if (empty($branch)) $branch = $config['version'];
|
2010-08-08 15:13:03 +02:00
|
|
|
$tags_url .= '/tags';
|
2016-06-02 14:18:59 +02:00
|
|
|
$pattern='|/tags/('.preg_quote($config['version'], '|').'\.[0-9.]+)|';
|
2015-01-21 11:08:16 +01:00
|
|
|
$matches = null;
|
2010-08-08 15:13:03 +02:00
|
|
|
$revision = get_last_svn_tag($tags_url,$pattern,$matches);
|
|
|
|
$tag = $matches[1];
|
|
|
|
}
|
|
|
|
elseif(!is_numeric($revision))
|
|
|
|
{
|
|
|
|
$revision = get_last_svn_tag($tags_url,$tag=$revision);
|
|
|
|
}
|
|
|
|
$cmd = $svn.' log --xml -r '.escapeshellarg($revision.':HEAD').' '.escapeshellarg($branch_url);
|
|
|
|
if (($v = $verbose))
|
|
|
|
{
|
|
|
|
echo "Querying SVN for log from r$revision".($tag ? " ($tag)" : '').":\n$cmd\n";
|
|
|
|
$verbose = false; // otherwise no $output!
|
|
|
|
}
|
|
|
|
$output = array();
|
|
|
|
run_cmd($cmd,$output);
|
|
|
|
$verbose = $v;
|
|
|
|
array_shift($output); // remove the command
|
2011-06-05 12:30:30 +02:00
|
|
|
|
2010-08-08 15:13:03 +02:00
|
|
|
$xml = simplexml_load_string($output=implode("\n",$output));
|
|
|
|
$message = '';
|
|
|
|
foreach($xml as $log)
|
|
|
|
{
|
2016-05-25 15:07:03 +02:00
|
|
|
if (!($msg = _match_log_pattern($log->msg, $log_pattern, $prefix))) continue; // no match --> ignore
|
|
|
|
|
2010-08-08 15:13:03 +02:00
|
|
|
$message .= $msg."\n";
|
|
|
|
}
|
|
|
|
if ($verbose) echo $message;
|
|
|
|
|
|
|
|
return $message;
|
|
|
|
}
|
|
|
|
|
2016-05-25 15:07:03 +02:00
|
|
|
/**
|
|
|
|
* Return first row of matching log lines always prefixed with $prefix
|
|
|
|
*
|
|
|
|
* @param string $msg whole log message
|
|
|
|
* @param string $log_pattern
|
|
|
|
* @param string $prefix ='* '
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function _match_log_pattern($msg, $log_pattern, $prefix='* ')
|
|
|
|
{
|
|
|
|
$pattern_len = strlen($log_pattern);
|
|
|
|
$prefix_len = strlen($prefix);
|
|
|
|
|
|
|
|
$matches = null;
|
|
|
|
if ($log_pattern[0] == '/' && preg_match($log_pattern,$msg,$matches))
|
|
|
|
{
|
|
|
|
$msg = $matches[1];
|
|
|
|
}
|
|
|
|
elseif($log_pattern && $log_pattern[0] != '/' && substr($msg,0,$pattern_len) == $log_pattern)
|
|
|
|
{
|
|
|
|
list($msg) = explode("\n",$msg);
|
|
|
|
}
|
|
|
|
elseif($log_pattern)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if ($prefix_len && substr($msg,0,$prefix_len) != $prefix) $msg = $prefix.$msg;
|
|
|
|
|
|
|
|
return $msg;
|
|
|
|
}
|
|
|
|
|
2010-08-08 15:13:03 +02:00
|
|
|
/**
|
|
|
|
* Get revision of last svn tag matching a given pattern in the log message
|
2011-06-05 12:30:30 +02:00
|
|
|
*
|
2010-08-08 15:13:03 +02:00
|
|
|
* @param string $tags_url
|
|
|
|
* @param string $pattern which has to be contained in the log message (NOT the tag itself)
|
|
|
|
* or (perl) regular expression against which log message is matched
|
|
|
|
* @param array &$matches=null on return matches of preg_match
|
|
|
|
* @return int revision of last svn tag matching pattern
|
|
|
|
*/
|
|
|
|
function get_last_svn_tag($tags_url,$pattern,&$matches=null)
|
|
|
|
{
|
2015-01-21 11:08:16 +01:00
|
|
|
global $verbose,$svn;
|
2011-06-05 12:30:30 +02:00
|
|
|
|
2016-06-02 14:18:59 +02:00
|
|
|
$cmd = $svn.' log --xml --limit 40 -v '.escapeshellarg($tags_url);
|
2010-08-08 15:13:03 +02:00
|
|
|
if (($v = $verbose))
|
|
|
|
{
|
|
|
|
echo "Querying SVN for last tags\n$cmd\n";
|
|
|
|
$verbose = false; // otherwise no $output!
|
|
|
|
}
|
|
|
|
$output = array();
|
|
|
|
run_cmd($cmd,$output);
|
|
|
|
$verbose = $v;
|
|
|
|
array_shift($output); // remove the command
|
2011-06-05 12:30:30 +02:00
|
|
|
|
2010-08-08 15:13:03 +02:00
|
|
|
$xml = simplexml_load_string($output=implode("\n",$output));
|
2016-06-02 15:37:34 +02:00
|
|
|
$is_regexp = $pattern[0] == substr($pattern, -1);
|
2010-08-08 15:13:03 +02:00
|
|
|
foreach($xml as $log)
|
|
|
|
{
|
|
|
|
//print_r($log);
|
2016-06-02 15:37:34 +02:00
|
|
|
if (!$is_regexp && strpos($log->paths->path, $pattern) !== false ||
|
|
|
|
$is_regexp && preg_match($pattern, $log->paths->path, $matches))
|
2010-08-08 15:13:03 +02:00
|
|
|
{
|
|
|
|
if ($verbose) echo "Revision {$log['revision']} matches".($matches?': '.$matches[1] : '')."\n";
|
|
|
|
return (int)$log['revision'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
2009-06-01 13:53:03 +02:00
|
|
|
}
|
|
|
|
|
2010-03-05 16:09:13 +01:00
|
|
|
/**
|
|
|
|
* Copy archive files to obs checkout and commit them
|
|
|
|
*
|
2015-01-21 11:08:16 +01:00
|
|
|
* @param boolean $only_update_changelog =false true update debian.changes, but nothing else, nor commit it
|
2010-03-05 16:09:13 +01:00
|
|
|
*/
|
2014-04-19 12:43:02 +02:00
|
|
|
function do_obs($only_update_changelog=false)
|
2010-03-05 16:09:13 +01:00
|
|
|
{
|
|
|
|
global $config,$verbose;
|
|
|
|
|
2010-03-06 10:31:19 +01:00
|
|
|
if (!is_dir($config['obs']))
|
|
|
|
{
|
|
|
|
usage("Path '$config[obs]' not found!");
|
|
|
|
}
|
2014-04-19 12:43:02 +02:00
|
|
|
if ($verbose) echo $only_update_changelog ? "Updating OBS changelogs\n" : "Updating OBS checkout\n";
|
2010-03-06 10:31:19 +01:00
|
|
|
run_cmd('osc up '.$config['obs']);
|
|
|
|
|
2010-03-05 16:09:13 +01:00
|
|
|
$n = 0;
|
|
|
|
foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($config['obs'])) as $path)
|
|
|
|
{
|
2014-04-19 16:15:29 +02:00
|
|
|
if (basename(dirname($path)) == '.osc' ||
|
|
|
|
!preg_match('/\/('.preg_quote($config['packagename']).
|
|
|
|
($config['obs_package_alias'] ? '|'.preg_quote($config['obs_package_alias']) : '').
|
2016-11-07 14:52:37 +01:00
|
|
|
')[a-z-]*-('.preg_quote($config['version']).'|trunk)/',$path))
|
2014-04-19 16:15:29 +02:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2015-01-21 11:08:16 +01:00
|
|
|
$matches = null;
|
2014-04-19 12:43:02 +02:00
|
|
|
if (preg_match('/\/('.preg_quote($config['packagename']).'[a-z-]*)-'.preg_quote($config['version']).'\.[0-9.]+[0-9](\.tar\.(gz|bz2))$/',$path,$matches) &&
|
2010-03-05 16:09:13 +01:00
|
|
|
file_exists($new_name=$config['sourcedir'].'/'.$matches[1].'-'.$config['version'].'.'.$config['packaging'].$matches[2]))
|
|
|
|
{
|
|
|
|
if (basename($path) != basename($new_name))
|
|
|
|
{
|
|
|
|
unlink($path);
|
|
|
|
if ($verbose) echo "rm $path\n";
|
|
|
|
}
|
|
|
|
copy($new_name,dirname($path).'/'.basename($new_name));
|
|
|
|
if ($verbose) echo "cp $new_name ".dirname($path)."/\n";
|
|
|
|
++$n;
|
|
|
|
}
|
2014-04-19 14:25:48 +02:00
|
|
|
// if we have no changelog (eg. because commands run separate), try parsing it from changelog file
|
|
|
|
if (empty($config['changelog']))
|
|
|
|
{
|
|
|
|
$config['changelog'] = parse_current_changelog();
|
|
|
|
}
|
2010-03-18 22:40:49 +01:00
|
|
|
// updating dsc, spec and changelog files
|
2014-04-19 12:43:02 +02:00
|
|
|
if (!$only_update_changelog && (substr($path,-4) == '.dsc' || substr($path,-5) == '.spec') ||
|
2010-03-18 22:40:49 +01:00
|
|
|
!empty($config['changelog']) && basename($path) == 'debian.changes')
|
2010-03-18 20:39:53 +01:00
|
|
|
{
|
|
|
|
$content = $content_was = file_get_contents($path);
|
|
|
|
|
2010-03-18 22:40:49 +01:00
|
|
|
if (substr($path,-4) == '.dsc' || substr($path,-5) == '.spec')
|
|
|
|
{
|
2014-04-19 12:43:02 +02:00
|
|
|
$content = preg_replace('/^Version: '.preg_quote($config['version']).'\.[0-9.]+[0-9]/m','Version: '.$config['version'].'.'.$config['packaging'],$content);
|
2010-03-18 22:40:49 +01:00
|
|
|
}
|
2010-03-18 20:39:53 +01:00
|
|
|
if (substr($path,-4) == '.dsc')
|
|
|
|
{
|
|
|
|
$content = preg_replace('/^(Debtransform-Tar: '.preg_quote($config['packagename']).'[a-z-]*)-'.
|
2014-04-19 12:43:02 +02:00
|
|
|
preg_quote($config['version']).'\.[0-9.]+[0-9](\.tar\.(gz|bz2))$/m',
|
2010-03-18 20:39:53 +01:00
|
|
|
'\\1-'.$config['version'].'.'.$config['packaging'].'\\2',$content);
|
|
|
|
}
|
2010-03-18 22:40:49 +01:00
|
|
|
if (basename($path) == 'debian.changes' && strpos($content,$config['version'].'.'.$config['packaging']) === false)
|
|
|
|
{
|
2014-04-19 12:43:02 +02:00
|
|
|
$content = update_changelog($content);
|
2010-03-18 22:40:49 +01:00
|
|
|
}
|
|
|
|
if (!empty($config['changelog']) && substr($path,-5) == '.spec' &&
|
|
|
|
($pos_changelog = strpos($content,'%changelog')) !== false)
|
|
|
|
{
|
|
|
|
$pos_changelog += strlen("%changelog\n");
|
|
|
|
$content = substr($content,0,$pos_changelog).' *'.date('D M d Y').' '.$config['changelog_packager']."\n".
|
|
|
|
$config['changelog']."\n".substr($content,$pos_changelog);
|
|
|
|
}
|
2010-03-18 20:39:53 +01:00
|
|
|
if ($content != $content_was)
|
|
|
|
{
|
|
|
|
file_put_contents($path,$content);
|
|
|
|
if ($verbose) echo "Updated $path\n";
|
|
|
|
++$n;
|
|
|
|
}
|
|
|
|
}
|
2010-03-05 16:09:13 +01:00
|
|
|
}
|
2014-04-19 12:43:02 +02:00
|
|
|
if ($n && !$only_update_changelog)
|
2010-03-06 10:31:19 +01:00
|
|
|
{
|
2010-03-18 22:40:49 +01:00
|
|
|
echo "$n files updated in OBS checkout ($config[obs]), commiting them now...\n";
|
|
|
|
//run_cmd('osc status '.$config['obs']);
|
2010-03-06 10:31:19 +01:00
|
|
|
run_cmd('osc addremove '.$config['obs'].'/*');
|
2010-03-22 22:28:11 +01:00
|
|
|
run_cmd('osc commit -m '.escapeshellarg('Version: '.$config['version'].'.'.$config['packaging'].":\n".$config['changelog']).' '.$config['obs']);
|
2010-03-06 10:31:19 +01:00
|
|
|
}
|
2010-03-05 16:09:13 +01:00
|
|
|
}
|
|
|
|
|
2014-04-19 14:25:48 +02:00
|
|
|
/**
|
|
|
|
* Parse current changelog from debian.changes file
|
|
|
|
*
|
2016-06-04 11:03:04 +02:00
|
|
|
* @param boolean $set_packaging =false true: set packaging from last changelog entry
|
2014-04-19 14:25:48 +02:00
|
|
|
* @return string changelog entries without header and footer lines
|
|
|
|
*/
|
2016-06-04 11:03:04 +02:00
|
|
|
function parse_current_changelog($set_packaging=false)
|
2014-04-19 14:25:48 +02:00
|
|
|
{
|
2015-01-21 11:08:16 +01:00
|
|
|
global $config;
|
2014-04-19 14:25:48 +02:00
|
|
|
|
2016-05-25 15:07:03 +02:00
|
|
|
$changelog = file_get_contents($config['checkoutdir'].'/doc/rpm-build/debian.changes');
|
2014-04-19 14:25:48 +02:00
|
|
|
$lines = explode("\n", $changelog, 100);
|
2016-06-04 11:03:04 +02:00
|
|
|
$matches = null;
|
2014-04-19 14:25:48 +02:00
|
|
|
foreach($lines as $n => $line)
|
|
|
|
{
|
2016-06-04 11:03:04 +02:00
|
|
|
if (preg_match($preg='/^'.preg_quote($config['packagename']).' \('.preg_quote($config['version']).'\.'.
|
|
|
|
($set_packaging ? '([0-9]+)' : preg_quote($config['packaging'])).'/', $line, $matches))
|
2014-04-19 14:25:48 +02:00
|
|
|
{
|
2016-06-04 11:03:04 +02:00
|
|
|
if ($set_packaging)
|
|
|
|
{
|
|
|
|
$config['packaging'] = $matches[1];
|
|
|
|
}
|
2014-04-19 14:25:48 +02:00
|
|
|
$n += empty($lines[$n+1]) ? 2 : 1; // overead empty line behind header
|
|
|
|
$logentry = '';
|
|
|
|
while($lines[$n]) // entry is terminated by empty line
|
|
|
|
{
|
2014-04-19 16:15:29 +02:00
|
|
|
$logentry .= (substr($lines[$n], 0, 2) == ' ' ? substr($lines[$n], 2) : $lines[$n])."\n";
|
2014-04-19 14:25:48 +02:00
|
|
|
++$n;
|
|
|
|
}
|
|
|
|
return substr($logentry, 0, -1); // remove training "\n"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null; // paragraph for current version NOT found
|
|
|
|
}
|
|
|
|
|
2014-04-19 12:43:02 +02:00
|
|
|
/**
|
|
|
|
* Update content of debian changelog file with new content from $config[changelog]
|
|
|
|
*
|
|
|
|
* @param string $content existing changelog content
|
|
|
|
* @return string updated changelog content
|
|
|
|
*/
|
|
|
|
function update_changelog($content)
|
|
|
|
{
|
2015-01-21 11:08:16 +01:00
|
|
|
global $config;
|
2014-04-19 12:43:02 +02:00
|
|
|
|
2015-01-21 11:08:16 +01:00
|
|
|
list($header) = explode("\n", $content);
|
|
|
|
$new_header = preg_replace('/\('.preg_quote($config['version']).'\.[0-9.]+[0-9](.*)\)/','('.$config['version'].'.'.$config['packaging'].'\\1)', $header);
|
2014-04-19 12:43:02 +02:00
|
|
|
if (substr($config['changelog'],0,2) != ' ') $config['changelog'] = ' '.implode("\n ",explode("\n",$config['changelog']));
|
|
|
|
$content = $new_header."\n\n".$config['changelog'].
|
|
|
|
"\n\n -- ".$config['changelog_packager'].' '.date('r')."\n\n".$content;
|
|
|
|
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
2017-02-02 10:36:22 +01:00
|
|
|
/**
|
|
|
|
* Update content of api/setup/setup.inc.php file with new maintenance version
|
|
|
|
*
|
|
|
|
* @param string $path full path to "api/setup/setup.inc.php"
|
|
|
|
*/
|
|
|
|
function update_api_setup($path)
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
if (!($content = file_get_contents($path)))
|
|
|
|
{
|
|
|
|
throw new Exception("Could not read file '$path' to update maintenance-version!");
|
|
|
|
}
|
|
|
|
|
2017-10-21 14:35:05 +02:00
|
|
|
$content = preg_replace('/'.preg_quote("\$setup_info['api']['versions']['maintenance_release']", '/').'[^;]+;/',
|
2017-02-02 10:36:22 +01:00
|
|
|
"\$setup_info['api']['versions']['maintenance_release'] = '".$config['version'].'.'.$config['packaging']."';",
|
|
|
|
$content);
|
|
|
|
|
|
|
|
if (!file_put_contents($path, $content))
|
|
|
|
{
|
|
|
|
throw new Exception("Could not update file '$path' with maintenance-version!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-01 13:53:03 +02:00
|
|
|
/**
|
|
|
|
* Sign sha1sum file
|
|
|
|
*/
|
|
|
|
function do_sign()
|
|
|
|
{
|
2015-01-21 11:08:16 +01:00
|
|
|
global $config;
|
2009-06-01 13:53:03 +02:00
|
|
|
|
|
|
|
if (substr($config['sourcedir'],0,2) == '~/') // sha1_file cant deal with '~/rpm'
|
|
|
|
{
|
|
|
|
$config['sourcedir'] = getenv('HOME').substr($config['sourcedir'],1);
|
|
|
|
}
|
|
|
|
$sumsfile = $config['sourcedir'].'/sha1sum-'.$config['packagename'].'-'.$config['version'].'.'.$config['packaging'].'.txt';
|
|
|
|
|
|
|
|
if (!file_exists($sumsfile))
|
|
|
|
{
|
|
|
|
echo "sha1sum file '$sumsfile' not found!\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// signing it
|
2009-06-01 14:35:00 +02:00
|
|
|
if (empty($config['gpg']) || !file_exists($config['gpg']))
|
2009-06-01 13:53:03 +02:00
|
|
|
{
|
2009-06-01 14:35:00 +02:00
|
|
|
if (!empty($config['gpg'])) echo "{$config['gpg']} not found --> skipping signing sha1sum file!\n";
|
2009-06-01 13:53:03 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
echo "Signing sha1sum file:\n";
|
|
|
|
if (file_exists($sumsfile.'.asc')) unlink($sumsfile.'.asc');
|
2009-06-01 14:35:00 +02:00
|
|
|
$cmd = $config['gpg'].' --local-user '.$config['packager'].' --clearsign '.$sumsfile;
|
2009-06-01 13:53:03 +02:00
|
|
|
run_cmd($cmd);
|
|
|
|
unlink($sumsfile); // delete the unsigned file
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create archives
|
|
|
|
*/
|
|
|
|
function do_create()
|
|
|
|
{
|
2015-01-21 11:08:16 +01:00
|
|
|
global $config;
|
2009-06-01 13:53:03 +02:00
|
|
|
|
|
|
|
if (!file_exists($config['sourcedir'])) mkdir($config['sourcedir'],0755,true);
|
|
|
|
if (substr($config['sourcedir'],0,2) == '~/') // sha1_file cant deal with '~/rpm'
|
|
|
|
{
|
|
|
|
$config['sourcedir'] = getenv('HOME').substr($config['sourcedir'],1);
|
|
|
|
}
|
|
|
|
$sumsfile = $config['sourcedir'].'/sha1sum-'.$config['packagename'].'-'.$config['version'].'.'.$config['packaging'].'.txt';
|
|
|
|
$sums = '';
|
|
|
|
|
|
|
|
chdir($config['egw_buildroot']);
|
|
|
|
|
|
|
|
if($config['extra'])
|
|
|
|
{
|
2016-05-27 11:51:57 +02:00
|
|
|
$exclude = $exclude_all = array();
|
|
|
|
foreach($config['extra'] as $name => $modules)
|
2009-06-01 14:35:00 +02:00
|
|
|
{
|
2016-05-25 15:07:03 +02:00
|
|
|
foreach((array)$modules as $module)
|
|
|
|
{
|
|
|
|
$exclude[] = basename($module);
|
2016-05-27 11:51:57 +02:00
|
|
|
if (!empty($config['all-add']) && !in_array($module, $config['all-add']) && (is_int($name) || !in_array($name, $config['all-add'])))
|
|
|
|
{
|
|
|
|
$exclude_all[] = basename($module);
|
|
|
|
}
|
2016-05-25 15:07:03 +02:00
|
|
|
}
|
2009-06-01 14:35:00 +02:00
|
|
|
}
|
2016-05-25 15:07:03 +02:00
|
|
|
$exclude_extra = ' --exclude=egroupware/'.implode(' --exclude=egroupware/', $exclude);
|
2016-05-27 11:51:57 +02:00
|
|
|
$exclude_all_extra = $exclude_all ? ' --exclude=egroupware/'.implode(' --exclude=egroupware/', $exclude_all) : '';
|
2009-06-01 13:53:03 +02:00
|
|
|
}
|
|
|
|
foreach($config['types'] as $type)
|
|
|
|
{
|
|
|
|
echo "Creating $type archives\n";
|
|
|
|
$tar_type = $type == 'tar.bz2' ? 'j' : 'z';
|
|
|
|
|
|
|
|
$file = $config['sourcedir'].'/'.$config['packagename'].'-'.$config['version'].'.'.$config['packaging'].'.'.$type;
|
|
|
|
switch($type)
|
|
|
|
{
|
2016-05-27 11:51:57 +02:00
|
|
|
case 'all.tar.bz2': // single tar-ball for debian builds not easily supporting to use multiple
|
2016-05-27 12:21:52 +02:00
|
|
|
$file = $config['sourcedir'].'/'.$config['packagename'].'-all-'.$config['version'].'.'.$config['packaging'].'.tar';
|
|
|
|
$cmd = $config['tar'].' --owner=root --group=root -cf '.$file.$exclude_all_extra.' egroupware';
|
2016-05-27 11:51:57 +02:00
|
|
|
if (!empty($config['all-add']))
|
|
|
|
{
|
|
|
|
foreach((array)$config['all-add'] as $add)
|
|
|
|
{
|
|
|
|
if (substr($add, -4) != '.tar') continue; // probably a module
|
2016-05-27 12:21:52 +02:00
|
|
|
if (!($tar = realpath($add))) throw new Exception("File '$add' not found!");
|
|
|
|
$cmd .= '; '.$config['tar'].' --owner=root --group=root -Af '.$file.' '.$tar;
|
2016-05-27 11:51:57 +02:00
|
|
|
}
|
|
|
|
}
|
2016-05-27 13:23:51 +02:00
|
|
|
if (file_exists($file.'.bz2')) $cmd .= '; rm -f '.$file.'.bz2';
|
2016-05-27 12:21:52 +02:00
|
|
|
$cmd .= '; '.$config['bzip2'].' '.$file;
|
2016-05-27 13:23:51 +02:00
|
|
|
// run cmd now and continue without adding all tar-ball to sums, as we dont want to publish it
|
|
|
|
run_cmd($cmd);
|
|
|
|
continue 2;
|
2009-06-01 13:53:03 +02:00
|
|
|
case 'tar.bz2':
|
|
|
|
case 'tar.gz':
|
2016-05-27 11:51:57 +02:00
|
|
|
$cmd = $config['tar'].' --owner=root --group=root -c'.$tar_type.'f '.$file.$exclude_extra.' egroupware';
|
2009-06-01 13:53:03 +02:00
|
|
|
break;
|
|
|
|
case 'zip':
|
2016-05-25 15:07:03 +02:00
|
|
|
$cmd = file_exists($file) ? $config['rm'].' -f '.$file.'; ' : '';
|
|
|
|
$cmd .= $config['mv'].' egroupware/'.implode(' egroupware/', $exclude).' . ;';
|
2015-01-21 11:08:16 +01:00
|
|
|
$cmd .= $config['zip'].' -q -r -9 '.$file.' egroupware ;';
|
2016-05-25 15:07:03 +02:00
|
|
|
$cmd .= $config['mv'].' '.implode(' ', $exclude).' egroupware';
|
2009-06-01 13:53:03 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
run_cmd($cmd);
|
|
|
|
$sums .= sha1_file($file)."\t".basename($file)."\n";
|
|
|
|
|
2016-05-25 15:07:03 +02:00
|
|
|
foreach($config['extra'] as $name => $modules)
|
2009-06-01 13:53:03 +02:00
|
|
|
{
|
2016-05-25 15:07:03 +02:00
|
|
|
if (is_numeric($name)) $name = $modules;
|
|
|
|
$dirs = ' egroupware/'.implode(' egroupware/', (array)$modules);
|
|
|
|
$file = $config['sourcedir'].'/'.$config['packagename'].'-'.$name.'-'.$config['version'].'.'.$config['packaging'].'.'.$type;
|
2009-06-01 13:53:03 +02:00
|
|
|
switch($type)
|
|
|
|
{
|
2016-05-27 11:51:57 +02:00
|
|
|
case 'all.tar.bz2':
|
|
|
|
break; // nothing to do
|
2009-06-01 13:53:03 +02:00
|
|
|
case 'tar.bz2':
|
|
|
|
case 'tar.gz':
|
2016-05-25 15:07:03 +02:00
|
|
|
$cmd = $config['tar'].' --owner=root --group=root -c'.$tar_type.'f '.$file.$dirs;
|
2009-06-01 13:53:03 +02:00
|
|
|
break;
|
|
|
|
case 'zip':
|
2016-05-25 15:07:03 +02:00
|
|
|
$cmd = file_exists($file) ? $config['rm'].' -f '.$file.'; ' : '';
|
|
|
|
$cmd .= $config['zip'].' -q -r -9 '.$file.$dirs;
|
2009-06-01 13:53:03 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
run_cmd($cmd);
|
|
|
|
$sums .= sha1_file($file)."\t".basename($file)."\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// writing sha1sum file
|
|
|
|
file_put_contents($sumsfile,$sums);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scan checkout for viruses, if clamscan is installed (not fatal if not!)
|
|
|
|
*/
|
|
|
|
function do_virusscan()
|
|
|
|
{
|
|
|
|
global $config,$verbose;
|
|
|
|
|
|
|
|
if (!file_exists($config['clamscan']) || !is_executable($config['clamscan']))
|
|
|
|
{
|
|
|
|
echo "Virusscanner '$config[clamscan]' not found --> skipping virus scan!\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// try updating virus database
|
|
|
|
if (file_exists($config['freshclam']))
|
|
|
|
{
|
|
|
|
echo "Updating virus signatures\n";
|
2020-05-25 13:34:05 +02:00
|
|
|
$cmd = '/usr/bin/sudo bash -c "cd /; '.$config['freshclam'].'"';
|
2009-06-01 13:53:03 +02:00
|
|
|
if (!$verbose && function_exists('posix_getuid') && posix_getuid()) echo $cmd."\n";
|
2015-01-21 11:08:16 +01:00
|
|
|
$output = null;
|
2009-06-01 13:53:03 +02:00
|
|
|
run_cmd($cmd,$output,1); // 1 = ignore already up to date database
|
|
|
|
}
|
|
|
|
echo "Starting virusscan\n";
|
|
|
|
$cmd = $config['clamscan'].' --quiet -r '.$config['egw_buildroot'];
|
|
|
|
run_cmd($cmd);
|
|
|
|
echo "Virusscan successful (no viruses found).\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-05-25 15:07:03 +02:00
|
|
|
* Copy non .svn/.git parts to egw_buildroot and fix permissions and ownership
|
|
|
|
*
|
2019-07-16 10:46:59 +02:00
|
|
|
* We need to stash local modifications (currently only in egroupware main module) to revert modifications
|
2009-06-01 13:53:03 +02:00
|
|
|
*/
|
|
|
|
function do_copy()
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
|
2016-05-25 15:07:03 +02:00
|
|
|
// copy everything, but .svn dirs from checkoutdir to egw_buildroot
|
2017-10-21 13:39:05 +02:00
|
|
|
echo "Copying non-svn/git/tests dirs to buildroot\n";
|
2016-05-25 15:07:03 +02:00
|
|
|
|
|
|
|
if (!file_exists($config['egw_buildroot']))
|
|
|
|
{
|
|
|
|
run_cmd("mkdir -p $config[egw_buildroot]");
|
|
|
|
}
|
|
|
|
|
2019-07-16 10:46:59 +02:00
|
|
|
// we need to stash uncommited changes, before copying
|
2016-05-25 15:07:03 +02:00
|
|
|
if (file_exists($config['checkoutdir'].'/.git')) run_cmd("cd $config[checkoutdir]; git stash");
|
|
|
|
|
|
|
|
try {
|
2019-07-16 10:46:59 +02:00
|
|
|
$cmd = '/usr/bin/rsync -r --delete --delete-excluded --exclude .svn --exclude .git\* --exclude node_modules/ --exclude tests '.$config['checkoutdir'].'/ '.$config['egw_buildroot'].'/'.$config['aliasdir'].'/';
|
2016-05-25 15:07:03 +02:00
|
|
|
run_cmd($cmd);
|
|
|
|
}
|
|
|
|
catch (Exception $e) {
|
|
|
|
// catch failures to pop stash, before throwing exception
|
|
|
|
}
|
2019-07-16 15:30:40 +02:00
|
|
|
$output = null;
|
|
|
|
if (file_exists($config['checkoutdir'].'/.git')) run_cmd("git stash pop", $output, 1); // do not fail, if there's nothing to pop
|
2016-05-25 15:07:03 +02:00
|
|
|
if (isset($e)) throw $e;
|
2009-06-01 13:53:03 +02:00
|
|
|
|
2015-01-21 11:08:16 +01:00
|
|
|
if (($cmd = config_translate('patchCmd')) && $cmd[0] != '#')
|
2011-06-05 12:30:30 +02:00
|
|
|
{
|
|
|
|
echo "Running $cmd\n";
|
|
|
|
run_cmd($cmd);
|
|
|
|
}
|
2009-06-01 13:53:03 +02:00
|
|
|
// fix permissions
|
|
|
|
echo "Fixing permissions\n";
|
|
|
|
chdir($config['egw_buildroot'].'/'.$config['aliasdir']);
|
2015-01-21 11:08:16 +01:00
|
|
|
run_cmd('/bin/chmod -R a-x,u=rwX,g=rX,o=rX .');
|
2019-07-16 15:30:40 +02:00
|
|
|
run_cmd('/bin/chmod +x */*cli.php doc/rpm-build/*.php');
|
2009-06-01 13:53:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checkout or update EGroupware
|
|
|
|
*
|
|
|
|
* Ensures an existing checkout is from the correct branch! Otherwise it get's deleted
|
|
|
|
*/
|
2016-05-25 15:07:03 +02:00
|
|
|
function do_svncheckout()
|
2009-06-01 13:53:03 +02:00
|
|
|
{
|
2015-01-21 11:08:16 +01:00
|
|
|
global $config,$svn;
|
2009-06-01 13:53:03 +02:00
|
|
|
|
|
|
|
echo "Starting svn checkout/update\n";
|
2016-05-25 15:07:03 +02:00
|
|
|
if (!file_exists($config['checkoutdir']))
|
2009-06-01 13:53:03 +02:00
|
|
|
{
|
2016-05-25 15:07:03 +02:00
|
|
|
mkdir($config['checkoutdir'],0755,true);
|
2009-06-01 13:53:03 +02:00
|
|
|
}
|
2016-05-25 15:07:03 +02:00
|
|
|
elseif (!is_dir($config['checkoutdir']) || !is_writable($config['checkoutdir']))
|
2009-06-01 13:53:03 +02:00
|
|
|
{
|
2016-05-25 15:07:03 +02:00
|
|
|
throw new Exception("svn checkout directory '{$config['checkoutdir']} exists and is NO directory or NOT writable!");
|
2009-06-01 13:53:03 +02:00
|
|
|
}
|
2016-05-25 15:07:03 +02:00
|
|
|
chdir($config['checkoutdir']);
|
2011-06-05 12:30:30 +02:00
|
|
|
|
2010-05-25 22:26:52 +02:00
|
|
|
// do we use a just created tag --> list of taged modules
|
2014-04-19 12:43:02 +02:00
|
|
|
if ($config['svntag'])
|
2010-05-25 22:26:52 +02:00
|
|
|
{
|
2014-04-19 12:43:02 +02:00
|
|
|
if (!isset($config['modules']))
|
|
|
|
{
|
2016-05-25 15:07:03 +02:00
|
|
|
get_modules_per_repo();
|
2014-04-19 12:43:02 +02:00
|
|
|
}
|
2015-01-21 11:08:16 +01:00
|
|
|
$config['svntag'] = config_translate('svntag'); // in case svntag command did not run, translate tag name
|
|
|
|
|
2010-05-25 22:26:52 +02:00
|
|
|
if (file_exists($config['aliasdir']))
|
|
|
|
{
|
|
|
|
system('/bin/rm -rf .svn '.$config['aliasdir']); // --> remove the whole checkout, as we dont implement switching tags
|
|
|
|
clearstatcache();
|
|
|
|
}
|
|
|
|
foreach($config['modules'] as $repo => $modules)
|
|
|
|
{
|
|
|
|
$cmd = $svn.' co ';
|
|
|
|
foreach($modules as $path => $url)
|
|
|
|
{
|
|
|
|
if ($path == $config['aliasdir'])
|
|
|
|
{
|
|
|
|
$cmd = $svn.' co '.$repo.'/'.$config['svntag'].'/'.$path;
|
|
|
|
run_cmd($cmd);
|
|
|
|
chdir($path);
|
|
|
|
$cmd = $svn.' co ';
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(file_exists($config['aliasdir']))
|
|
|
|
{
|
2010-05-25 22:39:08 +02:00
|
|
|
die("'egroupware' applications must be first one in externals!\n");
|
2010-05-25 22:26:52 +02:00
|
|
|
}
|
|
|
|
$cmd .= ' '.$repo.'/'.$config['svntag'].'/'.basename($path);
|
|
|
|
}
|
|
|
|
run_cmd($cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// regular branch update, without tag
|
2015-01-21 11:08:16 +01:00
|
|
|
else
|
2009-06-01 13:53:03 +02:00
|
|
|
{
|
2015-01-21 11:08:16 +01:00
|
|
|
$svnbranch = $config['svnbase'].'/'.$config['svnbranch'];
|
|
|
|
if (file_exists($config['aliasdir']))
|
2009-06-01 13:53:03 +02:00
|
|
|
{
|
2015-01-21 11:08:16 +01:00
|
|
|
// check if correct branch
|
|
|
|
$cmd = 'LANG=C '.$svn.' info';
|
|
|
|
$output = $ret = null;
|
|
|
|
exec($cmd,$output,$ret);
|
|
|
|
foreach($output as $line)
|
2009-06-01 13:53:03 +02:00
|
|
|
{
|
2015-01-21 11:08:16 +01:00
|
|
|
if ($ret || substr($line,0,5) == 'URL: ')
|
2009-06-01 13:53:03 +02:00
|
|
|
{
|
2015-01-21 11:08:16 +01:00
|
|
|
$url = substr($line,5);
|
|
|
|
if ($ret || substr($url,0,strlen($svnbranch)) != $svnbranch) // wrong branch (or no svn dir)
|
|
|
|
{
|
|
|
|
echo "Checkout is of wrong branch --> deleting it\n";
|
|
|
|
system('/bin/rm -rf .svn '.$config['aliasdir']); // --> remove the whole checkout
|
|
|
|
clearstatcache();
|
|
|
|
}
|
|
|
|
break;
|
2009-06-01 13:53:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-21 11:08:16 +01:00
|
|
|
$url = $svnbranch.'/'.$config['svnalias'];
|
|
|
|
$cmd = $svn.' co '.$url.' .';
|
|
|
|
run_cmd($cmd);
|
2009-06-01 13:53:03 +02:00
|
|
|
|
2015-01-21 11:08:16 +01:00
|
|
|
chdir($config['aliasdir']);
|
|
|
|
foreach($config['extra'] as $module)
|
2009-06-01 14:35:00 +02:00
|
|
|
{
|
2015-01-21 11:08:16 +01:00
|
|
|
$module = config_translate(null, $module); // allow to use config vars like $svnbranch in module
|
|
|
|
$url = strpos($module,'://') === false ? $svnbranch.'/' : '';
|
|
|
|
$url .= $module;
|
|
|
|
$cmd = $svn.' co '.$url;
|
|
|
|
run_cmd($cmd);
|
2009-06-01 14:35:00 +02:00
|
|
|
}
|
2015-01-21 11:08:16 +01:00
|
|
|
}
|
|
|
|
// do composer install to fetch dependencies
|
|
|
|
if ($config['composer'])
|
|
|
|
{
|
2019-02-25 10:46:06 +01:00
|
|
|
run_cmd($config['composer'].' install --ignore-platform-reqs --no-dev');
|
2009-06-01 13:53:03 +02:00
|
|
|
}
|
2016-01-26 13:48:14 +01:00
|
|
|
// run after-checkout command(s), eg. to purge source directories
|
|
|
|
run_cmd($config['after-checkout']);
|
2009-06-01 13:53:03 +02:00
|
|
|
}
|
|
|
|
|
2010-05-25 22:26:52 +02:00
|
|
|
/**
|
2016-05-25 15:07:03 +02:00
|
|
|
* Get module path per svn repo from our config
|
2011-06-05 12:30:30 +02:00
|
|
|
*
|
2016-05-25 15:07:03 +02:00
|
|
|
* @return array with $repro_url => $path => $url, eg. array(
|
|
|
|
* "svn+ssh://svn@dev.egroupware.org/egroupware" => array(
|
|
|
|
* "egroupware" => "svn+ssh://svn@dev.egroupware.org/egroupware/branches/14.2/egroupware",
|
|
|
|
* "egroupware/addressbook" => "svn+ssh://svn@dev.egroupware.org/egroupware/branches/14.2/addressbook",
|
2010-05-25 22:26:52 +02:00
|
|
|
*/
|
2016-05-25 15:07:03 +02:00
|
|
|
function get_modules_per_svn_repo()
|
2010-05-25 22:26:52 +02:00
|
|
|
{
|
|
|
|
global $config,$svn,$verbose;
|
|
|
|
|
|
|
|
// process alias/externals
|
|
|
|
$svnbranch = $config['svnbase'].'/'.$config['svnbranch'];
|
|
|
|
$url = $svnbranch.'/'.$config['svnalias'];
|
|
|
|
$cmd = $svn.' propget svn:externals --strict '.$url;
|
|
|
|
if ($verbose) echo $cmd."\n";
|
2015-01-21 11:08:16 +01:00
|
|
|
$output = $ret = null;
|
2010-05-25 22:26:52 +02:00
|
|
|
exec($cmd,$output,$ret);
|
|
|
|
$config['modules'] = array();
|
|
|
|
foreach($output as $line)
|
|
|
|
{
|
2010-05-25 22:53:22 +02:00
|
|
|
$line = trim($line);
|
|
|
|
if (empty($line) || $line[0] == '#') continue;
|
|
|
|
list($path,$url) = preg_split('/[ \t\r\n]+/',$line);
|
2015-01-21 11:08:16 +01:00
|
|
|
$matches = null;
|
2010-05-25 22:39:08 +02:00
|
|
|
if (!preg_match('/([a-z+]+:\/\/[a-z@.]+\/[a-z]+)\/(branches|tags|trunk)/',$url,$matches)) die("Invalid SVN URL: $url\n");
|
2010-05-25 22:26:52 +02:00
|
|
|
$repo = $matches[1];
|
2010-08-08 15:13:03 +02:00
|
|
|
if ($repo == 'http://svn.egroupware.org/egroupware') $repo = 'svn+ssh://svn@dev.egroupware.org/egroupware';
|
2010-05-25 22:26:52 +02:00
|
|
|
$config['modules'][$repo][$path] = $url;
|
|
|
|
}
|
|
|
|
// process extra modules
|
|
|
|
foreach($config['extra'] as $module)
|
|
|
|
{
|
2015-01-21 11:08:16 +01:00
|
|
|
$module = config_translate(null, $module); // allow to use config vars like $svnbranch in module
|
2010-05-25 22:26:52 +02:00
|
|
|
$url = strpos($module,'://') === false ? $svnbranch.'/' : '';
|
|
|
|
$url .= $module;
|
|
|
|
if (strpos($module,'://') !== false) $module = basename($module);
|
2010-05-25 22:39:08 +02:00
|
|
|
if (!preg_match('/([a-z+]+:\/\/[a-z@.]+\/[a-z]+)\/(branches|tags|trunk)/',$url,$matches)) die("Invalid SVN URL: $url\n");
|
2010-05-25 22:26:52 +02:00
|
|
|
$repo = $matches[1];
|
2010-08-08 15:13:03 +02:00
|
|
|
if ($repo == 'http://svn.egroupware.org/egroupware') $repo = 'svn+ssh://svn@dev.egroupware.org/egroupware';
|
2010-05-25 22:26:52 +02:00
|
|
|
$config['modules'][$repo][$config['aliasdir'].'/'.$module] = $url;
|
|
|
|
}
|
2016-05-25 15:07:03 +02:00
|
|
|
if ($verbose) print_r($config['modules']);
|
2010-08-08 15:13:03 +02:00
|
|
|
return $config['modules'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create svn tag or branch
|
|
|
|
*/
|
|
|
|
function do_svntag()
|
|
|
|
{
|
2015-01-21 11:08:16 +01:00
|
|
|
global $config,$svn;
|
2010-08-08 15:13:03 +02:00
|
|
|
|
2015-01-21 11:08:16 +01:00
|
|
|
if (empty($config['svntag'])) return; // otherwise we copy everything in svn root!
|
|
|
|
|
|
|
|
$config['svntag'] = config_translate('svntag'); // allow to use config vars like $version in tag
|
2010-08-09 13:42:50 +02:00
|
|
|
|
2010-08-08 15:13:03 +02:00
|
|
|
echo "Creating SVN tag $config[svntag]\n";
|
|
|
|
if (!isset($config['modules']))
|
|
|
|
{
|
2016-05-25 15:07:03 +02:00
|
|
|
get_modules_per_repo();
|
2010-08-08 15:13:03 +02:00
|
|
|
}
|
2010-05-25 22:26:52 +02:00
|
|
|
// create tags (per repo)
|
|
|
|
foreach($config['modules'] as $repo => $modules)
|
|
|
|
{
|
2010-05-25 22:53:22 +02:00
|
|
|
$cmd = $svn.' cp --parents -m '.escapeshellarg('Creating '.$config['svntag']).' '.implode(' ',$modules).' '.$repo.'/'.$config['svntag'].'/';
|
2010-05-25 22:26:52 +02:00
|
|
|
run_cmd($cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-01 13:53:03 +02:00
|
|
|
/**
|
2019-02-25 10:46:06 +01:00
|
|
|
* Runs given shell command
|
|
|
|
*
|
|
|
|
* If command return non-zero exit-code:
|
|
|
|
* 1) output is echoed, if not already running verbose
|
|
|
|
* 2a) if exit-code is contained in $no_bailout --> return it
|
|
|
|
* 2b) otherwise throws with $cmd as message and exit-code
|
2009-06-01 13:53:03 +02:00
|
|
|
*
|
|
|
|
* @param string $cmd
|
2016-05-25 15:07:03 +02:00
|
|
|
* @param array& $output=null $output of command, only if !$verbose !!!
|
2015-01-21 11:08:16 +01:00
|
|
|
* @param int|array $no_bailout =null exit code(s) to NOT bail out
|
2019-02-25 10:46:06 +01:00
|
|
|
* @throws Exception on non-zero exit-code not matching $no_bailout
|
2009-06-01 13:53:03 +02:00
|
|
|
* @return int exit code of $cmd
|
|
|
|
*/
|
|
|
|
function run_cmd($cmd,array &$output=null,$no_bailout=null)
|
|
|
|
{
|
|
|
|
global $verbose;
|
|
|
|
|
2016-05-25 15:07:03 +02:00
|
|
|
if ($verbose && func_num_args() == 1)
|
2009-06-01 13:53:03 +02:00
|
|
|
{
|
|
|
|
echo $cmd."\n";
|
2015-01-21 11:08:16 +01:00
|
|
|
$ret = null;
|
2009-06-01 13:53:03 +02:00
|
|
|
system($cmd,$ret);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$output[] = $cmd;
|
|
|
|
exec($cmd,$output,$ret);
|
2016-05-25 15:07:03 +02:00
|
|
|
if ($verbose) echo implode("\n",$output)."\n";
|
2009-06-01 13:53:03 +02:00
|
|
|
}
|
|
|
|
if ($ret && !in_array($ret,(array)$no_bailout))
|
|
|
|
{
|
|
|
|
if (!$verbose) echo implode("\n",$output)."\n";
|
|
|
|
throw new Exception("Error during '$cmd' --> aborting",$ret);
|
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
2015-01-21 11:08:16 +01:00
|
|
|
/**
|
|
|
|
* Format array or other types as (one-line) string, eg. for error_log statements
|
|
|
|
*
|
|
|
|
* @param mixed $var variable to dump
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function array2string($var)
|
|
|
|
{
|
|
|
|
switch (($type = gettype($var)))
|
|
|
|
{
|
|
|
|
case 'boolean':
|
|
|
|
return $var ? 'TRUE' : 'FALSE';
|
|
|
|
case 'string':
|
|
|
|
return "'$var'";
|
|
|
|
case 'integer':
|
|
|
|
case 'double':
|
|
|
|
case 'resource':
|
|
|
|
return $var;
|
|
|
|
case 'NULL':
|
|
|
|
return 'NULL';
|
|
|
|
case 'object':
|
|
|
|
case 'array':
|
|
|
|
return str_replace(array("\n",' '/*,'Array'*/),'',print_r($var,true));
|
|
|
|
}
|
|
|
|
return 'UNKNOWN TYPE!';
|
|
|
|
}
|
|
|
|
|
2009-06-01 13:53:03 +02:00
|
|
|
/**
|
|
|
|
* Give usage information and an optional error-message, before stoping program execution with exit-code 90 or 0
|
|
|
|
*
|
2015-01-21 11:08:16 +01:00
|
|
|
* @param string $error =null optional error-message
|
2009-06-01 13:53:03 +02:00
|
|
|
*/
|
|
|
|
function usage($error=null)
|
|
|
|
{
|
2016-06-04 11:03:04 +02:00
|
|
|
global $prog,$config,$verbose;
|
2009-06-01 13:53:03 +02:00
|
|
|
|
|
|
|
echo "Usage: $prog [-h|--help] [-v|--verbose] [options, ...]\n\n";
|
|
|
|
echo "options and their defaults:\n";
|
2016-06-04 11:03:04 +02:00
|
|
|
if ($verbose)
|
|
|
|
{
|
|
|
|
if (!isset($config['modules'])) $config['modules'] = get_modules_per_repo();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unset($config['modules']); // they give an error, because of nested array and are quite lengthy
|
|
|
|
}
|
2009-06-01 13:53:03 +02:00
|
|
|
foreach($config as $name => $default)
|
|
|
|
{
|
2016-06-04 11:03:04 +02:00
|
|
|
if (is_array($default)) $default = json_encode ($default, JSON_UNESCAPED_SLASHES);
|
2009-06-01 13:53:03 +02:00
|
|
|
echo '--'.str_pad($name,20).$default."\n";
|
|
|
|
}
|
|
|
|
if ($error)
|
|
|
|
{
|
|
|
|
echo "$error\n\n";
|
|
|
|
exit(90);
|
|
|
|
}
|
|
|
|
exit(0);
|
2022-04-20 21:43:42 +02:00
|
|
|
}
|