コード例 #1
0
 /**
  * Triggers Jenkins Build for the project
  */
 public function execute()
 {
     $success = true;
     if ($this->build->isSuccessful()) {
         // Builds the Jenkins trigger
         $jenkins = $this->jenkinsUrl . '/job/' . rawurlencode($this->jenkinsProject) . '/build?delay=0sec';
         if ($this->jenkinsToken && !empty($this->jenkinsToken)) {
             $jenkins .= '&token=%s';
         }
         $jenkins = sprintf($jenkins, rawurlencode($this->jenkinsProject), $this->jenkinsToken);
         $this->phpci->log($jenkins);
         $curlHandler = curl_init($jenkins);
         curl_setopt($curlHandler, CURLOPT_RETURNTRANSFER, 1);
         curl_exec($curlHandler);
         $status = curl_getinfo($curlHandler, CURLINFO_HTTP_CODE);
         $curlUrl = curl_getinfo($curlHandler, CURLINFO_EFFECTIVE_URL);
         curl_close($curlHandler);
         if ($status != '200') {
             $this->phpci->logFailure($curlUrl . ' return with status code ' . $status);
             return false;
         }
     } else {
         $this->phpci->log('Skipping due to failed Build');
     }
     return $success;
 }
コード例 #2
0
ファイル: Email.php プロジェクト: nelsonyang0710/PHPCI
 /**
  * Send a notification mail.
  */
 public function execute()
 {
     $addresses = $this->getEmailAddresses();
     // Without some email addresses in the yml file then we
     // can't do anything.
     if (count($addresses) == 0) {
         return false;
     }
     $buildStatus = $this->build->isSuccessful() ? "Passing Build" : "Failing Build";
     $projectName = $this->build->getProject()->getTitle();
     try {
         $view = $this->getMailTemplate();
     } catch (Exception $e) {
         $this->phpci->log(sprintf('Unknown mail template "%s", falling back to default.', $this->options['template']), LogLevel::WARNING);
         $view = $this->getDefaultMailTemplate();
     }
     $view->build = $this->build;
     $view->project = $this->build->getProject();
     $layout = new View('Email/layout');
     $layout->build = $this->build;
     $layout->project = $this->build->getProject();
     $layout->content = $view->render();
     $body = $layout->render();
     $sendFailures = $this->sendSeparateEmails($addresses, sprintf("PHPCI - %s - %s", $projectName, $buildStatus), $body);
     // This is a success if we've not failed to send anything.
     $this->phpci->log(sprintf("%d emails sent", count($addresses) - $sendFailures));
     $this->phpci->log(sprintf("%d emails failed to send", $sendFailures));
     return $sendFailures === 0;
 }
コード例 #3
0
ファイル: Email.php プロジェクト: kukupigs/PHPCI
 /**
  * Connects to MySQL and runs a specified set of queries.
  */
 public function execute()
 {
     $addresses = $this->getEmailAddresses();
     // Without some email addresses in the yml file then we
     // can't do anything.
     if (count($addresses) == 0) {
         return false;
     }
     $subjectTemplate = "PHPCI - %s - %s";
     $projectName = $this->phpci->getBuildProjectTitle();
     $logText = $this->build->getLog();
     if ($this->build->isSuccessful()) {
         $sendFailures = $this->sendSeparateEmails($addresses, sprintf($subjectTemplate, $projectName, "Passing Build"), sprintf("Log Output: <br><pre>%s</pre>", $logText));
     } else {
         $view = new View('Email/failed');
         $view->build = $this->build;
         $view->project = $this->build->getProject();
         $emailHtml = $view->render();
         $sendFailures = $this->sendSeparateEmails($addresses, sprintf($subjectTemplate, $projectName, "Failing Build"), $emailHtml);
     }
     // This is a success if we've not failed to send anything.
     $this->phpci->log(sprintf("%d emails sent", count($addresses) - count($sendFailures)));
     $this->phpci->log(sprintf("%d emails failed to send", count($sendFailures)));
     return count($sendFailures) == 0;
 }
コード例 #4
0
ファイル: Codeception.php プロジェクト: ntoniazzi/PHPCI
 /**
  * Run tests from a Codeception config file.
  * @param $configPath
  * @return bool|mixed
  * @throws \Exception
  */
 protected function runConfigFile($configPath)
 {
     $this->phpci->logExecOutput(false);
     $codecept = $this->phpci->findBinary('codecept');
     if (!$codecept) {
         $this->phpci->logFailure(Lang::get('could_not_find', 'codecept'));
         return false;
     }
     $cmd = 'cd "%s" && ' . $codecept . ' run -c "%s" --xml ' . $this->args;
     if (IS_WIN) {
         $cmd = 'cd /d "%s" && ' . $codecept . ' run -c "%s" --xml ' . $this->args;
     }
     $configPath = $this->phpci->buildPath . $configPath;
     $success = $this->phpci->executeCommand($cmd, $this->phpci->buildPath, $configPath);
     $this->phpci->log('Codeception XML path: ' . $this->phpci->buildPath . $this->path . 'report.xml', Loglevel::DEBUG);
     $xml = file_get_contents($this->phpci->buildPath . $this->path . 'report.xml', false);
     $parser = new Parser($this->phpci, $xml);
     $output = $parser->parse();
     $meta = array('tests' => $parser->getTotalTests(), 'timetaken' => $parser->getTotalTimeTaken(), 'failures' => $parser->getTotalFailures());
     $this->build->storeMeta('codeception-meta', $meta);
     $this->build->storeMeta('codeception-data', $output);
     $this->build->storeMeta('codeception-errors', $parser->getTotalFailures());
     $this->phpci->logExecOutput(true);
     return $success;
 }
コード例 #5
0
 /**
  * Runs the copy command.
  *
  * @return bool
  */
 public function execute()
 {
     $destinationFilename = $this->phpci->buildPath . '/' . $this->envFilename;
     $this->phpci->log(sprintf('Copy external environment file %s for the %s branch to build directory', $this->envFilepath, $this->branch));
     if (!copy($this->envFilepath, $destinationFilename)) {
         $this->phpci->logFailure('Copy error environment file to build directory!');
         return false;
     }
     $this->phpci->logSuccess('External environment file successful copied.');
     return true;
 }
コード例 #6
0
ファイル: LocalBuild.php プロジェクト: kukupigs/PHPCI
 protected function handleSymlink(Builder $builder, $reference, $buildPath)
 {
     if (is_link($buildPath) && is_file($buildPath)) {
         unlink($buildPath);
     }
     $builder->log(sprintf('Symlinking: %s to %s', $reference, $buildPath));
     if (!symlink($reference, $buildPath)) {
         $builder->logFailure('Failed to symlink.');
         return false;
     }
     return true;
 }
コード例 #7
0
ファイル: TechnicalDebt.php プロジェクト: zeus911/PHPCI
 /**
  * Runs the plugin
  */
 public function execute()
 {
     $success = true;
     $this->phpci->logExecOutput(false);
     $errorCount = $this->getErrorList();
     $this->phpci->log("Found {$errorCount} instances of " . implode(', ', $this->searches));
     $this->build->storeMeta('technical_debt-warnings', $errorCount);
     if ($this->allowed_errors != -1 && $errorCount > $this->allowed_errors) {
         $success = false;
     }
     return $success;
 }
コード例 #8
0
ファイル: Email.php プロジェクト: stefanius/phpci-box
 /**
  * Send a notification mail.
  */
 public function execute()
 {
     $addresses = $this->getEmailAddresses();
     // Without some email addresses in the yml file then we
     // can't do anything.
     if (count($addresses) == 0) {
         return false;
     }
     $buildStatus = $this->build->isSuccessful() ? "Passing Build" : "Failing Build";
     $projectName = $this->build->getProject()->getTitle();
     $mailTemplate = $this->build->isSuccessful() ? 'Email/success' : 'Email/failed';
     $view = new View($mailTemplate);
     $view->build = $this->build;
     $view->project = $this->build->getProject();
     $body = $view->render();
     $sendFailures = $this->sendSeparateEmails($addresses, sprintf("PHPCI - %s - %s", $projectName, $buildStatus), $body);
     // This is a success if we've not failed to send anything.
     $this->phpci->log(sprintf("%d emails sent", count($addresses) - $sendFailures));
     $this->phpci->log(sprintf("%d emails failed to send", $sendFailures));
     return $sendFailures === 0;
 }
コード例 #9
0
 /**
  * Calls the deployment url.
  *
  * @param string $deployUrl
  * @param string $method
  *
  * @return bool
  */
 protected function callDeploymentUrl($deployUrl, $method = 'get')
 {
     $curl = $this->getCurl();
     $this->phpci->log(sprintf('Calling remote deployment url %s with method (%s) on the %s branch', $deployUrl, $method, $this->branch));
     if ($method == 'GET') {
         $curl->get($deployUrl);
     }
     if ($method == 'POST') {
         $curl->post($deployUrl);
     }
     if ($curl->error) {
         $this->phpci->logFailure(sprintf('%s request to remote deployment url %s failed.', $method, $deployUrl));
         return false;
     }
     $this->phpci->logSuccess('Remote deployment request was successful.');
     return true;
 }
コード例 #10
0
 /**
  * Gets the number and list of errors returned from the search
  *
  * @return array
  */
 public function getErrorList()
 {
     $dirIterator = new \RecursiveDirectoryIterator($this->directory);
     $iterator = new \RecursiveIteratorIterator($dirIterator, \RecursiveIteratorIterator::SELF_FIRST);
     $files = array();
     $ignores = $this->ignore;
     $ignores[] = 'phpci.yml';
     foreach ($iterator as $file) {
         $filePath = $file->getRealPath();
         $skipFile = false;
         foreach ($ignores as $ignore) {
             if (stripos($filePath, $ignore) !== false) {
                 $skipFile = true;
                 break;
             }
         }
         // Ignore hidden files, else .git, .sass_cache, etc. all get looped over
         if (stripos($filePath, '/.') !== false) {
             $skipFile = true;
         }
         if ($skipFile == false) {
             $files[] = $file->getRealPath();
         }
     }
     $files = array_filter(array_unique($files));
     $errorCount = 0;
     $data = array();
     foreach ($files as $file) {
         foreach ($this->searches as $search) {
             $fileContent = file_get_contents($file);
             $allLines = explode(PHP_EOL, $fileContent);
             $beforeString = strstr($fileContent, $search, true);
             if (false !== $beforeString) {
                 $lines = explode(PHP_EOL, $beforeString);
                 $lineNumber = count($lines);
                 $content = trim($allLines[$lineNumber - 1]);
                 $errorCount++;
                 $this->phpci->log("Found {$search} on line {$lineNumber} of {$file}:\n{$content}");
                 $fileName = str_replace($this->directory, '', $file);
                 $data[] = array('file' => $fileName, 'line' => $lineNumber, 'message' => $content);
                 $this->build->reportError($this->phpci, $fileName, $lineNumber, $content);
             }
         }
     }
     return array($errorCount, $data);
 }
コード例 #11
0
ファイル: PhpCodeSniffer.php プロジェクト: zeus911/PHPCI
 /**
  * Process the PHPCS output report.
  * @param $output
  * @return array
  * @throws \Exception
  */
 protected function processReport($output)
 {
     $data = json_decode(trim($output), true);
     if (!is_array($data)) {
         $this->phpci->log($output);
         throw new \Exception(PHPCI\Helper\Lang::get('could_not_process_report'));
     }
     $errors = $data['totals']['errors'];
     $warnings = $data['totals']['warnings'];
     foreach ($data['files'] as $fileName => $file) {
         $fileName = str_replace($this->phpci->buildPath, '', $fileName);
         foreach ($file['messages'] as $message) {
             $this->build->reportError($this->phpci, 'php_code_sniffer', 'PHPCS: ' . $message['message'], $message['type'] == 'ERROR' ? BuildError::SEVERITY_HIGH : BuildError::SEVERITY_LOW, $fileName, $message['line']);
         }
     }
     return array($errors, $warnings);
 }
コード例 #12
0
ファイル: PhpMessDetector.php プロジェクト: zeus911/PHPCI
 /**
  * Process PHPMD's XML output report.
  * @param $xmlString
  * @return array
  * @throws \Exception
  */
 protected function processReport($xmlString)
 {
     $xml = simplexml_load_string($xmlString);
     if ($xml === false) {
         $this->phpci->log($xmlString);
         throw new \Exception('Could not process PHPMD report XML.');
     }
     $warnings = 0;
     foreach ($xml->file as $file) {
         $fileName = (string) $file['name'];
         $fileName = str_replace($this->phpci->buildPath, '', $fileName);
         foreach ($file->violation as $violation) {
             $warnings++;
             $this->build->reportError($this->phpci, 'php_mess_detector', (string) $violation, PHPCI\Model\BuildError::SEVERITY_HIGH, $fileName, (int) $violation['beginline'], (int) $violation['endline']);
         }
     }
     return $warnings;
 }
コード例 #13
0
ファイル: PhpCodeSniffer.php プロジェクト: kukupigs/PHPCI
 protected function processReport($output)
 {
     $data = json_decode(trim($output), true);
     if (!is_array($data)) {
         $this->phpci->log($output);
         throw new \Exception('Could not process PHPCS report JSON.');
     }
     $errors = $data['totals']['errors'];
     $warnings = $data['totals']['warnings'];
     $rtn = array();
     foreach ($data['files'] as $fileName => $file) {
         $fileName = str_replace($this->phpci->buildPath, '', $fileName);
         foreach ($file['messages'] as $message) {
             $rtn[] = array('file' => $fileName, 'line' => $message['line'], 'type' => $message['type'], 'message' => $message['message']);
         }
     }
     return array($errors, $warnings, $rtn);
 }
コード例 #14
0
 /**
  * Process the PHPCS output report.
  * @param $output
  * @return array
  * @throws \Exception
  */
 protected function processReport($output)
 {
     $data = json_decode(trim($output), true);
     if (!is_array($data)) {
         $this->phpci->log($output);
         throw new \Exception(PHPCI\Helper\Lang::get('could_not_process_report'));
     }
     $errors = $data['totals']['errors'];
     $warnings = $data['totals']['warnings'];
     $rtn = array();
     foreach ($data['files'] as $fileName => $file) {
         $fileName = str_replace($this->phpci->buildPath, '', $fileName);
         foreach ($file['messages'] as $message) {
             $this->build->reportError($this->phpci, $fileName, $message['line'], 'PHPCS: ' . $message['message']);
             $rtn[] = array('file' => $fileName, 'line' => $message['line'], 'type' => $message['type'], 'message' => $message['message']);
         }
     }
     return array($errors, $warnings, $rtn);
 }
コード例 #15
0
ファイル: PhpMessDetector.php プロジェクト: mrudtf/PHPCI
 /**
  * Process PHPMD's XML output report.
  * @param $xmlString
  * @return array
  * @throws \Exception
  */
 protected function processReport($xmlString)
 {
     $xml = simplexml_load_string($xmlString);
     if ($xml === false) {
         $this->phpci->log($xmlString);
         throw new \Exception('Could not process PHPMD report XML.');
     }
     $warnings = 0;
     $data = array();
     foreach ($xml->file as $file) {
         $fileName = (string) $file['name'];
         $fileName = str_replace($this->phpci->buildPath, '', $fileName);
         foreach ($file->violation as $violation) {
             $warnings++;
             $warning = array('file' => $fileName, 'line_start' => (int) $violation['beginline'], 'line_end' => (int) $violation['endline'], 'rule' => (string) $violation['rule'], 'ruleset' => (string) $violation['ruleset'], 'priority' => (int) $violation['priority'], 'message' => (string) $violation);
             $data[] = $warning;
         }
     }
     return array($warnings, $data);
 }
コード例 #16
0
 /**
  * Process JSHint's XML output report.
  * @param $xmlString
  * @return array
  * @throws \Exception
  */
 protected function processReport($xmlString)
 {
     $xml = simplexml_load_string($xmlString);
     if ($xml === false) {
         $this->phpci->log($xmlString);
         throw new \Exception('Could not process JSHint report XML.');
     }
     $warnings = 0;
     $data = array();
     foreach ($xml->file as $file) {
         $fileName = (string) $file['name'];
         $fileName = str_replace($this->phpci->buildPath, '', $fileName);
         foreach ($file->error as $error) {
             $warnings++;
             $warning = array('file' => $fileName, 'line' => (int) $error['line'], 'severity' => (string) $error['severity'], 'message' => (string) $error['message']);
             $this->build->reportError($this->phpci, $fileName, (int) $error['line'], (string) $error['message']);
             $data[] = $warning;
         }
     }
     return array($warnings, $data);
 }
コード例 #17
0
ファイル: Deployer.php プロジェクト: upassist/phpci-deployer
 /**
  * @param array $configuration
  * @return bool
  * @throws \Exception
  */
 private function _validateDeployerOptions($configuration = [])
 {
     if (empty($configuration)) {
         $configuration = $this->_getConfigurationForCurrentBranch();
     }
     if (empty($configuration['repository'])) {
         $this->phpci->logFailure('Deployer needs the repository variable set, this should be done automatically');
         return false;
     }
     if (empty($configuration['user'])) {
         $this->phpci->logFailure('Deployer needs the user variable set');
         return false;
     }
     if (empty($configuration['server'])) {
         $this->phpci->logFailure('Deployer needs the server variable set');
         return false;
     }
     if (empty($configuration['deploy_path'])) {
         $this->phpci->logFailure('Deployer needs the deploy_path variable set');
         return false;
     }
     if (isset($configuration['shared_dirs']) && !is_array($configuration['shared_dirs'])) {
         $this->phpci->logFailure('`shared_dirs` variable must be an array...');
         return false;
     }
     if (isset($configuration['writable_dirs']) && !is_array($configuration['writable_dirs'])) {
         $this->phpci->logFailure('`writable_dirs` variable must be an array...');
         return false;
     }
     $output = '';
     if (isset($this->options['deployFile'])) {
         $output .= '<b>Deploy file:</b> ' . $this->options['deployFile'] . PHP_EOL;
     }
     foreach ($configuration as $key => $value) {
         $output .= '<b>' . $key . ':</b> ';
         $output .= is_array($value) ? implode(PHP_EOL, $value) . PHP_EOL : $value . PHP_EOL;
     }
     $this->phpci->log('Using the following configuration:' . PHP_EOL . $output);
     return true;
 }