Exemplo n.º 1
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;
 }
Exemplo n.º 2
0
 /**
  * Initialise the logger
  *
  * By default a log is saved to file into the @home/log folder and
  * the log messages are stored by DeploYiiLogHandler to be used later.
  */
 private static function _initLogger()
 {
     $logDir = Shell::getHomeDir() . DIRECTORY_SEPARATOR . 'log';
     self::$logFile = $logDir . DIRECTORY_SEPARATOR . date('Ymd_His') . uniqid() . '.log';
     if (!is_dir($logDir)) {
         FileHelper::createDirectory($logDir);
     }
     self::$_logger = new Logger('main');
     $streamHandler = new StreamHandler(self::$logFile, Logger::DEBUG);
     /** @noinspection PhpParamsInspection */
     $streamHandler->pushProcessor(new PsrLogMessageProcessor());
     self::$deployiiHandler = new DeploYiiLogHandler();
     /** @noinspection PhpParamsInspection */
     self::$deployiiHandler->pushProcessor(new PsrLogMessageProcessor());
     self::$_logger->pushHandler($streamHandler);
     self::$_logger->pushHandler(self::$deployiiHandler);
 }
Exemplo n.º 3
0
 /**
  * @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;
 }
Exemplo n.º 4
0
 /**
  * Compare the php files of the built-in commands and recipes with the user defined ones.
  * If the user defined ones have the same name of the built-in ones, throws and exception.
  *
  * File names are converted to lower case so that the check is case insensitive.
  *
  * @throws \yii\console\Exception if a built-in command or recipe has been overridden
  */
 private function _checkUserScripts()
 {
     $buildScripts = Yii::getAlias('@buildScripts');
     $home = Shell::getHomeDir();
     $builtInCommands = $this->getLowercaseBaseNames(glob(__DIR__ . '/commands/*.php'));
     $builtInRecipes = $this->getLowercaseBaseNames(glob(__DIR__ . '/recipes/*.php'));
     $userGlobalCommands = $this->getLowercaseBaseNames(glob($home . '/commands/*.php'));
     $userGlobalRecipes = $this->getLowercaseBaseNames(glob($home . '/recipes/*.php'));
     $userBuildCommands = $this->getLowercaseBaseNames(glob($buildScripts . '/commands/*.php'));
     $userBuildRecipes = $this->getLowercaseBaseNames(glob($buildScripts . '/recipes/*.php'));
     $userCommands = array_merge($userBuildCommands, $userGlobalCommands);
     $userRecipes = array_merge($userBuildRecipes, $userGlobalRecipes);
     $overridingCommands = array_intersect($builtInCommands, $userCommands);
     $overridingRecipes = array_intersect($builtInRecipes, $userRecipes);
     if (!empty($overridingCommands) || !empty($overridingRecipes)) {
         Log::throwException('You cannot override built-in commands or recipes: ' . trim(implode(", ", $overridingCommands) . ", " . implode(".", $overridingRecipes), ', '));
     }
     $overridingUserCommands = array_intersect($userGlobalCommands, $userBuildCommands);
     $overridingUserRecipes = array_intersect($userGlobalRecipes, $userBuildRecipes);
     if (!empty($overridingUserCommands) || !empty($overridingUserRecipes)) {
         $this->controller->warn('You are overriding global commands or recipes: ' . trim(implode(", ", $overridingUserCommands) . ", " . implode(".", $overridingUserRecipes), ', ') . "\n");
     }
 }
Exemplo n.º 5
0
 /**
  * @return string The DeploYii home version
  */
 public static function getHomeVersion()
 {
     $versionFile = Shell::getHomeDir() . '/VERSION';
     if (!file_exists($versionFile)) {
         self::updateHomeVersion();
     }
     return trim(file_get_contents($versionFile));
 }
Exemplo n.º 6
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     Shell::initHomeDir();
 }