Skip to content

Commit c7c0552

Browse files
author
Frédéric Dewinne
authored
Merge pull request #6 from continuousphp/application-list
Add application list command
2 parents 121d8af + bf7a4cb commit c7c0552

6 files changed

Lines changed: 90 additions & 7 deletions

File tree

config/application.config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
return array(
88
'modules' => array(
99
'BsbFlysystem',
10-
'Continuous\\DeployAgent',
1110
'DoctrineModule',
11+
'Continuous\\DeployAgent',
1212
'DoctrineORMModule'
1313
),
1414
'module_listener_options' => array(

features/bootstrap/DeployAgentContext.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function __construct()
4949
/**
5050
* @BeforeSuite
5151
*/
52-
public static function setupTests(BeforeSuiteScope $scope)
52+
public static function setupTests()
5353
{
5454
copy('config/autoload/db.test.php.dist', 'config/autoload/db.test.php');
5555

@@ -69,15 +69,15 @@ public static function setupTests(BeforeSuiteScope $scope)
6969
/**
7070
* @AfterSuite
7171
*/
72-
public static function removeDB(AfterSuiteScope $scope)
72+
public static function removeDB()
7373
{
7474
unlink('config/autoload/db.test.php');
7575
}
7676

7777
/**
7878
* @BeforeScenario
7979
*/
80-
public function provisionDB(BeforeScenarioScope $scope)
80+
public function provisionDB()
8181
{
8282
if (file_exists('data/db/test.db')) {
8383
echo 'removing db...';
@@ -89,7 +89,7 @@ public function provisionDB(BeforeScenarioScope $scope)
8989
/**
9090
* @AfterScenario
9191
*/
92-
public function cleanDB(AfterScenarioScope $scope)
92+
public function cleanDB()
9393
{
9494
/** @var EntityManager $entityManager */
9595
$entityManager = self::$application->getServiceManager()->get('entitymanager');
@@ -98,10 +98,20 @@ public function cleanDB(AfterScenarioScope $scope)
9898
unlink('data/db/test.db');
9999
}
100100

101+
/**
102+
* @BeforeScenario @filesystem
103+
*/
104+
public function prepareFileSystem()
105+
{
106+
if (!file_exists('/tmp/test')) {
107+
mkdir('/tmp/test', 0777, true);
108+
}
109+
}
110+
101111
/**
102112
* @AfterScenario @filesystem
103113
*/
104-
public function cleanFileSystem(AfterScenarioScope $scope)
114+
public function cleanFileSystem()
105115
{
106116
exec('rm -Rf /tmp/test');
107117
exec('rm -Rf data/packages/*');
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
@continuousphp
2+
Feature: List all configured application
3+
4+
Scenario: List no application using the CLI
5+
Given I am in the "." folder
6+
When I run "./agent list applications"
7+
Then the exit code should be "0"
8+
And the output should contain:
9+
"""
10+
No application found
11+
"""
12+
13+
@filesystem
14+
Scenario: List an existing application using the CLI
15+
Given I am in the "." folder
16+
And I have the application
17+
| provider | continuousphp |
18+
| token | b52f9c7faf680988f88391b35e5e488883442036 |
19+
| repositoryProvider | git-hub |
20+
| repository | fdewinnetest/deploy-agent |
21+
| pipeline | refs/heads/master |
22+
| name | deploy-agent-staging |
23+
| path | /tmp/test/application |
24+
When I run "./agent list applications"
25+
Then the exit code should be "0"
26+
And the output should contain:
27+
"""
28+
deploy-agent-staging
29+
"""

module/DeployAgent/src/Application/ApplicationManager.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Continuous\DeployAgent\EntityManagerAwareInterface;
1414
use Continuous\DeployAgent\EntityRepositoryProviderInterface;
1515
use Continuous\DeployAgent\EntityRepositoryProviderTrait;
16+
use Doctrine\Common\Collections\Collection;
1617

1718
/**
1819
* ApplicationManager
@@ -61,6 +62,14 @@ public function find($provider, $repositoryProvider, $repository, $pipeline)
6162
}
6263
}
6364

65+
/**
66+
* @return Collection
67+
*/
68+
public function findAll()
69+
{
70+
return $this->getEntityRepository()->findAll();
71+
}
72+
6473
/**
6574
* @param Application $application
6675
*/

module/DeployAgent/src/Controller/ApplicationController.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
use Continuous\DeployAgent\Resource\FileSystem\Directory;
1919
use Continuous\DeployAgent\Task\TaskManager;
2020
use League\Flysystem\Filesystem;
21+
use Symfony\Component\Console\Helper\Table;
22+
use Symfony\Component\Console\Output\ConsoleOutput;
2123
use Zend\Config\Config;
2224
use Zend\Console\ColorInterface;
2325
use Zend\Console\Console;
@@ -38,8 +40,37 @@ class ApplicationController extends AbstractConsoleController
3840
public function listAction()
3941
{
4042
$model = new ConsoleModel();
43+
44+
/** @var \Continuous\DeployAgent\Application\ApplicationManager $applicationManager */
45+
$applicationManager = $this->getServiceLocator()
46+
->get('application/application-manager');
47+
48+
$applications = $applicationManager->findAll();
4149

42-
$model->setResult('No application found' . PHP_EOL);
50+
$output = new ConsoleOutput();
51+
52+
if (empty($applications)) {
53+
$model->setResult('No application found' . PHP_EOL);
54+
} else {
55+
$table = new Table($output);
56+
$table->setHeaders([]);
57+
foreach ($applications as $application) {
58+
/** @var Application $application */
59+
/** @var Continuousphp $provider */
60+
$provider = $application->getProvider();
61+
$table->setHeaders(['name', 'path', 'provider', 'source']);
62+
$table->addRow([
63+
$application->getName(),
64+
$application->getPath(),
65+
'continuousphp',
66+
$provider ?
67+
$provider->getRepositoryProvider()
68+
. '/' . $provider->getRepository()
69+
. '::' . $provider->getReference() : ''
70+
]);
71+
}
72+
$table->render();
73+
}
4374

4475
return $model;
4576
}

module/DeployAgent/src/Task/TaskManager.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ function (DeployEvent $event) {
248248
}
249249
);
250250
}
251+
252+
$mask = umask(0);
251253

252254
$this->getPackageFileSystem()->createDir($application->getName());
253255
$resourcePath = $this->getPackageStoragePath()
@@ -278,6 +280,8 @@ function () use ($application) {
278280
$agent = new Agent();
279281
$agent->setSource($origin)->setResource($resource)->setDestination($destination);
280282
$agent->deploy();
283+
284+
umask($mask);
281285
}
282286

283287
public function activate(EventInterface $event)

0 commit comments

Comments
 (0)