Added global application config (config.yml) option
'php-censor.build.allow_public_artifacts' for allow/deny to generate public artifacts (PHPUnit code coverage html report, Pdepend html reports). Issue #107.
This commit is contained in:
parent
0fc2a66678
commit
2a933a7ecb
|
@ -60,6 +60,7 @@ php-censor:
|
||||||
build:
|
build:
|
||||||
remove_builds: true # This option allow/deny build cleaning
|
remove_builds: true # This option allow/deny build cleaning
|
||||||
writer_buffer_size: 500 # BuildErrorWriter buffer size (count of inserts in one SQL query)
|
writer_buffer_size: 500 # BuildErrorWriter buffer size (count of inserts in one SQL query)
|
||||||
|
allow_public_artifacts: false # This option allow/deny to generate public artifacts (PHPUnit code coverage html report, Pdepend html reports)
|
||||||
security:
|
security:
|
||||||
disable_auth: false # This option allows/deny you to disable authentication for PHP Censor
|
disable_auth: false # This option allows/deny you to disable authentication for PHP Censor
|
||||||
default_user_id: 1 # Default user when authentication disabled
|
default_user_id: 1 # Default user when authentication disabled
|
||||||
|
|
|
@ -293,6 +293,7 @@ class InstallCommand extends Command
|
||||||
'build' => [
|
'build' => [
|
||||||
'remove_builds' => true,
|
'remove_builds' => true,
|
||||||
'writer_buffer_size' => 500,
|
'writer_buffer_size' => 500,
|
||||||
|
'allow_public_artifacts' => true,
|
||||||
],
|
],
|
||||||
'security' => [
|
'security' => [
|
||||||
'disable_auth' => false,
|
'disable_auth' => false,
|
||||||
|
|
|
@ -163,7 +163,7 @@ class RunCommand extends Command
|
||||||
$build->setStatus(Build::STATUS_FAILED);
|
$build->setStatus(Build::STATUS_FAILED);
|
||||||
$build->setFinishDate(new \DateTime());
|
$build->setFinishDate(new \DateTime());
|
||||||
$store->save($build);
|
$store->save($build);
|
||||||
$build->removeBuildDirectory();
|
$build->removeBuildDirectory(true);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -943,8 +943,10 @@ class Build extends Model
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the build directory.
|
* Removes the build directory.
|
||||||
|
*
|
||||||
|
* @param boolean $withArtifacts
|
||||||
*/
|
*/
|
||||||
public function removeBuildDirectory()
|
public function removeBuildDirectory($withArtifacts = false)
|
||||||
{
|
{
|
||||||
// Get the path and remove the trailing slash as this may prompt PHP
|
// Get the path and remove the trailing slash as this may prompt PHP
|
||||||
// to see this as a directory even if it's a link.
|
// to see this as a directory even if it's a link.
|
||||||
|
@ -964,10 +966,12 @@ class Build extends Model
|
||||||
$fileSystem->remove($buildPath);
|
$fileSystem->remove($buildPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($withArtifacts) {
|
||||||
$buildDirectory = $this->getBuildDirectory();
|
$buildDirectory = $this->getBuildDirectory();
|
||||||
|
|
||||||
$fileSystem->remove(PUBLIC_DIR . 'artifacts/pdepend/' . $buildDirectory);
|
$fileSystem->remove(PUBLIC_DIR . 'artifacts/pdepend/' . $buildDirectory);
|
||||||
$fileSystem->remove(PUBLIC_DIR . 'artifacts/phpunit/' . $buildDirectory);
|
$fileSystem->remove(PUBLIC_DIR . 'artifacts/phpunit/' . $buildDirectory);
|
||||||
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
namespace PHPCensor\Plugin\Option;
|
namespace PHPCensor\Plugin\Option;
|
||||||
|
|
||||||
|
use b8\Config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class PhpUnitOptions validates and parse the option for the PhpUnitV2 plugin
|
* Class PhpUnitOptions validates and parse the option for the PhpUnitV2 plugin
|
||||||
*
|
*
|
||||||
|
@ -120,7 +122,14 @@ class PhpUnitOptions
|
||||||
* Handles command aliases outside of the args option
|
* Handles command aliases outside of the args option
|
||||||
*/
|
*/
|
||||||
if (isset($this->options['coverage']) && $this->options['coverage']) {
|
if (isset($this->options['coverage']) && $this->options['coverage']) {
|
||||||
|
$allowPublicArtifacts = (bool)Config::getInstance()->get(
|
||||||
|
'php-censor.build.allow_public_artifacts',
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($allowPublicArtifacts) {
|
||||||
$this->addArgument('coverage-html', $this->location);
|
$this->addArgument('coverage-html', $this->location);
|
||||||
|
}
|
||||||
$this->addArgument('coverage-text');
|
$this->addArgument('coverage-text');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace PHPCensor\Plugin;
|
namespace PHPCensor\Plugin;
|
||||||
|
|
||||||
|
use b8\Config;
|
||||||
use PHPCensor\Builder;
|
use PHPCensor\Builder;
|
||||||
use PHPCensor\Model\Build;
|
use PHPCensor\Model\Build;
|
||||||
use PHPCensor\Plugin;
|
use PHPCensor\Plugin;
|
||||||
|
@ -91,19 +92,27 @@ class Pdepend extends Plugin
|
||||||
*/
|
*/
|
||||||
public function execute()
|
public function execute()
|
||||||
{
|
{
|
||||||
if (!file_exists($this->buildLocation)) {
|
$allowPublicArtifacts = (bool)Config::getInstance()->get(
|
||||||
mkdir($this->buildLocation, (0777 & ~umask()), true);
|
'php-censor.build.allow_public_artifacts',
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
$fileSystem = new Filesystem();
|
||||||
|
|
||||||
|
if (!$fileSystem->exists($this->buildLocation)) {
|
||||||
|
$fileSystem->mkdir($this->buildLocation, (0777 & ~umask()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_writable($this->buildLocation)) {
|
if (!is_writable($this->buildLocation)) {
|
||||||
throw new \Exception(sprintf('The location %s is not writable or does not exist.', $this->buildLocation));
|
throw new \Exception(sprintf(
|
||||||
|
'The location %s is not writable or does not exist.',
|
||||||
|
$this->buildLocation
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
$pdepend = $this->findBinary('pdepend');
|
$pdepend = $this->findBinary('pdepend');
|
||||||
|
|
||||||
$cmd = $pdepend . ' --summary-xml="%s" --jdepend-chart="%s" --overview-pyramid="%s" %s "%s"';
|
$cmd = $pdepend . ' --summary-xml="%s" --jdepend-chart="%s" --overview-pyramid="%s" %s "%s"';
|
||||||
|
|
||||||
$this->removeBuildArtifacts();
|
|
||||||
|
|
||||||
// If we need to ignore directories
|
// If we need to ignore directories
|
||||||
if (count($this->builder->ignore)) {
|
if (count($this->builder->ignore)) {
|
||||||
$ignore = ' --ignore=' . implode(',', $this->builder->ignore);
|
$ignore = ' --ignore=' . implode(',', $this->builder->ignore);
|
||||||
|
@ -120,16 +129,17 @@ class Pdepend extends Plugin
|
||||||
$this->directory
|
$this->directory
|
||||||
);
|
);
|
||||||
|
|
||||||
$fileSystem = new Filesystem();
|
if (!$allowPublicArtifacts) {
|
||||||
|
$fileSystem->remove($this->buildLocation);
|
||||||
if (file_exists($this->buildLocation)) {
|
}
|
||||||
|
if ($allowPublicArtifacts && file_exists($this->buildLocation)) {
|
||||||
$fileSystem->remove($this->buildBranchLocation);
|
$fileSystem->remove($this->buildBranchLocation);
|
||||||
$fileSystem->mirror($this->buildLocation, $this->buildBranchLocation);
|
$fileSystem->mirror($this->buildLocation, $this->buildBranchLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
$config = $this->builder->getSystemConfig('php-censor');
|
$config = $this->builder->getSystemConfig('php-censor');
|
||||||
|
|
||||||
if ($success) {
|
if ($allowPublicArtifacts && $success) {
|
||||||
$this->builder->logSuccess(
|
$this->builder->logSuccess(
|
||||||
sprintf(
|
sprintf(
|
||||||
"\nPdepend successful build report.\nYou can use report for this build for inclusion in the readme.md file:\n%s,\n![Chart](%s \"Pdepend Chart\") and\n![Pyramid](%s \"Pdepend Pyramid\")\n\nOr report for last build in the branch:\n%s,\n![Chart](%s \"Pdepend Chart\") and\n![Pyramid](%s \"Pdepend Pyramid\")\n",
|
"\nPdepend successful build report.\nYou can use report for this build for inclusion in the readme.md file:\n%s,\n![Chart](%s \"Pdepend Chart\") and\n![Pyramid](%s \"Pdepend Pyramid\")\n\nOr report for last build in the branch:\n%s,\n![Chart](%s \"Pdepend Chart\") and\n![Pyramid](%s \"Pdepend Pyramid\")\n",
|
||||||
|
@ -145,17 +155,4 @@ class Pdepend extends Plugin
|
||||||
|
|
||||||
return $success;
|
return $success;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove files created from previous builds
|
|
||||||
*/
|
|
||||||
protected function removeBuildArtifacts()
|
|
||||||
{
|
|
||||||
//Remove the created files first
|
|
||||||
foreach ([$this->summary, $this->chart, $this->pyramid] as $file) {
|
|
||||||
if (file_exists($this->buildLocation . DIRECTORY_SEPARATOR . $file)) {
|
|
||||||
unlink($this->buildLocation . DIRECTORY_SEPARATOR . $file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace PHPCensor\Plugin;
|
namespace PHPCensor\Plugin;
|
||||||
|
|
||||||
|
use b8\Config;
|
||||||
use PHPCensor;
|
use PHPCensor;
|
||||||
use PHPCensor\Builder;
|
use PHPCensor\Builder;
|
||||||
use PHPCensor\Model\Build;
|
use PHPCensor\Model\Build;
|
||||||
|
@ -76,7 +77,7 @@ class PhpUnit extends Plugin implements ZeroConfigPluginInterface
|
||||||
$this->buildLocation = PUBLIC_DIR . 'artifacts/phpunit/' . $this->buildDirectory;
|
$this->buildLocation = PUBLIC_DIR . 'artifacts/phpunit/' . $this->buildDirectory;
|
||||||
$this->buildBranchLocation = PUBLIC_DIR . 'artifacts/phpunit/' . $this->buildBranchDirectory;
|
$this->buildBranchLocation = PUBLIC_DIR . 'artifacts/phpunit/' . $this->buildBranchDirectory;
|
||||||
|
|
||||||
$this->options = new PhpUnitOptions($options, $this->buildLocation, $this->buildBranchLocation);
|
$this->options = new PhpUnitOptions($options, $this->buildLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -144,9 +145,18 @@ class PhpUnit extends Plugin implements ZeroConfigPluginInterface
|
||||||
* @param string $logFormat
|
* @param string $logFormat
|
||||||
*
|
*
|
||||||
* @return bool|mixed
|
* @return bool|mixed
|
||||||
|
*
|
||||||
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
protected function runConfig($directory, $configFile, $logFormat)
|
protected function runConfig($directory, $configFile, $logFormat)
|
||||||
{
|
{
|
||||||
|
$allowPublicArtifacts = (bool)Config::getInstance()->get(
|
||||||
|
'php-censor.build.allow_public_artifacts',
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
$fileSystem = new Filesystem();
|
||||||
|
|
||||||
$options = clone $this->options;
|
$options = clone $this->options;
|
||||||
$buildPath = $this->build->getBuildPath();
|
$buildPath = $this->build->getBuildPath();
|
||||||
|
|
||||||
|
@ -161,18 +171,29 @@ class PhpUnit extends Plugin implements ZeroConfigPluginInterface
|
||||||
$options->addArgument('configuration', $buildPath . $configFile);
|
$options->addArgument('configuration', $buildPath . $configFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
$fileSystem = new Filesystem();
|
if ($options->getOption('coverage') && $allowPublicArtifacts) {
|
||||||
|
if (!$fileSystem->exists($this->buildLocation)) {
|
||||||
if (!$fileSystem->exists($this->buildLocation) && $options->getOption('coverage')) {
|
|
||||||
$fileSystem->mkdir($this->buildLocation, (0777 & ~umask()));
|
$fileSystem->mkdir($this->buildLocation, (0777 & ~umask()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!is_writable($this->buildLocation)) {
|
||||||
|
throw new \Exception(sprintf(
|
||||||
|
'The location %s is not writable or does not exist.',
|
||||||
|
$this->buildLocation
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$arguments = $this->builder->interpolate($options->buildArgumentString());
|
$arguments = $this->builder->interpolate($options->buildArgumentString());
|
||||||
$cmd = $this->findBinary('phpunit') . ' %s %s';
|
$cmd = $this->findBinary('phpunit') . ' %s %s';
|
||||||
$success = $this->builder->executeCommand($cmd, $arguments, $directory);
|
$success = $this->builder->executeCommand($cmd, $arguments, $directory);
|
||||||
$output = $this->builder->getLastOutput();
|
$output = $this->builder->getLastOutput();
|
||||||
|
|
||||||
if ($fileSystem->exists($this->buildLocation) && $options->getOption('coverage')) {
|
if (
|
||||||
|
$fileSystem->exists($this->buildLocation) &&
|
||||||
|
$options->getOption('coverage') &&
|
||||||
|
$allowPublicArtifacts
|
||||||
|
) {
|
||||||
$fileSystem->remove($this->buildBranchLocation);
|
$fileSystem->remove($this->buildBranchLocation);
|
||||||
$fileSystem->mirror($this->buildLocation, $this->buildBranchLocation);
|
$fileSystem->mirror($this->buildLocation, $this->buildBranchLocation);
|
||||||
}
|
}
|
||||||
|
@ -194,6 +215,7 @@ class PhpUnit extends Plugin implements ZeroConfigPluginInterface
|
||||||
'lines' => !empty($matches[3]) ? $matches[3] : '0.00',
|
'lines' => !empty($matches[3]) ? $matches[3] : '0.00',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if ($allowPublicArtifacts) {
|
||||||
$this->builder->logSuccess(
|
$this->builder->logSuccess(
|
||||||
sprintf(
|
sprintf(
|
||||||
"\nPHPUnit successful build coverage report.\nYou can use coverage report for this build: %s\nOr coverage report for last build in the branch: %s",
|
"\nPHPUnit successful build coverage report.\nYou can use coverage report for this build: %s\nOr coverage report for last build in the branch: %s",
|
||||||
|
@ -202,6 +224,7 @@ class PhpUnit extends Plugin implements ZeroConfigPluginInterface
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $success;
|
return $success;
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,7 +150,7 @@ class BuildService
|
||||||
*/
|
*/
|
||||||
public function deleteBuild(Build $build)
|
public function deleteBuild(Build $build)
|
||||||
{
|
{
|
||||||
$build->removeBuildDirectory();
|
$build->removeBuildDirectory(true);
|
||||||
|
|
||||||
return $this->buildStore->delete($build);
|
return $this->buildStore->delete($build);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue