Example #1
0
 public function build(Project $project, $revision = null, $flags = 0, $callback = null)
 {
     // project already has a running build
     if ($project->isBuilding() && Sismo::FORCE_BUILD !== ($flags & Sismo::FORCE_BUILD)) {
         return;
     }
     $this->builder->init($project, $callback);
     list($sha, $author, $date, $message) = $this->builder->prepare($revision, Sismo::LOCAL_BUILD !== ($flags & Sismo::LOCAL_BUILD));
     $commit = $this->storage->getCommit($project, $sha);
     // commit has already been built
     if ($commit && $commit->isBuilt() && Sismo::FORCE_BUILD !== ($flags & Sismo::FORCE_BUILD)) {
         return;
     }
     $commit = $this->storage->initCommit($project, $sha, $author, \DateTime::createFromFormat('Y-m-d H:i:s O', $date), $message);
     $process = $this->builder->build();
     if ($process->getExitCode() > 0) {
         $commit->setStatusCode('failed');
         $commit->setOutput(sprintf("Build failed\n\nOutput\n%s\n\n Error%s", $process->getOutput(), $process->getErrorOutput()));
     } else {
         $commit->setStatusCode('success');
         $commit->setOutput($process->getOutput());
     }
     $this->storage->updateCommit($commit);
     if (Sismo::SILENT_BUILD !== ($flags & Sismo::SILENT_BUILD)) {
         foreach ($project->getNotifiers() as $notifier) {
             $notifier->notify($commit);
         }
     }
 }