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:
Dmitry Khomutov 2018-03-08 00:47:09 +07:00
parent 0fc2a66678
commit 2a933a7ecb
No known key found for this signature in database
GPG key ID: EC19426474B37AAC
8 changed files with 82 additions and 47 deletions

View file

@ -58,8 +58,9 @@ php-censor:
status:
commit: false # This option allow/deny to post status to Github commit
build:
remove_builds: true # This option allow/deny build cleaning
writer_buffer_size: 500 # BuildErrorWriter buffer size (count of inserts in one SQL query)
remove_builds: true # This option allow/deny build cleaning
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:
disable_auth: false # This option allows/deny you to disable authentication for PHP Censor
default_user_id: 1 # Default user when authentication disabled

View file

@ -291,8 +291,9 @@ class InstallCommand extends Command
],
],
'build' => [
'remove_builds' => true,
'writer_buffer_size' => 500,
'remove_builds' => true,
'writer_buffer_size' => 500,
'allow_public_artifacts' => true,
],
'security' => [
'disable_auth' => false,

View file

@ -163,7 +163,7 @@ class RunCommand extends Command
$build->setStatus(Build::STATUS_FAILED);
$build->setFinishDate(new \DateTime());
$store->save($build);
$build->removeBuildDirectory();
$build->removeBuildDirectory(true);
continue;
}

View file

@ -943,8 +943,10 @@ class Build extends Model
/**
* 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
// to see this as a directory even if it's a link.
@ -964,10 +966,12 @@ class Build extends Model
$fileSystem->remove($buildPath);
}
$buildDirectory = $this->getBuildDirectory();
if ($withArtifacts) {
$buildDirectory = $this->getBuildDirectory();
$fileSystem->remove(PUBLIC_DIR . 'artifacts/pdepend/' . $buildDirectory);
$fileSystem->remove(PUBLIC_DIR . 'artifacts/phpunit/' . $buildDirectory);
$fileSystem->remove(PUBLIC_DIR . 'artifacts/pdepend/' . $buildDirectory);
$fileSystem->remove(PUBLIC_DIR . 'artifacts/phpunit/' . $buildDirectory);
}
} catch (\Exception $e) {
}

View file

@ -2,6 +2,8 @@
namespace PHPCensor\Plugin\Option;
use b8\Config;
/**
* 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
*/
if (isset($this->options['coverage']) && $this->options['coverage']) {
$this->addArgument('coverage-html', $this->location);
$allowPublicArtifacts = (bool)Config::getInstance()->get(
'php-censor.build.allow_public_artifacts',
true
);
if ($allowPublicArtifacts) {
$this->addArgument('coverage-html', $this->location);
}
$this->addArgument('coverage-text');
}

View file

@ -2,6 +2,7 @@
namespace PHPCensor\Plugin;
use b8\Config;
use PHPCensor\Builder;
use PHPCensor\Model\Build;
use PHPCensor\Plugin;
@ -91,18 +92,26 @@ class Pdepend extends Plugin
*/
public function execute()
{
if (!file_exists($this->buildLocation)) {
mkdir($this->buildLocation, (0777 & ~umask()), true);
$allowPublicArtifacts = (bool)Config::getInstance()->get(
'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)) {
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');
$cmd = $pdepend . ' --summary-xml="%s" --jdepend-chart="%s" --overview-pyramid="%s" %s "%s"';
$this->removeBuildArtifacts();
$cmd = $pdepend . ' --summary-xml="%s" --jdepend-chart="%s" --overview-pyramid="%s" %s "%s"';
// If we need to ignore directories
if (count($this->builder->ignore)) {
@ -120,16 +129,17 @@ class Pdepend extends Plugin
$this->directory
);
$fileSystem = new Filesystem();
if (file_exists($this->buildLocation)) {
if (!$allowPublicArtifacts) {
$fileSystem->remove($this->buildLocation);
}
if ($allowPublicArtifacts && file_exists($this->buildLocation)) {
$fileSystem->remove($this->buildBranchLocation);
$fileSystem->mirror($this->buildLocation, $this->buildBranchLocation);
}
$config = $this->builder->getSystemConfig('php-censor');
if ($success) {
if ($allowPublicArtifacts && $success) {
$this->builder->logSuccess(
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",
@ -145,17 +155,4 @@ class Pdepend extends Plugin
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);
}
}
}
}

View file

@ -2,6 +2,7 @@
namespace PHPCensor\Plugin;
use b8\Config;
use PHPCensor;
use PHPCensor\Builder;
use PHPCensor\Model\Build;
@ -76,7 +77,7 @@ class PhpUnit extends Plugin implements ZeroConfigPluginInterface
$this->buildLocation = PUBLIC_DIR . 'artifacts/phpunit/' . $this->buildDirectory;
$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
*
* @return bool|mixed
*
* @throws \Exception
*/
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;
$buildPath = $this->build->getBuildPath();
@ -161,10 +171,17 @@ class PhpUnit extends Plugin implements ZeroConfigPluginInterface
$options->addArgument('configuration', $buildPath . $configFile);
}
$fileSystem = new Filesystem();
if ($options->getOption('coverage') && $allowPublicArtifacts) {
if (!$fileSystem->exists($this->buildLocation)) {
$fileSystem->mkdir($this->buildLocation, (0777 & ~umask()));
}
if (!$fileSystem->exists($this->buildLocation) && $options->getOption('coverage')) {
$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());
@ -172,7 +189,11 @@ class PhpUnit extends Plugin implements ZeroConfigPluginInterface
$success = $this->builder->executeCommand($cmd, $arguments, $directory);
$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->mirror($this->buildLocation, $this->buildBranchLocation);
}
@ -194,13 +215,15 @@ class PhpUnit extends Plugin implements ZeroConfigPluginInterface
'lines' => !empty($matches[3]) ? $matches[3] : '0.00',
]);
$this->builder->logSuccess(
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",
$config['url'] . '/artifacts/phpunit/' . $this->buildDirectory . '/index.html',
$config['url'] . '/artifacts/phpunit/' . $this->buildBranchDirectory . '/index.html'
)
);
if ($allowPublicArtifacts) {
$this->builder->logSuccess(
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",
$config['url'] . '/artifacts/phpunit/' . $this->buildDirectory . '/index.html',
$config['url'] . '/artifacts/phpunit/' . $this->buildBranchDirectory . '/index.html'
)
);
}
}
return $success;

View file

@ -150,7 +150,7 @@ class BuildService
*/
public function deleteBuild(Build $build)
{
$build->removeBuildDirectory();
$build->removeBuildDirectory(true);
return $this->buildStore->delete($build);
}