Skip to content

Commit be9c6f7

Browse files
committed
Change PHP version when needed
1 parent 0c58371 commit be9c6f7

File tree

17 files changed

+76
-71
lines changed

17 files changed

+76
-71
lines changed

common.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ function validateBranchName {
153153
echoValidationGroupEnd
154154
}
155155

156+
function definePhpCliVersion {
157+
local phpVersion=$1
158+
159+
sudo /usr/bin/update-alternatives --set php /usr/bin/php$phpVersion
160+
}
161+
156162
VERBOSE_LEVEL=0
157163
for param in "$@"; do
158164
if [ "$param" == "-v" ]; then

composerUpdate.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ if [ $VERBOSE_LEVEL -ge 2 ]; then
2121
[ $? != "0" ] && exitScript "Error while building Docker container."
2222
else
2323
docker-compose up --build --no-start &>/tmp/phpbenchmarks.docker
24-
[ $? != "0" ] && cat /tmp/phpbenchmarks.docker && exitScript "Error while building Docker container."
25-
rm /tmp/phpbenchmarks.docker
24+
[ $? != "0" ] \
25+
&& cat /tmp/phpbenchmarks.docker \
26+
&& rm /tmp/phpbenchmarks.docker \
27+
&& exitScript "Error while building Docker container."
2628
fi
2729
echoValidationGroupEnd
2830

@@ -32,8 +34,10 @@ if [ $VERBOSE_LEVEL -ge 1 ]; then
3234
[ $? != "0" ] && exitScript "Composer update failed."
3335
else
3436
docker-compose up --abort-on-container-exit --exit-code-from phpbenchmarks_composer_update &>/tmp/phpbenchmarks.docker
35-
[ $? != "0" ] && cat /tmp/phpbenchmarks.docker && exitScript "Composer update failed."
36-
rm /tmp/phpbenchmarks.docker
37+
[ $? != "0" ] \
38+
&& cat /tmp/phpbenchmarks.docker \
39+
&& rm /tmp/phpbenchmarks.docker \
40+
&& exitScript "Composer update failed."
3741
fi
3842
echoValidationGroupEnd
3943

docker/benchmarkKit/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ RUN echo "phpbenchmarks ALL=(ALL) NOPASSWD: /usr/sbin/service php7.1-fpm start"
3838
RUN echo "phpbenchmarks ALL=(ALL) NOPASSWD: /usr/sbin/service php7.2-fpm start" >> /etc/sudoers.d/phpbenchmarks
3939
RUN echo "phpbenchmarks ALL=(ALL) NOPASSWD: /usr/sbin/service php7.3-fpm start" >> /etc/sudoers.d/phpbenchmarks
4040

41+
RUN echo "phpbenchmarks ALL=(ALL) NOPASSWD: /usr/bin/update-alternatives --set php /usr/bin/php5.6" >> /etc/sudoers.d/phpbenchmarks
42+
RUN echo "phpbenchmarks ALL=(ALL) NOPASSWD: /usr/bin/update-alternatives --set php /usr/bin/php7.0" >> /etc/sudoers.d/phpbenchmarks
43+
RUN echo "phpbenchmarks ALL=(ALL) NOPASSWD: /usr/bin/update-alternatives --set php /usr/bin/php7.1" >> /etc/sudoers.d/phpbenchmarks
44+
RUN echo "phpbenchmarks ALL=(ALL) NOPASSWD: /usr/bin/update-alternatives --set php /usr/bin/php7.2" >> /etc/sudoers.d/phpbenchmarks
45+
RUN echo "phpbenchmarks ALL=(ALL) NOPASSWD: /usr/bin/update-alternatives --set php /usr/bin/php7.3" >> /etc/sudoers.d/phpbenchmarks
46+
4147
# we have some commands to do in this dir with phpbenchmarks user
4248
# so instead of adding a lot of commands into sudoers, and as security doesn't matter in this container,
4349
# change this dir credentials to 777

docker/benchmarkKit/cli/Command/AbstractCommand.php

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
<?php
22

3-
declare(strict_types=1);
4-
53
namespace App\Command;
64

7-
use App\{
8-
ComponentConfiguration,
9-
Exception\ValidationException
10-
};
11-
use Symfony\Component\Console\{
12-
Command\Command,
13-
Input\InputArgument,
14-
Input\InputInterface,
15-
Output\OutputInterface
16-
};
5+
use App\ComponentConfiguration;
6+
use App\Exception\ValidationException;
7+
use Symfony\Component\Console\Command\Command;
8+
use Symfony\Component\Console\Input\InputArgument;
9+
use Symfony\Component\Console\Input\InputInterface;
10+
use Symfony\Component\Console\Output\OutputInterface;
1711

1812
abstract class AbstractCommand extends Command
1913
{
@@ -27,17 +21,17 @@ abstract class AbstractCommand extends Command
2721
/** @var ?string */
2822
private $resultTypeSlug;
2923

30-
public function isValidateDev(): bool
24+
public function isValidateDev()
3125
{
3226
return $this->validateDev;
3327
}
3428

35-
public function isRepositoriesCreated(): bool
29+
public function isRepositoriesCreated()
3630
{
3731
return $this->repositoriesCreated;
3832
}
3933

40-
public function getResultTypeSlug(): ?string
34+
public function getResultTypeSlug()
4135
{
4236
return $this->resultTypeSlug;
4337
}
@@ -59,26 +53,26 @@ protected function execute(InputInterface $input, OutputInterface $output)
5953
return 0;
6054
}
6155

62-
protected function validationSuccess(OutputInterface $output, string $message): self
56+
protected function validationSuccess(OutputInterface $output, $message)
6357
{
6458
$output->writeln(" \e[42m > \e[00m \e[32mValidated\e[00m " . $this->validationPrefix . $message);
6559

6660
return $this;
6761
}
6862

69-
protected function validationFailed(OutputInterface $output, string $error): void
63+
protected function validationFailed(OutputInterface $output, $error)
7064
{
7165
throw new ValidationException($output, $this->validationPrefix . $error);
7266
}
7367

74-
protected function warning(OutputInterface $output, string $message): self
68+
protected function warning(OutputInterface $output, $message)
7569
{
7670
$output->writeln(" \e[43m > \e[00m \e[43m " . $this->validationPrefix . $message . " \e[00m");
7771

7872
return $this;
7973
}
8074

81-
protected function repositoriesNotCreatedWarning(OutputInterface $output): self
75+
protected function repositoriesNotCreatedWarning(OutputInterface $output)
8276
{
8377
$this->warning(
8478
$output,
@@ -90,17 +84,17 @@ protected function repositoriesNotCreatedWarning(OutputInterface $output): self
9084
return $this;
9185
}
9286

93-
protected function getInstallationPath(): string
87+
protected function getInstallationPath()
9488
{
9589
return '/var/www/phpbenchmarks';
9690
}
9791

98-
protected function getCommonRepositoryName(): string
92+
protected function getCommonRepositoryName()
9993
{
10094
return 'phpbenchmarks/' . ComponentConfiguration::COMMON_REPOSITORY;
10195
}
10296

103-
protected function getCommonDevBranchName(): string
97+
protected function getCommonDevBranchName()
10498
{
10599
return
106100
'dev-'
@@ -112,7 +106,7 @@ protected function getCommonDevBranchName(): string
112106
. '_prepare';
113107
}
114108

115-
protected function getCommonProdBranchPrefix(OutputInterface $output): string
109+
protected function getCommonProdBranchPrefix(OutputInterface $output)
116110
{
117111
switch ($this->getResultTypeSlug()) {
118112
case 'hello-world': $commonMinorVersion = 1; break;

docker/benchmarkKit/cli/Command/ValidateComposerJsonCommand.php

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
<?php
22

3-
declare(strict_types=1);
4-
53
namespace App\Command;
64

7-
use App\{
8-
ComponentConfiguration,
9-
Exception\ValidationException
10-
};
11-
use Symfony\Component\Console\{
12-
Command\Command,
13-
Input\InputArgumpent,
14-
Input\InputInterface,
15-
Output\OutputInterface
16-
};
5+
use App\ComponentConfiguration;
6+
use App\Exception\ValidationException;
7+
use Symfony\Component\Console\Input\InputArgumpent;
8+
use Symfony\Component\Console\Input\InputInterface;
9+
use Symfony\Component\Console\Output\OutputInterface;
1710

1811
class ValidateComposerJsonCommand extends AbstractCommand
1912
{
@@ -54,7 +47,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
5447
return 0;
5548
}
5649

57-
private function validateName(OutputInterface $output, array $data): self
50+
private function validateName(OutputInterface $output, array $data)
5851
{
5952
($data['name'] ?? null) === 'phpbenchmarks/' . ComponentConfiguration::SLUG
6053
? $this->validationSuccess($output, 'Name ' . $data['name'] . ' is valid.')
@@ -67,7 +60,7 @@ private function validateName(OutputInterface $output, array $data): self
6760
return $this;
6861
}
6962

70-
private function validateLicense(OutputInterface $output, array $data): self
63+
private function validateLicense(OutputInterface $output, array $data)
7164
{
7265
($data['license'] ?? null) === 'proprietary'
7366
? $this->validationSuccess($output, 'License ' . $data['license'] .' is valid.')
@@ -76,7 +69,7 @@ private function validateLicense(OutputInterface $output, array $data): self
7669
return $this;
7770
}
7871

79-
private function validateRequireComponent(OutputInterface $output, array $data): self
72+
private function validateRequireComponent(OutputInterface $output, array $data)
8073
{
8174
if (is_null($data['require'][ComponentConfiguration::DEPENDENCY_NAME] ?? null)) {
8275
$this->validationFailed(
@@ -111,7 +104,7 @@ private function validateRequireComponent(OutputInterface $output, array $data):
111104
return $this;
112105
}
113106

114-
private function validateRequireCommon(InputInterface $input, OutputInterface $output, array $data): self
107+
private function validateRequireCommon(InputInterface $input, OutputInterface $output, array $data)
115108
{
116109
if ($this->isRepositoriesCreated()) {
117110
$commonRepository = $this->getCommonRepositoryName();

docker/benchmarkKit/cli/Command/ValidateComposerLockCommand.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
<?php
22

3-
declare(strict_types=1);
4-
53
namespace App\Command;
64

7-
use App\{
8-
ComponentConfiguration,
9-
Exception\ValidationException
10-
};
11-
use Symfony\Component\Console\{
12-
Command\Command,
13-
Input\InputInterface,
14-
Output\OutputInterface
15-
};
5+
use App\ComponentConfiguration;
6+
use App\Exception\ValidationException;
7+
use Symfony\Component\Console\Input\InputInterface;
8+
use Symfony\Component\Console\Output\OutputInterface;
169

1710
class ValidateComposerLockCommand extends AbstractCommand
1811
{
@@ -40,7 +33,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
4033
return 0;
4134
}
4235

43-
private function validateDisabledPhpVersions(OutputInterface $output): self
36+
private function validateDisabledPhpVersions(OutputInterface $output)
4437
{
4538
foreach (ComponentConfiguration::getDisabledPhpVersions() as $phpVersion) {
4639
$lockFile = 'composer.lock.php' . $phpVersion;
@@ -59,7 +52,7 @@ private function validateDisabledPhpVersions(OutputInterface $output): self
5952
return $this;
6053
}
6154

62-
private function validateEnabledPhpVersions(OutputInterface $output): self
55+
private function validateEnabledPhpVersions(OutputInterface $output)
6356
{
6457
foreach (ComponentConfiguration::getEnabledPhpVersions() as $phpVersion) {
6558
$lockFile = 'composer.lock.php' . $phpVersion;
@@ -83,7 +76,7 @@ private function validateEnabledPhpVersions(OutputInterface $output): self
8376
return $this;
8477
}
8578

86-
private function validateComponentVersion(OutputInterface $output, array $data): self
79+
private function validateComponentVersion(OutputInterface $output, array $data)
8780
{
8881
$packageFound = false;
8982
foreach ($data['packages'] as $package) {
@@ -125,7 +118,7 @@ private function validateComponentVersion(OutputInterface $output, array $data):
125118
return $this;
126119
}
127120

128-
private function validateCommonVersion(OutputInterface $output, array $data): self
121+
private function validateCommonVersion(OutputInterface $output, array $data)
129122
{
130123
if ($this->isRepositoriesCreated()) {
131124
$packageFound = false;

docker/benchmarkKit/cli/ComponentConfiguration.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
declare(strict_types=1);
4-
53
namespace App;
64

75
class ComponentConfiguration
@@ -22,7 +20,7 @@ class ComponentConfiguration
2220
public const DEPENDENCY_MINOR_VERSION = ____PHPBENCHMARKS_DEPENDENCY_MINOR_VERSION____;
2321
public const DEPENDENCY_BUGFIX_VERSION = ____PHPBENCHMARKS_DEPENDENCY_BUGFIX_VERSION____;
2422

25-
public static function getDependencyVersion(): string
23+
public static function getDependencyVersion()
2624
{
2725
return
2826
static::DEPENDENCY_MAJOR_VERSION

docker/benchmarkKit/cli/Exception/ValidationException.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
<?php
22

3-
declare(strict_types=1);
4-
53
namespace App\Exception;
64

75
use Symfony\Component\Console\Output\OutputInterface;
86

97
class ValidationException extends \Exception
108
{
11-
public function __construct(OutputInterface $output, string $message)
9+
public function __construct(OutputInterface $output, $message)
1210
{
1311
parent::__construct($message);
1412

docker/benchmarkKit/cli/composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
"name": "phpbenchmarks/benchmark-kit-cli",
33
"license": "proprietary",
44
"require": {
5-
"symfony/console": "4.2.*"
5+
"php": "^5.6|^7.0",
6+
"ext-json": "*",
7+
"symfony/console": "^3.0"
68
},
79
"autoload": {
810
"psr-4": {

docker/benchmarkKit/cli/console

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33

44
require __DIR__ . '/vendor/autoload.php';
55

6-
use App\{
7-
Command\ValidateComposerLockCommand,
8-
Command\ValidateComposerJsonCommand
9-
};
6+
use App\Command\ValidateComposerLockCommand;
7+
use App\Command\ValidateComposerJsonCommand;
108
use Symfony\Component\Console\Application;
119

1210
$application = new Application();

0 commit comments

Comments
 (0)