com web/rmtools: basic build uploads for pickle: client/include/Tools.php client/script/pickle.php

From: Date: Wed, 06 May 2015 11:42:32 +0000
Subject: com web/rmtools: basic build uploads for pickle: client/include/Tools.php client/script/pickle.php
Groups: php.webmaster 
Request: Send a blank email to php-webmaster+get-25995@lists.php.net to get a copy of this message
Commit: 726eafa89d81cabf05a56c10d1ebe06ab7dc8590 Author: Anatol Belski <ab@php.net> Wed, 6 May 2015 13:42:32 +0200 Parents: 262500301bf7678dec2569ef8ebaec3254646c78 Branches: master pecl_legacy Link: http://git.php.net/?p=web/rmtools.git;a=commitdiff;h=726eafa89d81cabf05a56c10d1ebe06ab7dc8590 Log: basic build uploads for pickle Changed paths: M client/include/Tools.php M client/script/pickle.php Diff: diff --git a/client/include/Tools.php b/client/include/Tools.php index 77d02e4..8bcb68a 100644 --- a/client/include/Tools.php +++ b/client/include/Tools.php @@ -471,3 +471,103 @@ function upload_pecl_pkg_ftp_curl($files, $logs, $target) return true; } +function upload_pickle_pkg_ftp_curl($files, $logs, $target) +{ + include __DIR__ . '/../data/config/credentials_ftps.php'; + + $ftp = ftp_connect($ftp_server); + if (!$ftp) { + echo "Cannot connect to $ftp_server\n"; + return false; + } + $login_result = ftp_login($ftp, $user_pickle, $password_pickle); + if (!$login_result) { + return false; + } + + $try = 0; + do { + $status = ftp_make_directory($ftp, $target . '/logs/'); + $try++; + } while ( $status === false && $try < 10 ); + ftp_close($ftp); + + $curl = array(); + + $ftp_path = $target; + $ftp_user = $user_pickle; + $ftp_password = $password_pickle; + + if ($ftp_path[0] != '/') { + $ftp_path = '/' . $ftp_path; + } + $mh = \curl_multi_init(); + + $files = is_array($files) ? $files : array($files); + $offset = 0; + foreach ($files as $i => $local_file) { + + $curl[$i] = $ch = \curl_init(); + $fp = fopen($local_file, "rb"); + $local_file = basename($local_file); + + $remoteurl = "ftps://${ftp_user}:${ftp_password}@${ftp_server}${ftp_path}/${local_file}"; + + \curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); + \curl_setopt($ch, CURLOPT_URL, $remoteurl); + \curl_setopt($ch, CURLOPT_UPLOAD, 1); + \curl_setopt($ch, CURLOPT_INFILE, $fp); + \curl_setopt($ch , CURLOPT_USERPWD, $ftp_user . ':' . $ftp_password); + + \curl_multi_add_handle ($mh, $ch); + $offset++; + } + + $files = is_array($logs) ? $logs : array($logs); + foreach ($files as $i => $local_file) { + + $ch = $curl[$offset + $i] = \curl_init(); + $fp = fopen($local_file, "rb"); + $local_file = basename($local_file); + + $remoteurl = "ftps://${ftp_user}:${ftp_password}@${ftp_server}${ftp_path}/logs/${local_file}"; + + \curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); + \curl_setopt($ch, CURLOPT_URL, $remoteurl); + \curl_setopt($ch, CURLOPT_UPLOAD, 1); + \curl_setopt($ch, CURLOPT_INFILE, $fp); + \curl_setopt($ch , CURLOPT_USERPWD, $ftp_user . ':' . $ftp_password); + + \curl_multi_add_handle ($mh, $ch); + } + + $retry = 0; + do { + $err = 0; + do { + \curl_multi_exec($mh,$active); + $info = curl_multi_info_read($mh); + if ($info !== false) { + curl_multi_remove_handle($mh, $info['handle']); + if ($info['result'] != 0) { + $err = 1; +// echo curl_getinfo($info['handle'], CURLINFO_EFFECTIVE_URL) . "\n"; +// echo curl_error($info['handle']) . "\n\n"; + curl_multi_add_handle($mh, $info['handle']); + } + } + } while ($active); + $retry++; + } while ($err != 0 && $retry < 10); + + foreach ($curl as $ch) { + \curl_multi_remove_handle($mh, $ch); + if (\curl_errno($ch) != 0) { + echo \curl_error($ch) . "\n"; + } + \curl_close($ch); + } + //\curl_multi_close($mh); + return true; +} + diff --git a/client/script/pickle.php b/client/script/pickle.php index a7a6b34..dfe851d 100644 --- a/client/script/pickle.php +++ b/client/script/pickle.php @@ -57,6 +57,8 @@ echo "Using <$pkg_path>" . PHP_EOL . PHP_EOL; foreach ($builds as $build_name) { + $build_error = 0; + echo "Starting build $build_name" . PHP_EOL; //$build_config = $branch->config->getBuildFromName($build_name); @@ -85,13 +87,15 @@ foreach ($builds as $build_name) { echo "Running pickle build" . PHP_EOL; try { - $ret = $build->build($ext); + $ret = $build->build($ext); } catch (Exception $e) { echo 'Error: ' . $e->getMessage() . PHP_EOL; $ret = array("return_value" => 1, "log" => ""); /* send error mail*/ + $build_error++; + continue; } @@ -108,6 +112,8 @@ foreach ($builds as $build_name) { echo "Build failed" . PHP_EOL; echo $ret["log"]; + $build_error++; + continue; } @@ -117,6 +123,41 @@ foreach ($builds as $build_name) { // add the deps license to the pickle archive ... or should pickle do that? /* upload logs and builds */ + + $fl_base = "php_" . $ext->getName() . "-" . $ext->getVersion() . "-" . $build->branch->config->getBranch() . "-" . ($build->thread_safe ? "ts" : "nts") . "-" . $build->compiler . "-" . $build->architecture; + + $logs_zip = realpath(TMP_DIR . DIRECTORY_SEPARATOR . "$fl_base-logs.zip"); + $pkg_file = realpath(TMP_DIR . DIRECTORY_SEPARATOR . "$fl_base.zip"); + + $upload_success = true; + if ($upload) { + try { + $root = $is_snap ? 'snaps' : 'releases'; + $target = '/' . $root . '/' . $ext->getName() . '/' . $ext->getVersion(); + + $pkgs_to_upload = $build_error ? array() : array($pkg_file); + + if ($build_error) { + echo "Uploading logs" . PHP_EOL; + } else { + echo "Uploading '$pkg_file' and logs" . PHP_EOL; + } + + if ($build_error && !file_exists($logs_zip)) { + throw new Exception("Logs wasn't packaged, nothing to upload"); + } + + if (rm\upload_pickle_pkg_ftp_curl($pkgs_to_upload, array($logs_zip), $target)) { + echo "Upload succeeded" . PHP_EOL; + } else { + echo "Upload failed" . PHP_EOL; + } + } catch (Exception $e) { + echo 'Error . ' . $e->getMessage() . PHP_EOL; + $upload_success = false; + } + } + /* notify pickle */ //var_dump($build_name);

« previous php.webmaster (#25995) next »