Skip to content

Commit f9275cd

Browse files
committed
Added implementation of periodical builds in Worker and cronjob with
rich configuration (app/periodical.yml config).
1 parent 31ed99d commit f9275cd

18 files changed

Lines changed: 379 additions & 156 deletions

.gitignore

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
/vendor
21
/composer.phar
32

3+
/vendor
4+
/public/assets/vendor
5+
6+
/app/config.yml
7+
/app/periodical.yml
8+
49
/runtime/*.log
510

611
/runtime/builds
@@ -12,8 +17,5 @@
1217
/runtime/status_cache
1318
!/runtime/status_cache/.gitkeep
1419

15-
/app/config.yml
16-
/public/assets/vendor
17-
1820
/public/artifacts
1921
!/public/artifacts/.gitkeep

docs/en/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ Using PHP Censor
2727
* [Injecting variables into messages](interpolation.md)
2828
* [Project Status Images and Status Page](status.md)
2929
* [Build environments](environments.md)
30+
* [Periodical builds](periodical_builds.md)
31+
* [Console commands](commands.md)
32+
* [CCMenu/CCTray integration](ccmenu.md)
3033

3134
Plugins
3235
-------

docs/en/ccmenu.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CCMenu/CCTray integration
2+
=========================
3+
4+
Use URL: `http://php-censor.local/build-status/ccxml/<project_id>`.

docs/en/commands.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Console commands
2+
================
3+
4+
* `php-censor:check-localizations` - Check localizations.
5+
* `php-censor:create-admin` - Create an admin user
6+
* `php-censor:create-build` - Create a build for a project
7+
* `php-censor:install` - Install PHP Censor
8+
* `php-censor:rebuild` - Re-runs the last run build.
9+
* `php-censor:rebuild-queue` - Rebuilds the PHP Censor worker queue.
10+
* `php-censor:run-builds` - Run all pending PHP Censor builds
11+
* `php-censor:worker` - Runs the PHP Censor build worker.

docs/en/periodical_builds.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Periodical builds
2+
=================
3+
4+
You can create periodical builds for your projects. For starting use periodical builds you should create config
5+
`app/periodical.yml` and run **one of the workers** with option `--periodical-work|-p`:
6+
`./bin/console php-censor:worker -v --periodical-work` (With cronjob worker feature starts work automatically).
7+
8+
Periodical builds config example:
9+
10+
```yaml
11+
projects:
12+
1: # Project id
13+
branches: # Branch list for periodical build
14+
- master
15+
- release-1.0
16+
- release-2.0
17+
interval: P1W # Interval to build project if no other builds (from webhook etc.).Used format of PHP DateInterval class. See: http://php.net/manual/ru/dateinterval.construct.php
18+
12: # Another project id
19+
branches:
20+
- master
21+
interval: PT12H
22+
```

src/Command/RebuildCommand.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Symfony\Component\Console\Input\ArgvInput;
1010
use Symfony\Component\Console\Input\InputInterface;
1111
use Symfony\Component\Console\Output\OutputInterface;
12+
use PHPCensor\Store\BuildStore;
13+
use PHPCensor\Store\ProjectStore;
1214

1315
/**
1416
* Re-runs the last run build.
@@ -62,11 +64,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
6264
$runner = new RunCommand($this->logger);
6365
$runner->setMaxBuilds(1);
6466

65-
/** @var \PHPCensor\Store\BuildStore $store */
66-
$store = Factory::getStore('Build');
67-
$service = new BuildService($store);
67+
/** @var BuildStore $buildStore */
68+
$buildStore = Factory::getStore('Build');
6869

69-
$builds = $store->getLatestBuilds(null, 1);
70+
/** @var ProjectStore $projectStore */
71+
$projectStore = Factory::getStore('Project');
72+
73+
$service = new BuildService($buildStore, $projectStore);
74+
75+
$builds = $buildStore->getLatestBuilds(null, 1);
7076
$lastBuild = array_shift($builds);
7177
$service->createDuplicateBuild($lastBuild);
7278

src/Command/RebuildQueueCommand.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
namespace PHPCensor\Command;
44

5+
use PHPCensor\Store\BuildStore;
56
use PHPCensor\Store\Factory;
67
use Monolog\Logger;
78
use PHPCensor\BuildFactory;
89
use PHPCensor\Logging\OutputLogHandler;
910
use PHPCensor\Service\BuildService;
11+
use PHPCensor\Store\ProjectStore;
1012
use Symfony\Component\Console\Command\Command;
1113
use Symfony\Component\Console\Input\InputInterface;
1214
use Symfony\Component\Console\Output\OutputInterface;
@@ -55,12 +57,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
5557
);
5658
}
5759

58-
$store = Factory::getStore('Build');
59-
$result = $store->getByStatus(0);
60+
/** @var BuildStore $buildStore */
61+
$buildStore = Factory::getStore('Build');
62+
63+
/** @var ProjectStore $projectStore */
64+
$projectStore = Factory::getStore('Project');
65+
66+
$result = $buildStore->getByStatus(0);
6067

6168
$this->logger->addInfo(sprintf('Found %d builds', count($result['items'])));
6269

63-
$buildService = new BuildService($store);
70+
$buildService = new BuildService($buildStore, $projectStore);
6471

6572
while (count($result['items'])) {
6673
$build = array_shift($result['items']);

src/Command/RunCommand.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
use Monolog\Logger;
66
use PHPCensor\Logging\BuildDBLogHandler;
7+
use PHPCensor\Service\BuildService;
78
use PHPCensor\Store\BuildStore;
9+
use PHPCensor\Store\ProjectStore;
810
use Symfony\Component\Console\Input\InputInterface;
911
use Symfony\Component\Console\Output\OutputInterface;
1012
use PHPCensor\Store\Factory;
@@ -19,11 +21,32 @@
1921
*/
2022
class RunCommand extends LoggingCommand
2123
{
24+
/**
25+
* @var BuildService
26+
*/
27+
protected $buildService;
28+
2229
/**
2330
* @var int
2431
*/
2532
protected $maxBuilds = 10;
2633

34+
/**
35+
* @param Logger $logger
36+
* @param BuildService $buildService
37+
* @param string $name
38+
*/
39+
public function __construct(
40+
Logger $logger,
41+
BuildService $buildService,
42+
$name = null
43+
)
44+
{
45+
parent::__construct($logger, $name);
46+
47+
$this->buildService = $buildService;
48+
}
49+
2750
protected function configure()
2851
{
2952
$this
@@ -37,7 +60,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
3760

3861
/** @var BuildStore $buildStore */
3962
$buildStore = Factory::getStore('Build');
40-
$result = $buildStore->getByStatus(Build::STATUS_PENDING, $this->maxBuilds);
63+
64+
$this->buildService->createPeriodicalBuilds($this->logger);
65+
66+
$result = $buildStore->getByStatus(Build::STATUS_PENDING, $this->maxBuilds);
4167

4268
$this->logger->notice(
4369
sprintf('Found %d pending builds', count($result['items']))

src/Command/ScheduleBuildCommand.php

Lines changed: 0 additions & 103 deletions
This file was deleted.

src/Command/WorkerCommand.php

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22

33
namespace PHPCensor\Command;
44

5+
use Monolog\Logger;
56
use PHPCensor\Config;
7+
use PHPCensor\Service\BuildService;
8+
use PHPCensor\Store\BuildStore;
9+
use PHPCensor\Store\Factory;
10+
use PHPCensor\Store\ProjectStore;
611
use PHPCensor\Worker\BuildWorker;
712
use Symfony\Component\Console\Input\InputInterface;
13+
use Symfony\Component\Console\Input\InputOption;
814
use Symfony\Component\Console\Output\OutputInterface;
915

1016
/**
@@ -14,10 +20,37 @@
1420
*/
1521
class WorkerCommand extends LoggingCommand
1622
{
23+
/**
24+
* @var BuildService
25+
*/
26+
protected $buildService;
27+
28+
/**
29+
* @param Logger $logger
30+
* @param BuildService $buildService
31+
* @param string $name
32+
*/
33+
public function __construct(
34+
Logger $logger,
35+
BuildService $buildService,
36+
$name = null
37+
)
38+
{
39+
parent::__construct($logger, $name);
40+
41+
$this->buildService = $buildService;
42+
}
43+
1744
protected function configure()
1845
{
1946
$this
2047
->setName('php-censor:worker')
48+
->addOption(
49+
'periodical-work',
50+
'p',
51+
InputOption::VALUE_NONE,
52+
'Allow worker run periodical work'
53+
)
2154
->setDescription('Runs the PHP Censor build worker.');
2255
}
2356

@@ -38,7 +71,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
3871
);
3972
}
4073

41-
(new BuildWorker($this->logger, $config['host'], $config['name']))
74+
(new BuildWorker(
75+
$this->logger,
76+
$this->buildService,
77+
$config['host'],
78+
$config['name'],
79+
($input->hasOption('periodical-work') && $input->getOption('periodical-work'))
80+
))
4281
->startWorker();
4382
}
4483
}

0 commit comments

Comments
 (0)