Skip to content

Commit 15b4fbd

Browse files
authored
Travis config and CS fixes (#1)
* Adding blackfire and xdebug * updates * Create nice folded reports * Use before install * cleanup * Syntax fixes * Use minimal travis image * CS fixes * cs
1 parent 6afeae0 commit 15b4fbd

File tree

12 files changed

+83
-121
lines changed

12 files changed

+83
-121
lines changed

.gitattributes

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
export/ export-ignore
12
layers/ export-ignore
3+
src/ export-ignore
24
.gitattributes export-ignore
35
.gitignore export-ignore
6+
.phpcs.xml.dist export-ignore
7+
.prettyci.composer.json export-ignore
48
.travis.yml export-ignore
9+
bref-extra export-ignore
10+
bchecksums.json export-ignore
511
Makefile export-ignore
612

.phpcs.xml.dist

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,8 @@
77
<!-- Show sniff names -->
88
<arg value="s"/>
99

10-
<file>bref</file>
10+
<file>bref-extra</file>
1111
<file>src</file>
12-
<file>tests</file>
13-
<exclude-pattern>tests/Bridge/Symfony/var</exclude-pattern>
14-
<exclude-pattern>tests/Bridge/Symfony/cache</exclude-pattern>
15-
<exclude-pattern>tests/Bridge/Symfony/logs</exclude-pattern>
16-
<exclude-pattern>tests/Bridge/Laravel/bootstrap/cache</exclude-pattern>
1712

1813
<!-- Import the Doctrine coding standard -->
1914
<rule ref="Doctrine"/>

.travis.yml

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
language: php
1+
language: minimal
22

33
notifications:
44
email:
@@ -8,16 +8,31 @@ services:
88
- docker
99

1010
env:
11-
- LAYER=amqp PHP=72
12-
- LAYER=amqp PHP=73
13-
- LAYER=amqp PHP=74
14-
- LAYER=blackfire PHP=72
15-
- LAYER=blackfire PHP=73
16-
- LAYER=blackfire PHP=74
17-
- LAYER=xdebug PHP=72
18-
- LAYER=xdebug PHP=73
19-
- LAYER=xdebug PHP=74
11+
- LAYER=amqp PHP="72 73 74"
12+
- LAYER=blackfire PHP="72 73 74"
13+
- LAYER=xdebug PHP="72 73 74"
14+
15+
before_install:
16+
- |
17+
# tfold is a helper to create folded reports (From Symfony)
18+
tfold () {
19+
local title="$1"
20+
local fold=$(echo $title | sed -r 's/[^-_A-Za-z0-9]+/./g')
21+
shift
22+
echo -e "travis_fold:start:$fold"
23+
echo -e "\\e[1;34m$title\\e[0m"
24+
bash -xc "$*" 2>&1
25+
local ok=$?
26+
(exit $ok) &&
27+
echo -e "\\e[32mOK\\e[0m $title\\n\\ntravis_fold:end:$fold" ||
28+
echo -e "\\e[41mKO\\e[0m $title\\n"
29+
(exit $ok)
30+
}
31+
export -f tfold
2032
2133
script:
2234
- cd layers/$LAYER
23-
- docker build --build-arg PHP_VERSION=$PHP .
35+
- |
36+
for php_version in $PHP; do
37+
tfold "Build $php_version" docker build --build-arg PHP_VERSION=${php_version} .
38+
done

Readme.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ provider:
1717

1818
plugins:
1919
- ./vendor/bref/bref
20-
- ./vendor/bref/extra-layers # <--- Add the extra Serverless plugin
20+
- ./vendor/bref/extra-layers # <----- Add the extra Serverless plugin
2121

2222
functions:
2323
console:
@@ -28,7 +28,7 @@ functions:
2828
- ${bref:layer.console}
2929
```
3030
31-
```
31+
```ini
3232
;php/conf.d/php.ini
3333
extension=/opt/bref-extra/amqp.so
3434
```
@@ -45,7 +45,6 @@ extension=/opt/bref-extra/amqp.so
4545

4646
```
4747
make publish
48-
make list
4948
git add checksums.json layers.json
5049
git commit -m "New version of layers"
5150
git push

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
2-
"name": "bref/extra-layers",
2+
"name": "bref/extra-php-extensions",
3+
"description": "Extra PHP extensions for your lambda application.",
34
"type": "library",
45
"require-dev": {
56
"symfony/process": "^5.0",

src/Application.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
1-
<?php
2-
3-
declare(strict_types=1);
1+
<?php declare(strict_types=1);
42

53
namespace Bref\Extra;
64

75
use Bref\Extra\Aws\LayerProvider;
86
use Bref\Extra\Aws\LayerPublisher;
9-
use Bref\Extra\Service\RegionProvider;
107
use Bref\Extra\Command\ListCommand;
118
use Bref\Extra\Command\PublishCommand;
9+
use Bref\Extra\Service\RegionProvider;
10+
use DI\Container;
1211
use DI\ContainerBuilder;
1312
use Psr\Container\ContainerInterface;
1413

1514
class Application extends \Silly\Edition\PhpDi\Application
1615
{
17-
protected function createContainer()
16+
protected function createContainer(): Container
1817
{
19-
$builder = new ContainerBuilder();
18+
$builder = new ContainerBuilder;
2019
$awsId = getenv('AWS_ID');
2120
$awsProfile = getenv('AWS_PROFILE');
22-
if (empty($awsId)){
21+
if (empty($awsId)) {
2322
$awsId = 'xxxxxxxxx';
2423
}
25-
if (empty($awsProfile)){
24+
if (empty($awsProfile)) {
2625
$awsProfile = null;
2726
}
2827

2928
$projectDir = dirname(__DIR__);
30-
$localLayers = array_keys(json_decode(file_get_contents($projectDir.'/checksums.json'), true));
29+
$localLayers = array_keys(json_decode(file_get_contents($projectDir . '/checksums.json'), true));
3130

3231
$builder->addDefinitions([
3332
'project_dir' => $projectDir,
@@ -50,4 +49,4 @@ protected function createContainer()
5049

5150
return $builder->build();
5251
}
53-
}
52+
}

src/Aws/LayerProvider.php

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
1-
<?php
2-
3-
declare(strict_types=1);
1+
<?php declare(strict_types=1);
42

53
namespace Bref\Extra\Aws;
64

75
use Aws\Lambda\LambdaClient;
8-
use function GuzzleHttp\Promise\unwrap;
96

107
/**
118
* Fetches layers and details from AWS
12-
*
13-
* @author Tobias Nyholm <[email protected]>
149
*/
1510
class LayerProvider
1611
{
12+
/** @var string */
1713
private $awsId;
1814

19-
/**
20-
* @var array
21-
*/
15+
/** @var array */
2216
private $layerNames;
2317

2418
/**
25-
* @param array $layerNames the name of the layers to list.
26-
* @param string $awsId The account id
19+
* @param array $layerNames the name of the layers to list.
20+
* @param string $awsId The account id
2721
*/
2822
public function __construct(array $layerNames, string $awsId)
2923
{
@@ -50,7 +44,7 @@ public function listLayers(string $selectedRegion): array
5044

5145
// Wait on all of the requests to complete. Throws a ConnectException
5246
// if any of the requests fail
53-
$results = \GuzzleHttp\Promise\unwrap($promises);
47+
$results = unwrap($promises);
5448

5549
$layers = [];
5650
foreach ($results as $layerName => $result) {
@@ -61,6 +55,4 @@ public function listLayers(string $selectedRegion): array
6155

6256
return $layers;
6357
}
64-
65-
66-
}
58+
}

src/Aws/LayerPublisher.php

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,23 @@
1-
<?php
2-
3-
declare(strict_types=1);
1+
<?php declare(strict_types=1);
42

53
namespace Bref\Extra\Aws;
64

75
use Symfony\Component\Process\Process;
86

97
class LayerPublisher
108
{
11-
/**
12-
* @var string|null
13-
*/
9+
/** @var string|null */
1410
private $awsProfile;
1511

16-
/**
17-
*
18-
* @param string|null $awsProfile
19-
*/
2012
public function __construct(?string $awsProfile)
2113
{
2214
$this->awsProfile = $awsProfile;
2315
}
2416

2517

2618
/**
27-
* @param array<string, string> $layers Layer name and layer zip file path.
28-
* @param array $regions
19+
* @param array<string, string> $layers Layer name and layer zip file path.
20+
* @param array $regions
2921
*/
3022
public function publishLayers(array $layers, array $regions): void
3123
{
@@ -38,7 +30,6 @@ public function publishLayers(array $layers, array $regions): void
3830
}
3931
$this->finishProcesses($publishingProcesses);
4032

41-
4233
// Add public permissions on the layers
4334
/** @var Process[] $permissionProcesses */
4435
$permissionProcesses = [];
@@ -55,9 +46,7 @@ public function publishLayers(array $layers, array $regions): void
5546

5647
/**
5748
* @param string $region The AWS region to publish the layer to
58-
* @param string $layerName
59-
* @param string $file The absolute file path to the layer
60-
* @return Process
49+
* @param string $file The absolute file path to the layer
6150
*/
6251
private function publishSingleLayer(string $region, string $layerName, string $file): Process
6352
{
@@ -74,7 +63,7 @@ private function publishSingleLayer(string $region, string $layerName, string $f
7463
'--license-info',
7564
'MIT',
7665
'--zip-file',
77-
'fileb://'.$file,
66+
'fileb://' . $file,
7867
'--compatible-runtimes',
7968
'provided',
8069
// Output the version so that we can fetch it and use it
@@ -122,10 +111,7 @@ private function finishProcesses(array $processes): void
122111
}
123112

124113
/**
125-
* @param string $region
126114
* @param string $layer name
127-
* @param string $layerVersion
128-
* @return Process
129115
*/
130116
private function addPublicLayerPermissions(string $region, string $layer, string $layerVersion): Process
131117
{
@@ -157,7 +143,4 @@ private function addPublicLayerPermissions(string $region, string $layer, string
157143

158144
return $process;
159145
}
160-
161-
162-
163-
}
146+
}

src/Command/HelpCommand.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
1-
<?php
2-
3-
declare(strict_types=1);
1+
<?php declare(strict_types=1);
42

53
namespace Bref\Extra\Command;
64

7-
use Bref\Extra\Aws\LayerPublisher;
8-
use Bref\Extra\Service\RegionProvider;
95
use Symfony\Component\Console\Output\OutputInterface;
10-
use Symfony\Component\Finder\Finder;
116

127
class HelpCommand
138
{
14-
public function __invoke(OutputInterface $output)
9+
public function __invoke(OutputInterface $output): int
1510
{
1611
$output->writeln('With this small application you may publish new layers and list existing ones in layer.json');
1712
$output->writeln('You may specify the following environment variables: AWS_ID, AWS_PROFILE');
1813

1914
return 0;
2015
}
21-
}
16+
}

src/Command/ListCommand.php

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
<?php
2-
3-
declare(strict_types=1);
1+
<?php declare(strict_types=1);
42

53
namespace Bref\Extra\Command;
64

@@ -15,19 +13,13 @@
1513
*/
1614
class ListCommand
1715
{
18-
/**
19-
* @var LayerProvider
20-
*/
16+
/** @var LayerProvider */
2117
private $provider;
2218

23-
24-
/**
25-
* @var string
26-
*/
19+
/** @var string */
2720
private $projectDir;
28-
/**
29-
* @var RegionProvider
30-
*/
21+
22+
/** @var RegionProvider */
3123
private $regionProvider;
3224

3325
public function __construct(LayerProvider $provider, RegionProvider $regionProvider, string $projectDir)
@@ -37,7 +29,7 @@ public function __construct(LayerProvider $provider, RegionProvider $regionProvi
3729
$this->regionProvider = $regionProvider;
3830
}
3931

40-
public function __invoke(OutputInterface $output)
32+
public function __invoke(OutputInterface $output): int
4133
{
4234
$export = [];
4335
foreach ($this->regionProvider->getAll() as $region) {
@@ -52,4 +44,4 @@ public function __invoke(OutputInterface $output)
5244

5345
return 0;
5446
}
55-
}
47+
}

0 commit comments

Comments
 (0)