Skip to content
Permalink
Browse files

Added a new configuration variable, PHPCI_BUILD_ROOT_DI.

This variable allows to change where the build happens.
It defaults to PHPCI_DIR.'PHPCI/build/'.

Moved build path calculate and build removal into the Build class.

Also remove the build directory when deleting the build.

Close #834
  • Loading branch information...
Adirelle authored and tvbeek committed Feb 27, 2015
1 parent 60131ae commit 9590336c499047ff186248401331c8122c9ab9ae
Showing with 37 additions and 26 deletions.
  1. +6 −10 PHPCI/Builder.php
  2. +1 −16 PHPCI/Command/RunCommand.php
  3. +24 −0 PHPCI/Model/Build.php
  4. +1 −0 PHPCI/Service/BuildService.php
  5. +5 −0 vars.php
@@ -215,15 +215,6 @@ public function execute()
$this->pluginExecutor->executePlugins($this->config, 'failure');
$this->buildLogger->logFailure(Lang::get('build_failed'));
}
// Clean up:
$this->buildLogger->log(Lang::get('removing_build'));
$cmd = 'rm -Rf "%s"';
if (IS_WIN) {
$cmd = 'rmdir /S /Q "%s"';
}
$this->executeCommand($cmd, rtrim($this->buildPath, '/'));
} catch (\Exception $ex) {
$this->build->setStatus(Build::STATUS_FAILED);
$this->buildLogger->logFailure(Lang::get('exception') . $ex->getMessage());
@@ -233,6 +224,11 @@ public function execute()
// Update the build in the database, ping any external services, etc.
$this->build->sendStatusPostback();
$this->build->setFinished(new \DateTime());
// Clean up:
$this->buildLogger->log(Lang::get('removing_build'));
$this->build->removeBuildDirectory();
$this->store->save($this->build);
}
@@ -287,7 +283,7 @@ public function interpolate($input)
*/
protected function setupBuild()
{
$this->buildPath = PHPCI_DIR . 'PHPCI/build/' . $this->build->getId() . '/';
$this->buildPath = $this->build->getBuildPath() . '/';
$this->build->currentBuildPath = $this->buildPath;
$this->interpolator->setupInterpolationVars(
@@ -166,7 +166,7 @@ protected function validateRunningBuilds()
$build->setStatus(Build::STATUS_FAILED);
$build->setFinished(new \DateTime());
$store->save($build);
$this->removeBuildDirectory($build);
$build->removeBuildDirectory();
continue;
}
@@ -175,19 +175,4 @@ protected function validateRunningBuilds()
return $rtn;
}
protected function removeBuildDirectory($build)
{
$buildPath = PHPCI_DIR . 'PHPCI/build/' . $build->getId() . '/';
if (is_dir($buildPath)) {
$cmd = 'rm -Rf "%s"';
if (IS_WIN) {
$cmd = 'rmdir /S /Q "%s"';
}
shell_exec($cmd);
}
}
}
@@ -217,4 +217,28 @@ public function reportError(Builder $builder, $file, $line, $message)
{
return array($builder, $file, $line, $message);
}
/**
* Return the path to run this build into.
*
* @return string
*/
public function getBuildPath()
{
return PHPCI_BUILD_ROOT_DIR . $this->getId();
}
/**
* Removes the build directory.
*/
public function removeBuildDirectory()
{
$buildPath = $this->getBuildPath();
if (!is_dir($buildPath)) {
return;
}
exec(sprintf(IS_WIN ? 'rmdir /S /Q "%s"' : 'rm -Rf "%s"', $buildPath));
}
}
@@ -112,6 +112,7 @@ public function createDuplicateBuild(Build $copyFrom)
*/
public function deleteBuild(Build $build)
{
$build->removeBuildDirectory();
return $this->buildStore->delete($build);
}
}
@@ -16,6 +16,11 @@
define('PHPCI_BIN_DIR', PHPCI_DIR . 'vendor/bin/');
}
// Define PHPCI_BUILD_ROOT_DIR
if (!defined('PHPCI_BUILD_ROOT_DIR')) {
define('PHPCI_BUILD_ROOT_DIR', PHPCI_DIR . 'PHPCI/build/');
}
// Should PHPCI run the Shell plugin?
if (!defined('ENABLE_SHELL_PLUGIN')) {
define('ENABLE_SHELL_PLUGIN', false);

0 comments on commit 9590336

Please sign in to comment.
You can’t perform that action at this time.