public static function package_pear_package($package_xml_path, $target_dir) { if (!file_exists($package_xml_path)) { throw new pakeException('"' . $package_xml_path . '" file does not exist'); } pake_mkdirs($target_dir); $current = getcwd(); chdir($target_dir); if (!class_exists('PEAR_Packager')) { @(include 'PEAR/Packager.php'); if (!class_exists('PEAR_Packager')) { // falling back to cli-call $results = pake_sh('pear package ' . escapeshellarg($package_xml_path)); if ($task->is_verbose()) { echo $results; } chdir($current); return; } } $packager = new PEAR_Packager(); $packager->debug = 0; // silence output $archive = $packager->package($package_xml_path, true); pake_echo_action('file+', $target_dir . '/' . $archive); chdir($current); }
public static function run_pear($task, $args) { $results = pake_sh('pear package'); if ($task->is_verbose()) { echo $results; } }
public function dropDatabase($name) { if ($this->mode == 'cli') { pake_sh($this->cliCommandPrefix() . ' drop ' . escapeshellarg($name)); } else { $sql = 'DROP DATABASE IF EXISTS ' . $name; $this->sqlExec($sql); } }
public static function export($src_url, $target_path) { if (count(pakeFinder::type('any')->in($target_path)) > 0) { throw new pakeException('"' . $target_path . '" directory is not empty. Can not export there'); } pake_echo_action('svn export', $target_path); if (extension_loaded('svn')) { $result = svn_export($src_url, $target_path, false); if (false === $result) { throw new pakeException('Couldn\'t export "' . $src_url . '" repository'); } } else { pake_sh(escapeshellarg(pake_which('svn')) . ' export ' . escapeshellarg($src_url) . ' ' . escapeshellarg($target_path)); } }
function run_phpunit() { $cc_token = getenv('CODECLIMATE_REPO_TOKEN'); $cc = !empty($cc_token); $clover = $cc ? ' --coverage-clover build/logs/clover.xml' : ''; $circle_test_reports = getenv('CIRCLE_TEST_REPORTS'); if (!empty($circle_test_reports)) { pake_mkdirs($circle_test_reports); $junit = " --log-junit {$circle_test_reports}/phpunit/junit.xml"; } else { $junit = ''; } print pake_sh('vendor/bin/phpunit' . $clover . $junit); if ($cc && file_exists('build/logs/clover.xml')) { print pake_sh('vendor/bin/test-reporter'); } }
function run_sync($task, $args) { if (!count($args)) { throw new Exception('You must provide an environment to synchronize.'); } $env = $args[0]; $dryrun = isset($args[1]) ? $args[1] : false; if (!file_exists('config/rsync_exclude.txt')) { throw new Exception('You must create a rsync_exclude file for your project.'); } $host = $task->get_property('host', $env); $dir = $task->get_property('dir', $env); try { $user = $task->get_property('user', $env) . '@'; } catch (pakeException $e) { $user = ''; } if (substr($dir, -1) != '/') { $dir .= '/'; } $ssh = 'ssh'; try { $port = $task->get_property('port', $env); $ssh = '"ssh -p' . $port . '"'; } catch (pakeException $e) { } try { $parameters = $task->get_property('parameters', $env); } catch (pakeException $e) { $parameters = '-azC --force --delete'; if (file_exists('config/rsync_exclude.txt')) { $parameters .= ' --exclude-from=config/rsync_exclude.txt'; } if (file_exists('config/rsync_include.txt')) { $parameters .= ' --include-from=config/rsync_include.txt'; } if (file_exists('config/rsync.txt')) { $parameters .= ' --files-from=config/rsync.txt'; } } $dry_run = $dryrun == 'go' || $dryrun == 'ok' ? '' : '--dry-run'; $cmd = "rsync --progress {$dry_run} {$parameters} -e {$ssh} ./ {$user}{$host}:{$dir}"; echo pake_sh($cmd); }
public static function clone_repository($src_url, $target_path = null) { if (null === $target_path) { // trying to "guess" path $target_path = basename($src_url); // removing suffix if (substr($target_path, -3) === '.hg') { $target_path = substr($target_path, 0, -3); } } if (self::isRepository($target_path)) { throw new pakeException('"' . $target_path . '" directory is a Mercurial repository already'); } if (file_exists($target_path)) { throw new pakeException('"' . $target_path . '" directory already exists. Can not clone Mercurial-repository there'); } pake_mkdirs($target_path); pake_sh('hg clone -q ' . escapeshellarg($src_url) . ' ' . escapeshellarg($target_path)); return new pakeMercurial($target_path); }
public static function sync_from_server($local_path, $server_host, $remote_paths, $rsync_login = '', $transport = 'ssh') { if (strlen($rsync_login) > 0) { $rsync_login .= '@'; } pake_mkdirs($local_path); if (is_string($remote_paths)) { // sync contents of dir, so adding trailing slash if ($remote_paths[strlen($remote_paths) - 1] != '/') { $remote_paths .= '/'; } $remote_paths = array($remote_paths); } elseif (is_array($remote_paths)) { // syncing multiple objects, so removing trailing slashes $remote_paths = array_map(create_function('$path', 'return rtrim($path, "/");'), $remote_paths); } foreach ($remote_paths as &$remote_path) { $remote_path = $rsync_login . $server_host . ':' . $remote_path; } pake_sh('rsync -az -e ' . escapeshellarg($transport) . ' ' . implode(' ', array_map('escapeshellarg', $remote_paths)) . ' ' . escapeshellarg($local_path)); }
function run_demo() { pake_sh('aip app ' . realpath(__DIR__ . '/examples/new/config.yaml'), true); }
public static function clone_repository($src_url, $target_path = null) { if (null === $target_path) { // trying to "guess" path $target_path = basename($src_url); // removing suffix if (substr($target_path, -4) === '.git') { $target_path = substr($target_path, 0, -4); } } if (self::isRepository($target_path)) { throw new pakeException('"' . $target_path . '" directory is a Git repository already'); } if (file_exists($target_path)) { throw new pakeException('"' . $target_path . '" directory already exists. Can not clone git-repository there'); } pake_sh(escapeshellarg(pake_which('git')) . ' clone -q ' . escapeshellarg($src_url) . ' ' . escapeshellarg($target_path)); return new pakeGit($target_path); }
function pake_shdir($cmd, $dir, $interactive = false) { $current_dir = realpath(getcwd()); $dir = realpath($dir); pake_echo_comment("Jump into {$dir}"); chdir($dir); try { $result = pake_sh($cmd, $interactive); } catch (Exception $e) { pake_echo_comment("Cd back into {$current_dir}"); chdir($current_dir); throw $e; } pake_echo_comment("Jump back into {$current_dir}"); chdir($current_dir); return $result; }
/** * Creates the tarballs for a release */ function run_dist($task = null, $args = array(), $cliOpts = array()) { // copy workspace dir into dist dir, without git pake_mkdirs(Builder::distDir()); $finder = pakeFinder::type('any')->ignore_version_control(); pake_mirror($finder, realpath(Builder::workspaceDir()), realpath(Builder::distDir())); // remove unwanted files from dist dir // also: do we still need to run dos2unix? // create tarballs $cwd = getcwd(); chdir(dirname(Builder::distDir())); foreach (Builder::distFiles() as $distFile) { // php can not really create good zip files via phar: they are not compressed! if (substr($distFile, -4) == '.zip') { $cmd = Builder::tool('zip'); $extra = '-9 -r'; pake_sh("{$cmd} {$distFile} {$extra} " . basename(Builder::distDir())); } else { $finder = pakeFinder::type('any')->pattern(basename(Builder::distDir()) . '/**'); // see https://bugs.php.net/bug.php?id=58852 $pharFile = str_replace(Builder::libVersion(), '_LIBVERSION_', $distFile); pakeArchive::createArchive($finder, '.', $pharFile); rename($pharFile, $distFile); } } chdir($cwd); }
/** * Classifies all entries in git changelog as 4 types. * Each entry is returned starting with "- " * @return array the 1st-level elements are themselves matrixes, except for 'unmatchedEntries' which is a plain array */ public static function extractChangelogEntriesFromRepo($rootpath, $previousrev) { if ($previousrev != '') { /// @todo check if given revision exists in git repo? We'll get an empty changelog if it does not... /// @todo replace with pakegit::log $git = escapeshellarg(pake_which('git')); $changelogArray = preg_split('/(\\r\\n|\\n\\r|\\r|\\n)/', pake_sh(self::getCdCmd($rootpath) . " && {$git} log --pretty=%s " . escapeshellarg($previousrev) . "..HEAD")); $changelogArray = array_map('trim', $changelogArray); foreach ($changelogArray as $i => $line) { if ($line == '') { unset($changelogArray[$i]); } } $changelogText = implode("\n", $changelogArray); if ($changelogText == '') { pake_echo("Git log returns an empty string - generating an empty changelog file. Please check if there is any problem with {$rootpath}"); } // Was: "extract and categorize issues using known patterns" // This proved not to be reliable! // We categorize all issues by looking at their type in the bug tracker instead /*preg_match_all( "/^[- ]?Fix(?:ed|ing)?(?: bug|issue|for ticket)? (EZP-[0-9]+):? (.*)$/mi", $changelogText, $bugfixesMatches, PREG_PATTERN_ORDER ); preg_match_all( "/^[- ]?Implement(?:ed)?(?: enhancement|issue)? (EZP-[0-9]+):? (.*)$/mi", $changelogText, $enhancementsMatches, PREG_PATTERN_ORDER );*/ preg_match_all("!^Merge pull request #0?([0-9]+):? ([^/]*)(?:/.*)?\$!mi", $changelogText, $pullreqsMatches, PREG_PATTERN_ORDER); // remove merge commits to get "unmatched" items $unmatchedEntries = array_diff($changelogArray, $pullreqsMatches[0]); /// if we identify an issue number, look up its type in jira to determine its type $issueTypes = array(); foreach ($unmatchedEntries as $i => $entry) { if (preg_match('/(EZP-[0-9]+):? (.*)$/i', $entry, $matches)) { if (isset($issueTypes[$matches[1]])) { $type = $issueTypes[$matches[1]]; } else { $type = self::findIssueType($matches[1]); $issueTypes[$matches[1]] = $type; } switch ($type) { case 'enhancement': $enhancementsMatches[0][] = $matches[0]; $enhancementsMatches[1][] = $matches[1]; $enhancementsMatches[2][] = $matches[2]; unset($unmatchedEntries[$i]); break; case 'bugfix': $bugfixesMatches[0][] = $matches[0]; $bugfixesMatches[1][] = $matches[1]; $bugfixesMatches[2][] = $matches[2]; unset($unmatchedEntries[$i]); break; } } } $unmatchedEntries = array_values(array_map(function ($item) { return substr($item, 0, 2) != "- " ? "- {$item}" : $item; }, $unmatchedEntries)); } else { pake_echo('Can not determine the git tag of last version. Generating an empty changelog file'); $bugfixesMatches = array(array()); $enhancementsMatches = array(array()); $pullreqsMatches = array(array()); $unmatchedEntries = array(); } return array('bugfixesMatches' => $bugfixesMatches, 'enhancementsMatches' => $enhancementsMatches, 'pullreqsMatches' => $pullreqsMatches, 'unmatchedEntries' => $unmatchedEntries); }
// unit tests $h->register_glob($h->base_dir . '/unit/*/*Test.php'); // functional tests $h->register_glob($h->base_dir . '/functional/*Test.php'); $h->register_glob($h->base_dir . '/functional/*/*Test.php'); $ret = $h->run(); if (!$ret) { throw new Exception('Some tests failed. Release process aborted!'); } if (is_file('package.xml')) { pake_remove('package.xml', getcwd()); } pake_copy(getcwd() . '/package.xml.tmpl', getcwd() . '/package.xml'); // add class files $finder = pakeFinder::type('file')->ignore_version_control()->relative(); $xml_classes = ''; $dirs = array('lib' => 'php', 'data' => 'data'); foreach ($dirs as $dir => $role) { $class_files = $finder->in($dir); foreach ($class_files as $file) { $xml_classes .= '<file role="' . $role . '" baseinstalldir="symfony" install-as="' . $file . '" name="' . $dir . '/' . $file . '" />' . "\n"; } } // replace tokens pake_replace_tokens('package.xml', getcwd(), '##', '##', array('SYMFONY_VERSION' => $version, 'CURRENT_DATE' => date('Y-m-d'), 'CLASS_FILES' => $xml_classes, 'STABILITY' => $stability)); $results = pake_sh('pear package'); echo $results; pake_remove('package.xml', getcwd()); // copy .tgz as symfony-latest.tgz pake_copy(getcwd() . '/symfony-' . $version . '.tgz', getcwd() . '/symfony-latest.tgz'); exit(0);
/** * Downloads the build tarballs from Jenkins for further repackaging; options: --build=<buildnr> */ public static function run_dist_init($task = null, $args = array(), $cliopts = array()) { $opts = self::getOpts($args, $cliopts); $buildnr = @$cliopts['build']; if ($buildnr == '') { pake_echo('Fetching latest available build'); $buildnr = 'lastBuild'; } // get list of files from the build $out = self::jenkinsCall('job/' . $opts['jenkins']['jobs']['community'] . '/' . $buildnr . '/api/json', $opts); if (!is_array($out) || !is_array(@$out['artifacts'])) { pake_echo('Error in retrieving build description from Jenkins or no artifacts in build'); return; } else { if ($buildnr == 'lastBuild') { pake_echo('Found build ' . $out['number']); } } // find the correct variant //$buildurl = self::jenkinsUrl( 'job/' . $opts['jenkins']['jobs']['community'] . '/' . $buildnr, $opts ); $fileurl = ''; foreach ($out['artifacts'] as $artifact) { if (substr($artifact['fileName'], -4) == '.bz2') { $fileurl = 'job/' . $opts['jenkins']['jobs']['community'] . '/' . $buildnr . '/artifact/' . $artifact['relativePath']; break; } } if ($fileurl == '') { pake_echo("No artifacts available for build {$buildnr}"); return; } // clean up the 'release' dir $rootpath = $opts['build']['dir'] . '/release'; /// @todo this method is a bit slow, should find a faster one pake_remove_dir($rootpath); // download and unzip the file pake_mkdirs($rootpath); $filename = $rootpath . '/' . $artifact['fileName']; pake_write_file($filename, self::jenkinsCall($fileurl, $opts, 'GET', null, false), 'cpb'); // and unzip eZ into it - in a folder with a specific name $tar = self::getTool('tar', $opts); pake_sh(self::getCdCmd($rootpath) . " && {$tar} -xjf " . escapeshellarg($artifact['fileName'])); $currdir = pakeFinder::type('directory')->in($rootpath); $currdir = $currdir[0]; $finaldir = $rootpath . '/' . self::getProjName(); pake_rename($currdir, $finaldir); pake_echo("dir+ " . $finaldir); }
/** * Creates an archive out of a directory. * * Uses command-lne tar as Zeta Cmponents do no compress well, and pake * relies on phar which is buggy/unstable on old php versions * * @param boolean $no_top_dir when set, $sourcedir directory is not packaged as top-level dir in archive * @todo for tar formats, fix the extra "." dir packaged */ static function archiveDir($sourcedir, $archivefile, $no_top_dir = false) { // please tar cmd on win - OH MY! $archivefile = str_replace('\\', '/', $archivefile); $sourcedir = str_replace('\\', '/', realpath($sourcedir)); if ($no_top_dir) { $srcdir = '.'; $workdir = $sourcedir; } else { $srcdir = basename($sourcedir); $workdir = dirname($sourcedir); } $archivedir = dirname($archivefile); $extra = ''; $tar = self::getTool('tar'); if (substr($archivefile, -7) == '.tar.gz' || substr($archivefile, -4) == '.tgz') { $cmd = "{$tar} -z -cvf"; $extra = "-C " . escapeshellarg($workdir); $workdir = $archivedir; $archivefile = basename($archivefile); } else { if (substr($archivefile, -8) == '.tar.bz2') { $cmd = "{$tar} -j -cvf"; $extra = "-C " . escapeshellarg($workdir); $workdir = $archivedir; $archivefile = basename($archivefile); } else { if (substr($archivefile, -4) == '.tar') { $cmd = "{$tar} -cvf"; $extra = "-C " . escapeshellarg($workdir); $workdir = $archivedir; $archivefile = basename($archivefile); } else { if (substr($archivefile, -4) == '.zip') { $zip = self::getTool('zip'); $cmd = "{$zip} -9 -r"; } else { throw new pakeException("Can not determine archive type from filename: {$archivefile}"); } } } } pake_sh(self::getCdCmd($workdir) . " && {$cmd} {$archivefile} {$extra} {$srcdir}"); pake_echo_action('file+', $archivefile); }
function pake_superuser_sh($cmd, $interactive = false) { if (!isset($_SERVER['USER'])) { throw new pakeException("Don't know how to run commands as superuser"); } // we're superuser already if ($_SERVER['USER'] === 'root') { return pake_sh($cmd, $interactive); } try { $sudo = pake_which('sudo'); $cmd = escapeshellarg($sudo) . ' ' . $cmd; } catch (pakeException $e) { try { $su = pake_which('su'); $cmd = escapeshellarg($su) . ' root -c ' . $cmd; $interactive = true; // force interactive, as su asks for password on stdout } catch (pakeException $e) { // no "sudo" and no "su". bad throw new pakeException("Don't know how to run commands as superuser"); } } pake_echo_comment('Next command will be run using superuser priveleges'); pake_sh($cmd, $interactive); }
public function execute($command) { return pake_sh(escapeshellarg(pake_which('ssh')) . ' -C ' . escapeshellarg($this->login . '@' . $this->host) . ' ' . escapeshellarg($command)); }
$_newstyle_local = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'pake'; if ($_self_path != $_newstyle_local) { $php_exec = (isset($_SERVER['_']) and substr($_SERVER['_'], -4) != 'pake') ? $_SERVER['_'] : 'php'; $args = ''; if ($_SERVER['argc'] > 1) { array_shift($_SERVER['argv']); // removing pake.php $args_arr = array_map('escapeshellarg', $_SERVER['argv']); $args = ' ' . implode(' ', $args_arr); } $force_tty = ''; if (defined('PAKE_FORCE_TTY') or DIRECTORY_SEPARATOR != '\\' and function_exists('posix_isatty') and @posix_isatty(STDOUT)) { $force_tty = ' --force-tty'; } pake_echo_comment("oops… you're using installed pake. restarting with local version…"); pake_sh(escapeshellarg($php_exec) . ' ' . escapeshellarg($_newstyle_local) . $force_tty . $args, true); die; } else { pake_echo_comment("using local version of pake. good!"); } /* registration */ pake_import('simpletest'); pake_task('phar'); pake_task('foo'); /** * Demo-task * * @param string $task * @param string $args * @return bool * @author Alexey Zakhlestin
function run_install_deps() { pake_sh('composer install', TRUE); }
public static function run_test($task) { $php_cgi = ''; $_php_cgi = self::_get_php_executable() . '-cgi'; if (file_exists($_php_cgi)) { $php_cgi = ' ' . escapeshellarg('TEST_PHP_CGI_EXECUTABLE=' . $_php_cgi); } pake_echo_comment('Running test-suite. This can take awhile…'); pake_sh('make test NO_INTERACTION=1' . $php_cgi); pake_echo_comment('Done'); $path = dirname(pakeApp::get_instance()->getPakefilePath()) . '/tests'; $files = pakeFinder::type('file')->ignore_version_control()->relative()->name('*.diff')->in($path); if (count($files) == 0) { pake_echo(' All tests PASSed!'); return; } pake_echo_error('Following tests FAILed:'); foreach ($files as $file) { $phpt_file = substr($file, 0, -4) . 'phpt'; $_lines = file($path . '/' . $phpt_file); $description = $_lines[1]; unset($_lines); pake_echo(' ' . $phpt_file . ' (' . rtrim($description) . ')'); } }
/** * Checks for validity all php files; use config options to specify the path to php executable if needed */ static function run_check_php_files($task = null, $args = array(), $cliopts = array()) { $opts = self::getOpts(@$args[0], @$args[1], $cliopts); if (!SharedLock::acquire($opts['extension']['name'], LOCK_SH, $opts)) { throw new PakeException("Source code locked by another process"); } $destdir = self::getBuildDir($opts) . '/' . $opts['extension']['name']; $files = pakeFinder::type('file')->name(array('*.php'))->in($destdir); if (count($files)) { $php = self::getTool('php', $opts); if (strpos(pake_sh($php . " -v"), 'PHP') === false) { SharedLock::release($opts['extension']['name'], LOCK_SH, $opts); throw new pakeException("{$php} does not seem to be a valid php executable"); } foreach (pakeFinder::type('file')->name(array('*.php'))->in($destdir) as $file) { if (strpos(pake_sh($php . " -l " . escapeshellarg($file)), 'No syntax errors detected') === false) { SharedLock::release($opts['extension']['name'], LOCK_SH, $opts); throw new pakeException("{$file} does not seem to be a valid php file"); } } } SharedLock::release($opts['extension']['name'], LOCK_SH, $opts); }
function run_obs($task) { run_release($task); $_root = dirname(__FILE__); $options = pakeYaml::loadFile($_root . '/options.yaml'); $version = $options['version']; $target = $_root . '/target'; pake_sh(escapeshellarg(pake_which('gunzip')) . ' ' . escapeshellarg($target . '/pake-' . $version . '.tgz')); pake_sh(escapeshellarg(pake_which('tar')) . ' -r -f ' . escapeshellarg($target . '/pake-' . $version . '.tar') . ' -C ' . escapeshellarg($_root) . ' debian'); pake_sh(escapeshellarg(pake_which('gzip')) . ' ' . escapeshellarg($target . '/pake-' . $version . '.tar')); }
// force usage of local pake if ($_SERVER['PHP_SELF'] != dirname(__FILE__) . '/bin/pake.php') { $php_exec = (isset($_SERVER['_']) and substr($_SERVER['_'], -4) != 'pake') ? $_SERVER['_'] : 'php'; $args = ''; if ($_SERVER['argc'] > 1) { array_shift($_SERVER['argv']); // removing pake.php $args_arr = array_map('escapeshellarg', $_SERVER['argv']); $args = ' ' . implode(' ', $args_arr); } $force_tty = ''; if (defined('PAKE_FORCE_TTY') or DIRECTORY_SEPARATOR != '\\' and function_exists('posix_isatty') and @posix_isatty(STDOUT)) { $force_tty = ' --force-tty'; } pake_echo_comment("oops… you're using installed pake. restarting with local version…"); pake_sh(escapeshellarg($php_exec) . ' ' . escapeshellarg(dirname(__FILE__) . '/bin/pake.php') . $force_tty . $args, true); die; } else { pake_echo_comment("using local version of pake. good!"); } /* registration */ pake_import('simpletest'); pake_import('pear'); pake_desc('create a single file with all pake classes. usage: pake compact [plugin1 [plugin2 […]]]'); pake_task('compact'); pake_desc('create an executable PHAR-archive of Pake'); pake_task('phar'); pake_desc('release a new pake version'); pake_task('release'); pake_task('foo'); pake_task('create_package_xml');