Exemple #1
0
 /**
  * This command echoes what you have entered as the message.
  *
  * @param string $workspace Path to the project workspace
  * @param string $target    The target to be ran; if not specified "default" will be used
  *
  * @return int The exit code
  */
 public function actionIndex($workspace, $target = '')
 {
     $this->workspace = realpath($workspace);
     $buildFile = $this->workspace . DIRECTORY_SEPARATOR . $this->getScriptFolder() . DIRECTORY_SEPARATOR . 'build.php';
     $taskRunner = new TaskRunner($this, $buildFile);
     $exitCode = $taskRunner->run($target);
     $this->stdout("\n");
     return $exitCode;
 }
Exemple #2
0
 /**
  * @param string $workspace Path to the project workspace
  *
  * @return int The exit code
  */
 public function actionIndex($workspace)
 {
     $exitCode = 0;
     $this->_checkDirectory($workspace);
     $this->workspace = realpath($workspace);
     $scriptsDir = $this->workspace . DIRECTORY_SEPARATOR . $this->getScriptFolder();
     $this->_checkDirectory($scriptsDir);
     $buildFile = $scriptsDir . DIRECTORY_SEPARATOR . 'build.php';
     if (file_exists($buildFile)) {
         Log::throwException('Build script already exists in the given workspace: ' . $buildFile);
     } else {
         $home = Shell::getHomeDir();
         $srcFile = $home . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'build.tpl.php';
         if (file_exists($srcFile)) {
             $this->stdout('- ');
             $this->logStdout('Generating build script: ' . $buildFile . "\n");
             if (!$this->dryRun) {
                 $template = file_get_contents($srcFile);
                 $template = str_replace('{{deployiiVersion}}', DEPLOYII_VERSION, $template);
                 // Save build file
                 file_put_contents($buildFile, $template);
                 // Copy gitignore
                 copy($home . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'gitignore.tpl', $scriptsDir . DIRECTORY_SEPARATOR . '.gitignore');
                 // Copy config.php (if needed)
                 if ($this->interactive) {
                     $createConf = $this->confirm('Do you need to create the build configuration file?', $this->createConfig);
                 } else {
                     $createConf = $this->createConfig;
                 }
                 if ($createConf) {
                     $configFile = $home . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'config.tpl.php';
                     $buildConfigFile = $scriptsDir . DIRECTORY_SEPARATOR . 'config.php';
                     if (!file_exists($buildConfigFile)) {
                         $this->logStdout('Generating build config: ' . $buildConfigFile . "\n");
                         copy($configFile, $buildConfigFile);
                     } else {
                         Log::throwException('Build configuration already exists in the given workspace: ' . $buildConfigFile);
                     }
                 }
                 $run = $this->confirm('Do you want to run the build script?', $this->run);
                 if ($run) {
                     $taskRunner = new TaskRunner($this, $buildFile);
                     $exitCode = $taskRunner->run();
                 }
             }
         }
     }
     $this->stdout("\n");
     return $exitCode;
 }
 /**
  * @param $projectId
  *
  * @return int The exit code
  */
 public function actionIndex($projectId)
 {
     $exitCode = 0;
     // TODO: read info from the database
     $projectInfo = (object) (require __DIR__ . '/../projects_tmp/' . $projectId . '.php');
     // ------------------------
     $home = Shell::getHomeDir();
     $this->workspace = $home . DIRECTORY_SEPARATOR . 'workspace' . DIRECTORY_SEPARATOR . $projectInfo->id . "_" . time();
     $this->stdout('Fetching into ');
     $this->stdout($this->workspace . "\n", Console::FG_CYAN);
     $gitClone = false;
     try {
         $wrapper = new GitWrapper();
         $gitOptions = [];
         if (!empty($projectInfo->branch)) {
             $gitOptions['branch'] = $projectInfo->branch;
         }
         $gitClone = $wrapper->cloneRepository($projectInfo->repo, $this->workspace, $gitOptions);
     } catch (GitException $e) {
         $this->stderr($e->getMessage(), Console::FG_RED);
         $exitCode = 1;
     }
     if (!empty($projectInfo->rootFolder)) {
         $this->workspace .= '/' . $projectInfo->rootFolder;
     }
     if ($gitClone && $this->run) {
         // TODO: parametrise deployii folder name / path (relative to workspace)
         $buildFile = $this->workspace . '/' . $this->getScriptFolder() . '/build.php';
         if (file_exists($buildFile)) {
             $taskRunner = new TaskRunner($this, $buildFile);
             $exitCode = $taskRunner->run($this->target);
         } else {
             $this->stderr("Build file not found: " . $buildFile, Console::FG_RED);
             $exitCode = 1;
         }
     }
     $this->stdout("\n");
     return $exitCode;
 }