WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 49ec2b9

Browse files
authored
Transport support for Skpr (#66)
* Skpr plugin Signed-off-by: Karl Hepworth <[email protected]> * Quick fixes Signed-off-by: Karl Hepworth <[email protected]> Signed-off-by: Karl Hepworth <[email protected]>
1 parent 399bd23 commit 49ec2b9

File tree

4 files changed

+147
-0
lines changed

4 files changed

+147
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Consolidation\SiteProcess\Factory;
4+
5+
use Consolidation\SiteAlias\SiteAliasInterface;
6+
use Consolidation\SiteProcess\Transport\SkprTransport;
7+
8+
/**
9+
* SkprTransportFactory will create an SkprTransport for applicable site aliases.
10+
*/
11+
class SkprTransportFactory implements TransportFactoryInterface
12+
{
13+
/**
14+
* @inheritdoc
15+
*/
16+
public function check(SiteAliasInterface $siteAlias)
17+
{
18+
return $siteAlias->has('skpr');
19+
}
20+
21+
/**
22+
* @inheritdoc
23+
*/
24+
public function create(SiteAliasInterface $siteAlias)
25+
{
26+
return new SkprTransport($siteAlias);
27+
}
28+
}

src/ProcessManager.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Consolidation\SiteProcess;
44

55
use Consolidation\SiteProcess\Factory\KubectlTransportFactory;
6+
use Consolidation\SiteProcess\Factory\SkprTransportFactory;
67
use Consolidation\SiteProcess\Factory\VagrantTransportFactory;
78
use Psr\Log\LoggerInterface;
89
use Consolidation\SiteAlias\SiteAliasInterface;
@@ -70,6 +71,7 @@ public static function addTransports(ProcessManager $processManager)
7071
{
7172
$processManager->add(new SshTransportFactory());
7273
$processManager->add(new KubectlTransportFactory());
74+
$processManager->add(new SkprTransportFactory());
7375
$processManager->add(new DockerComposeTransportFactory());
7476
$processManager->add(new VagrantTransportFactory());
7577

src/Transport/SkprTransport.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
namespace Consolidation\SiteProcess\Transport;
4+
5+
use Consolidation\SiteProcess\SiteProcess;
6+
use Consolidation\SiteAlias\SiteAliasInterface;
7+
use Consolidation\SiteProcess\Util\Shell;
8+
9+
/**
10+
* SkprTransport knows how to wrap a command to run on a site hosted
11+
* on the Skpr platform.
12+
*/
13+
class SkprTransport implements TransportInterface
14+
{
15+
16+
/** @var \Consolidation\SiteAlias\SiteAliasInterface */
17+
protected $siteAlias;
18+
19+
public function __construct(SiteAliasInterface $siteAlias)
20+
{
21+
$this->siteAlias = $siteAlias;
22+
}
23+
24+
/**
25+
* @inheritdoc
26+
*/
27+
public function configure(SiteProcess $process)
28+
{
29+
$path = $this->siteAlias->getDefault('skpr.path', getcwd());
30+
if ($path) {
31+
$process->chdirToSiteRoot($path);
32+
}
33+
}
34+
35+
/**
36+
* inheritdoc
37+
*/
38+
public function wrap($args)
39+
{
40+
$environment = $this->siteAlias->get('skpr.env');
41+
42+
$transport = [
43+
'skpr',
44+
'exec',
45+
"$environment",
46+
];
47+
$transport[] = "--";
48+
49+
return array_merge($transport, $args);
50+
}
51+
52+
/**
53+
* @inheritdoc
54+
*/
55+
public function addChdir($cd_remote, $args)
56+
{
57+
return array_merge(
58+
[
59+
'cd',
60+
$cd_remote,
61+
Shell::op('&&'),
62+
],
63+
$args
64+
);
65+
}
66+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace Consolidation\SiteProcess;
4+
5+
use Consolidation\SiteProcess\Transport\SkprTransport;
6+
use PHPUnit\Framework\TestCase;
7+
use Consolidation\SiteAlias\SiteAlias;
8+
9+
class SkprTransportTest extends TestCase
10+
{
11+
/**
12+
* Data provider for testWrap.
13+
*/
14+
public function wrapTestValues()
15+
{
16+
return [
17+
// Everything explicit.
18+
[
19+
'skpr exec dev -- ls',
20+
['ls'],
21+
[
22+
'skpr' => [
23+
'env' => 'dev',
24+
]
25+
],
26+
],
27+
28+
// Ensure we aren't escaping arguments after "--"
29+
[
30+
'skpr exec dev -- monday "tuesday" \'wednesday\'',
31+
['monday', '"tuesday"', "'wednesday'"],
32+
[
33+
'skpr' => [
34+
'env' => 'dev'
35+
]
36+
],
37+
],
38+
];
39+
}
40+
41+
/**
42+
* @dataProvider wrapTestValues
43+
*/
44+
public function testWrap($expected, $args, $siteAliasData)
45+
{
46+
$siteAlias = new SiteAlias($siteAliasData, '@alias.dev');
47+
$dockerTransport = new SkprTransport($siteAlias);
48+
$actual = $dockerTransport->wrap($args);
49+
$this->assertEquals($expected, implode(' ', $actual));
50+
}
51+
}

0 commit comments

Comments
 (0)