Skip to content

Commit

Permalink
Added a new configuration variable, PHPCI_BUILD_ROOT_DI.
Browse files Browse the repository at this point in the history
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 Apr 22, 2015
1 parent 60131ae commit 9590336
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 26 deletions.
16 changes: 6 additions & 10 deletions PHPCI/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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);
}

Expand Down Expand Up @@ -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(
Expand Down
17 changes: 1 addition & 16 deletions PHPCI/Command/RunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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);
}
}
}
24 changes: 24 additions & 0 deletions PHPCI/Model/Build.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
1 change: 1 addition & 0 deletions PHPCI/Service/BuildService.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public function createDuplicateBuild(Build $copyFrom)
*/
public function deleteBuild(Build $build)
{
$build->removeBuildDirectory();
return $this->buildStore->delete($build);
}
}
5 changes: 5 additions & 0 deletions vars.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9590336

Please sign in to comment.