protected function execute(InputInterface $input, OutputInterface $output)
 {
     $targetPlugin = $input->getOption('plugin');
     $artifactsPass = $input->getOption('artifacts-pass');
     $githubToken = $input->getOption('github-token');
     $outputYmlPath = $this->getTravisYmlOutputPath($input, $targetPlugin);
     $thisConsoleCommand = $this->getExecutedConsoleCommandForTravis($input);
     $view = new TravisYmlView();
     if (file_exists($outputYmlPath)) {
         $output->writeln("<info>Found existing YAML file at {$outputYmlPath}.</info>");
         $view->processExistingTravisYml($outputYmlPath);
     } else {
         $output->writeln("<info>Could not find existing YAML file at {$outputYmlPath}, generating a new one.</info>");
     }
     $view->configure($targetPlugin, $artifactsPass, $githubToken, $thisConsoleCommand, $output);
     $travisYmlContents = $view->render();
     $writePath = $input->getOption('dump');
     if (empty($writePath)) {
         $writePath = $outputYmlPath;
     }
     file_put_contents($writePath, $travisYmlContents);
     $this->writeSuccessMessage($output, array("Generated .travis.yml file at '{$writePath}'!"));
 }
Esempio n. 2
0
 public function testViewGeneratesCorrectLookingYAMLWhenCustomPhpVersionsUsed()
 {
     $view = new TravisYmlView();
     $view->setPlugin('ExamplePlugin');
     $view->setPhpVersions(array('5.4', '5.6', 'hhvm'));
     $view->setGenerateYmlCommand('./console generate:travis-yml arg1 arg2');
     $output = $view->render();
     $yaml = Spyc::YAMLLoadString($output);
     $this->assertNotEmpty($yaml['php']);
     $this->assertEquals(array('5.4', '5.6', 'hhvm'), $yaml['php']);
 }
 private function travisEncrypt($data, TravisYmlView $view, OutputInterface $output)
 {
     $output->writeln("Encrypting \"{$data}\"...");
     $command = "travis encrypt \"{$data}\"";
     // change dir to target plugin since plugin will be in its own git repo
     if (!empty($view->pluginName)) {
         $command = "cd \"" . $view->getPluginRootFolder() . "\" && " . $command;
     }
     exec($command, $commandOutput, $returnCode);
     if ($returnCode !== 0) {
         throw new Exception("Cannot encrypt \"{$data}\" for travis! Please make sure you have the travis command line " . "utility installed (see http://blog.travis-ci.com/2013-01-14-new-client/).\n\n" . "return code: {$returnCode}\n\n" . "travis output:\n\n" . implode("\n", $commandOutput));
     }
     if (empty($commandOutput)) {
         throw new Exception("Cannot parse travis encrypt output:\n\n" . implode("\n", $commandOutput));
     }
     // when not executed from a command line travis encrypt will return only the encrypted data
     $encryptedData = $commandOutput[0];
     if (substr($encryptedData, 0, 1) != '"' || substr($encryptedData, -1) != '"') {
         $encryptedData = '"' . addslashes($encryptedData) . '"';
     }
     return "secure: " . $encryptedData;
 }