Improvements for new 'deploy' stage

This commit is contained in:
Dmitry Khomutov 2017-03-16 21:54:25 +07:00
parent 788aeb161a
commit 21a73abd16
No known key found for this signature in database
GPG key ID: 7EB36C9576F9ECB9
14 changed files with 37 additions and 20 deletions

View file

@ -42,6 +42,12 @@ test:
grunt: grunt:
task: "build" task: "build"
deploy:
deployer:
webhook_url: "http://deployer.local/deploy/QZaF1bMIUqbMFTmKDmgytUuykRN0cjCgW9SooTnwkIGETAYhDTTYoR8C431t"
reason: "PHP Censor Build #%BUILD% - %COMMIT_MESSAGE%"
update_only: true
complete: complete:
mysql: mysql:
host: "localhost" 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. * `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. * `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. * `success` - Called upon success of the `test` phase.

View file

@ -190,7 +190,7 @@ class Builder implements LoggerAwareInterface
$this->setupBuild(); $this->setupBuild();
// Run the core plugin stages: // 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); $success &= $this->pluginExecutor->executePlugins($this->config, $stage);
} }
@ -204,16 +204,16 @@ class Builder implements LoggerAwareInterface
if ($success) { if ($success) {
$this->pluginExecutor->executePlugins($this->config, 'success'); $this->pluginExecutor->executePlugins($this->config, Build::STAGE_SUCCESS);
if ($previous_state == Build::STATUS_FAILED) { if ($previous_state == Build::STATUS_FAILED) {
$this->pluginExecutor->executePlugins($this->config, 'fixed'); $this->pluginExecutor->executePlugins($this->config, Build::STAGE_FIXED);
} }
} else { } 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) { 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) { } catch (\Exception $ex) {
@ -229,7 +229,7 @@ class Builder implements LoggerAwareInterface
try { try {
// Complete stage plugins are always run // Complete stage plugins are always run
$this->pluginExecutor->executePlugins($this->config, 'complete'); $this->pluginExecutor->executePlugins($this->config, Build::STAGE_COMPLETE);
} catch (\Exception $ex) { } catch (\Exception $ex) {
$this->buildLogger->logFailure('Exception: ' . $ex->getMessage()); $this->buildLogger->logFailure('Exception: ' . $ex->getMessage());
} }

View file

@ -12,6 +12,15 @@ use b8\Store\Factory;
*/ */
class Build extends Model 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 * @var array
*/ */
@ -739,7 +748,7 @@ class Build extends Model
continue; continue;
} }
foreach (['setup', 'test', 'complete', 'success', 'failure'] as $stage) { foreach ([Build::STAGE_SETUP, Build::STAGE_TEST] as $stage) {
if ($className::canExecute($stage, $builder, $this)) { if ($className::canExecute($stage, $builder, $this)) {
$config[$stage][$className::pluginName()] = [ $config[$stage][$className::pluginName()] = [
'zero_config' => true 'zero_config' => true

View file

@ -72,7 +72,7 @@ class Codeception extends Plugin implements ZeroConfigPluginInterface
*/ */
public static function canExecute($stage, Builder $builder, Build $build) 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));
} }
/** /**

View file

@ -82,7 +82,7 @@ class Composer extends Plugin implements ZeroConfigPluginInterface
{ {
$path = $builder->buildPath . DIRECTORY_SEPARATOR . 'composer.json'; $path = $builder->buildPath . DIRECTORY_SEPARATOR . 'composer.json';
if (file_exists($path) && $stage == 'setup') { if (file_exists($path) && $stage == Build::STAGE_SETUP) {
return true; return true;
} }

View file

@ -131,7 +131,7 @@ class PhpCodeSniffer extends Plugin implements ZeroConfigPluginInterface
*/ */
public static function canExecute($stage, Builder $builder, Build $build) public static function canExecute($stage, Builder $builder, Build $build)
{ {
if ($stage == 'test') { if ($stage == Build::STAGE_TEST) {
return true; return true;
} }

View file

@ -67,7 +67,7 @@ class PhpCpd extends Plugin implements ZeroConfigPluginInterface
*/ */
public static function canExecute($stage, Builder $builder, Build $build) public static function canExecute($stage, Builder $builder, Build $build)
{ {
if ($stage == 'test') { if ($stage == Build::STAGE_TEST) {
return true; return true;
} }

View file

@ -79,7 +79,7 @@ class PhpDocblockChecker extends Plugin implements ZeroConfigPluginInterface
*/ */
public static function canExecute($stage, Builder $builder, Build $build) public static function canExecute($stage, Builder $builder, Build $build)
{ {
if ($stage == 'test') { if ($stage == Build::STAGE_TEST) {
return true; return true;
} }

View file

@ -37,7 +37,7 @@ class PhpLoc extends Plugin implements ZeroConfigPluginInterface
*/ */
public static function canExecute($stage, Builder $builder, Build $build) public static function canExecute($stage, Builder $builder, Build $build)
{ {
if ($stage == 'test') { if ($stage == Build::STAGE_TEST) {
return true; return true;
} }

View file

@ -87,7 +87,7 @@ class PhpMessDetector extends Plugin implements ZeroConfigPluginInterface
*/ */
public static function canExecute($stage, Builder $builder, Build $build) public static function canExecute($stage, Builder $builder, Build $build)
{ {
if ($stage == 'test') { if ($stage == Build::STAGE_TEST) {
return true; return true;
} }

View file

@ -80,7 +80,7 @@ class PhpParallelLint extends Plugin implements ZeroConfigPluginInterface
*/ */
public static function canExecute($stage, Builder $builder, Build $build) public static function canExecute($stage, Builder $builder, Build $build)
{ {
if ($stage == 'test') { if ($stage == Build::STAGE_TEST) {
return true; return true;
} }

View file

@ -60,7 +60,7 @@ class PhpUnit extends Plugin implements ZeroConfigPluginInterface
*/ */
public static function canExecute($stage, Builder $builder, Build $build) 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; return true;
} }

View file

@ -87,7 +87,7 @@ class TechnicalDebt extends Plugin implements ZeroConfigPluginInterface
*/ */
public static function canExecute($stage, Builder $builder, Build $build) public static function canExecute($stage, Builder $builder, Build $build)
{ {
if ($stage == 'test') { if ($stage == Build::STAGE_TEST) {
return true; return true;
} }

View file

@ -149,18 +149,18 @@ class Executor
// Execution failed // Execution failed
$this->setPluginStatus($stage, $plugin, Build::STATUS_FAILED); $this->setPluginStatus($stage, $plugin, Build::STATUS_FAILED);
if ($stage === 'setup') { if ($stage === Build::STAGE_SETUP) {
$this->logger->logFailure('PLUGIN: FAILED'); $this->logger->logFailure('PLUGIN: FAILED');
// If we're in the "setup" stage, execution should not continue after // If we're in the "setup" stage, execution should not continue after
// a plugin has failed: // a plugin has failed:
throw new Exception('Plugin failed: ' . $plugin); throw new Exception('Plugin failed: ' . $plugin);
} elseif ($stage === 'deploy') { } elseif ($stage === Build::STAGE_DEPLOY) {
$this->logger->logFailure('PLUGIN: FAILED'); $this->logger->logFailure('PLUGIN: FAILED');
$success = false; $success = false;
} else { } else {
// If we're in the "test" stage and the plugin is not allowed to fail, // If we're in the "test" stage and the plugin is not allowed to fail,
// then mark the build as failed: // 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'); $this->logger->logFailure('PLUGIN: FAILED');
$success = false; $success = false;
} else { } else {