diff --git a/docs/en/configuring_project.md b/docs/en/configuring_project.md index 631ab4fb..82aff672 100644 --- a/docs/en/configuring_project.md +++ b/docs/en/configuring_project.md @@ -42,6 +42,12 @@ test: grunt: task: "build" +deploy: + deployer: + webhook_url: "http://deployer.local/deploy/QZaF1bMIUqbMFTmKDmgytUuykRN0cjCgW9SooTnwkIGETAYhDTTYoR8C431t" + reason: "PHP Censor Build #%BUILD% - %COMMIT_MESSAGE%" + update_only: true + complete: mysql: host: "localhost" @@ -62,6 +68,8 @@ As mentioned earlier, PHP Censor is powered by plugins, there are several phases * `test` - The tests that should be run during the build. Plugins run during this phase will contribute to the success or failure of the build. +* `deploy` - The deploy that should be run after the build. Plugins run during this phase will contribute to the success or failure of the build. + * `complete` - Always called when the `test` phase completes, regardless of success or failure. **Note** that is you do any DB stuff here, you will need to add the DB credentials to this section as well, as it runs in a separate instance. * `success` - Called upon success of the `test` phase. diff --git a/src/PHPCensor/Builder.php b/src/PHPCensor/Builder.php index 6ccbf389..bc4fcd0c 100644 --- a/src/PHPCensor/Builder.php +++ b/src/PHPCensor/Builder.php @@ -190,7 +190,7 @@ class Builder implements LoggerAwareInterface $this->setupBuild(); // Run the core plugin stages: - foreach (['setup', 'test', 'deploy'] as $stage) { + foreach ([Build::STAGE_SETUP, Build::STAGE_TEST, Build::STAGE_DEPLOY] as $stage) { $success &= $this->pluginExecutor->executePlugins($this->config, $stage); } @@ -204,16 +204,16 @@ class Builder implements LoggerAwareInterface if ($success) { - $this->pluginExecutor->executePlugins($this->config, 'success'); + $this->pluginExecutor->executePlugins($this->config, Build::STAGE_SUCCESS); if ($previous_state == Build::STATUS_FAILED) { - $this->pluginExecutor->executePlugins($this->config, 'fixed'); + $this->pluginExecutor->executePlugins($this->config, Build::STAGE_FIXED); } } else { - $this->pluginExecutor->executePlugins($this->config, 'failure'); + $this->pluginExecutor->executePlugins($this->config, Build::STAGE_FAILURE); if ($previous_state == Build::STATUS_SUCCESS || $previous_state == Build::STATUS_PENDING) { - $this->pluginExecutor->executePlugins($this->config, 'broken'); + $this->pluginExecutor->executePlugins($this->config, Build::STAGE_BROKEN); } } } catch (\Exception $ex) { @@ -229,7 +229,7 @@ class Builder implements LoggerAwareInterface try { // Complete stage plugins are always run - $this->pluginExecutor->executePlugins($this->config, 'complete'); + $this->pluginExecutor->executePlugins($this->config, Build::STAGE_COMPLETE); } catch (\Exception $ex) { $this->buildLogger->logFailure('Exception: ' . $ex->getMessage()); } diff --git a/src/PHPCensor/Model/Build.php b/src/PHPCensor/Model/Build.php index 5568a429..51efac39 100644 --- a/src/PHPCensor/Model/Build.php +++ b/src/PHPCensor/Model/Build.php @@ -12,6 +12,15 @@ use b8\Store\Factory; */ class Build extends Model { + const STAGE_SETUP = 'setup'; + const STAGE_TEST = 'test'; + const STAGE_DEPLOY = 'deploy'; + const STAGE_COMPLETE = 'complete'; + const STAGE_SUCCESS = 'success'; + const STAGE_FAILURE = 'failure'; + const STAGE_FIXED = 'fixed'; + const STAGE_BROKEN = 'broken'; + /** * @var array */ @@ -739,7 +748,7 @@ class Build extends Model continue; } - foreach (['setup', 'test', 'complete', 'success', 'failure'] as $stage) { + foreach ([Build::STAGE_SETUP, Build::STAGE_TEST] as $stage) { if ($className::canExecute($stage, $builder, $this)) { $config[$stage][$className::pluginName()] = [ 'zero_config' => true diff --git a/src/PHPCensor/Plugin/Codeception.php b/src/PHPCensor/Plugin/Codeception.php index 402fc887..5210f960 100644 --- a/src/PHPCensor/Plugin/Codeception.php +++ b/src/PHPCensor/Plugin/Codeception.php @@ -72,7 +72,7 @@ class Codeception extends Plugin implements ZeroConfigPluginInterface */ public static function canExecute($stage, Builder $builder, Build $build) { - return $stage == 'test' && !is_null(self::findConfigFile($builder->buildPath)); + return $stage == Build::STAGE_TEST && !is_null(self::findConfigFile($builder->buildPath)); } /** diff --git a/src/PHPCensor/Plugin/Composer.php b/src/PHPCensor/Plugin/Composer.php index 25b95958..bc8e81c7 100644 --- a/src/PHPCensor/Plugin/Composer.php +++ b/src/PHPCensor/Plugin/Composer.php @@ -82,7 +82,7 @@ class Composer extends Plugin implements ZeroConfigPluginInterface { $path = $builder->buildPath . DIRECTORY_SEPARATOR . 'composer.json'; - if (file_exists($path) && $stage == 'setup') { + if (file_exists($path) && $stage == Build::STAGE_SETUP) { return true; } diff --git a/src/PHPCensor/Plugin/PhpCodeSniffer.php b/src/PHPCensor/Plugin/PhpCodeSniffer.php index 917083de..81734183 100644 --- a/src/PHPCensor/Plugin/PhpCodeSniffer.php +++ b/src/PHPCensor/Plugin/PhpCodeSniffer.php @@ -131,7 +131,7 @@ class PhpCodeSniffer extends Plugin implements ZeroConfigPluginInterface */ public static function canExecute($stage, Builder $builder, Build $build) { - if ($stage == 'test') { + if ($stage == Build::STAGE_TEST) { return true; } diff --git a/src/PHPCensor/Plugin/PhpCpd.php b/src/PHPCensor/Plugin/PhpCpd.php index 80d50b90..0ba8c137 100644 --- a/src/PHPCensor/Plugin/PhpCpd.php +++ b/src/PHPCensor/Plugin/PhpCpd.php @@ -67,7 +67,7 @@ class PhpCpd extends Plugin implements ZeroConfigPluginInterface */ public static function canExecute($stage, Builder $builder, Build $build) { - if ($stage == 'test') { + if ($stage == Build::STAGE_TEST) { return true; } diff --git a/src/PHPCensor/Plugin/PhpDocblockChecker.php b/src/PHPCensor/Plugin/PhpDocblockChecker.php index 6187d70e..dddea556 100644 --- a/src/PHPCensor/Plugin/PhpDocblockChecker.php +++ b/src/PHPCensor/Plugin/PhpDocblockChecker.php @@ -79,7 +79,7 @@ class PhpDocblockChecker extends Plugin implements ZeroConfigPluginInterface */ public static function canExecute($stage, Builder $builder, Build $build) { - if ($stage == 'test') { + if ($stage == Build::STAGE_TEST) { return true; } diff --git a/src/PHPCensor/Plugin/PhpLoc.php b/src/PHPCensor/Plugin/PhpLoc.php index 391fa6b0..4f9b1f96 100644 --- a/src/PHPCensor/Plugin/PhpLoc.php +++ b/src/PHPCensor/Plugin/PhpLoc.php @@ -37,7 +37,7 @@ class PhpLoc extends Plugin implements ZeroConfigPluginInterface */ public static function canExecute($stage, Builder $builder, Build $build) { - if ($stage == 'test') { + if ($stage == Build::STAGE_TEST) { return true; } diff --git a/src/PHPCensor/Plugin/PhpMessDetector.php b/src/PHPCensor/Plugin/PhpMessDetector.php index 56e27e13..82754ac7 100644 --- a/src/PHPCensor/Plugin/PhpMessDetector.php +++ b/src/PHPCensor/Plugin/PhpMessDetector.php @@ -87,7 +87,7 @@ class PhpMessDetector extends Plugin implements ZeroConfigPluginInterface */ public static function canExecute($stage, Builder $builder, Build $build) { - if ($stage == 'test') { + if ($stage == Build::STAGE_TEST) { return true; } diff --git a/src/PHPCensor/Plugin/PhpParallelLint.php b/src/PHPCensor/Plugin/PhpParallelLint.php index 4026ba82..158798ec 100644 --- a/src/PHPCensor/Plugin/PhpParallelLint.php +++ b/src/PHPCensor/Plugin/PhpParallelLint.php @@ -80,7 +80,7 @@ class PhpParallelLint extends Plugin implements ZeroConfigPluginInterface */ public static function canExecute($stage, Builder $builder, Build $build) { - if ($stage == 'test') { + if ($stage == Build::STAGE_TEST) { return true; } diff --git a/src/PHPCensor/Plugin/PhpUnit.php b/src/PHPCensor/Plugin/PhpUnit.php index 7ad15045..a005d2ea 100644 --- a/src/PHPCensor/Plugin/PhpUnit.php +++ b/src/PHPCensor/Plugin/PhpUnit.php @@ -60,7 +60,7 @@ class PhpUnit extends Plugin implements ZeroConfigPluginInterface */ public static function canExecute($stage, Builder $builder, Build $build) { - if ($stage == 'test' && !is_null(PhpUnitOptions::findConfigFile($build->getBuildPath()))) { + if ($stage == Build::STAGE_TEST && !is_null(PhpUnitOptions::findConfigFile($build->getBuildPath()))) { return true; } diff --git a/src/PHPCensor/Plugin/TechnicalDebt.php b/src/PHPCensor/Plugin/TechnicalDebt.php index 0a738817..d349041b 100644 --- a/src/PHPCensor/Plugin/TechnicalDebt.php +++ b/src/PHPCensor/Plugin/TechnicalDebt.php @@ -87,7 +87,7 @@ class TechnicalDebt extends Plugin implements ZeroConfigPluginInterface */ public static function canExecute($stage, Builder $builder, Build $build) { - if ($stage == 'test') { + if ($stage == Build::STAGE_TEST) { return true; } diff --git a/src/PHPCensor/Plugin/Util/Executor.php b/src/PHPCensor/Plugin/Util/Executor.php index d502119d..5f430390 100644 --- a/src/PHPCensor/Plugin/Util/Executor.php +++ b/src/PHPCensor/Plugin/Util/Executor.php @@ -149,18 +149,18 @@ class Executor // Execution failed $this->setPluginStatus($stage, $plugin, Build::STATUS_FAILED); - if ($stage === 'setup') { + if ($stage === Build::STAGE_SETUP) { $this->logger->logFailure('PLUGIN: FAILED'); // If we're in the "setup" stage, execution should not continue after // a plugin has failed: throw new Exception('Plugin failed: ' . $plugin); - } elseif ($stage === 'deploy') { + } elseif ($stage === Build::STAGE_DEPLOY) { $this->logger->logFailure('PLUGIN: FAILED'); $success = false; } else { // If we're in the "test" stage and the plugin is not allowed to fail, // then mark the build as failed: - if (empty($options['allow_failures']) && $stage === 'test') { + if (empty($options['allow_failures']) && $stage === Build::STAGE_TEST) { $this->logger->logFailure('PLUGIN: FAILED'); $success = false; } else {