Skip to content

Commit

Permalink
Merge pull request #191 from shlinkio/develop
Browse files Browse the repository at this point in the history
Release 8.4.1
  • Loading branch information
acelaya authored Jun 15, 2023
2 parents e8f7bbc + 8532ab6 commit 25cb9c3
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 12 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org).

## [8.4.2] - 2023-06-15
### Added
* *Nothing*

### Changed
* *Nothing*

### Deprecated
* *Nothing*

### Removed
* *Nothing*

### Fixed
* Make sure installation commands are run with the right timeout


## [8.4.1] - 2023-06-08
### Added
* *Nothing*
Expand Down
2 changes: 2 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,15 @@
'errorMessage' => 'Error generating database.',
'failOnError' => true,
'printOutput' => false,
'timeout' => 600, // 10 minutes
],
InstallationCommand::DB_MIGRATE->value => [
'command' => 'vendor/doctrine/migrations/bin/doctrine-migrations.php migrations:migrate',
'initMessage' => 'Updating database...',
'errorMessage' => 'Error updating database.',
'failOnError' => true,
'printOutput' => false,
'timeout' => 600, // 10 minutes
],
InstallationCommand::ORM_PROXIES->value => [
'command' => 'vendor/doctrine/orm/bin/doctrine.php orm:generate-proxies',
Expand Down
6 changes: 3 additions & 3 deletions src/Command/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class InitCommand extends Command
private readonly FlagOption $skipInitDb;
private readonly FlagOption $clearDbCache;
private readonly FlagOption $initialApiKey;
private readonly FlagOption $updateRoadRunnerBin;
private readonly FlagOption $downloadRoadRunnerBin;
private readonly FlagOption $skipDownloadGeoLiteDb;

public function __construct(private readonly InstallationCommandsRunnerInterface $commandsRunner)
Expand All @@ -33,7 +33,7 @@ public function __construct(private readonly InstallationCommandsRunnerInterface
$this->skipInitDb = InitOption::SKIP_INITIALIZE_DB->toFlagOption($this);
$this->clearDbCache = InitOption::CLEAR_DB_CACHE->toFlagOption($this);
$this->initialApiKey = InitOption::INITIAL_API_KEY->toFlagOption($this);
$this->updateRoadRunnerBin = InitOption::DOWNLOAD_RR_BINARY->toFlagOption($this);
$this->downloadRoadRunnerBin = InitOption::DOWNLOAD_RR_BINARY->toFlagOption($this);
$this->skipDownloadGeoLiteDb = InitOption::SKIP_DOWNLOAD_GEOLITE->toFlagOption($this);
}

Expand All @@ -52,7 +52,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
$config = new ShlinkInitConfig(
initializeDb: ! $this->skipInitDb->get($input),
clearDbCache: $this->clearDbCache->get($input),
updateRoadrunnerBinary: $this->updateRoadRunnerBin->get($input),
downloadRoadrunnerBinary: $this->downloadRoadRunnerBin->get($input),
generateApiKey: $this->initialApiKey->get($input),
downloadGeoLiteDb: ! $this->skipDownloadGeoLiteDb->get($input),
);
Expand Down
2 changes: 1 addition & 1 deletion src/Model/ShlinkInitConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ final class ShlinkInitConfig
public function __construct(
public readonly bool $initializeDb,
public readonly bool $clearDbCache,
public readonly bool $updateRoadrunnerBinary,
public readonly bool $downloadRoadrunnerBinary,
public readonly bool $generateApiKey,
public readonly bool $downloadGeoLiteDb,
) {
Expand Down
3 changes: 2 additions & 1 deletion src/Service/InstallationCommandsRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\Process;

use function array_filter;
use function explode;
Expand Down Expand Up @@ -56,7 +57,7 @@ public function execPhpCommand(string $name, SymfonyStyle $io): bool
OutputInterface::VERBOSITY_VERBOSE,
);

$process = $this->processHelper->run($io, $command);
$process = $this->processHelper->run($io, new Process($command, timeout: $commandConfig['timeout'] ?? 60));
$isSuccess = $process->isSuccessful();
$isWarning = ! $isSuccess && ! $failOnError;
$isVerbose = $io->isVerbose();
Expand Down
2 changes: 1 addition & 1 deletion src/Util/InstallationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static function resolveCommandsForConfig(ShlinkInitConfig $config): itera
yield self::API_KEY_GENERATE;
}

if ($config->updateRoadrunnerBinary) {
if ($config->downloadRoadrunnerBinary) {
yield self::ROAD_RUNNER_BINARY_DOWNLOAD;
}
}
Expand Down
27 changes: 21 additions & 6 deletions test/Service/InstallationCommandsRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ private function buildCommands(): array
'errorMessage' => sprintf('%s_error', $name),
'failOnError' => $name === 'foo',
'printOutput' => false,
'timeout' => $name === 'foo' ? 1000 : null,
]));
}

Expand All @@ -60,14 +61,16 @@ public function doesNothingWhenRequestedCommandDoesNotExist(): void
self::assertFalse($this->commandsRunner->execPhpCommand('invalid', $this->io));
}

#[Test]
public function returnsSuccessWhenProcessIsProperlyRunOrDoesNotFailOnError(): void
#[Test, DataProvider('provideTimeouts')]
public function returnsSuccessWhenProcessIsProperlyRun(string $name, float $expectedTimeout): void
{
$name = 'foo';
$command = ['php', $name, 'something'];

$process = $this->createProcessMock(true);
$this->processHelper->expects($this->once())->method('run')->with($this->io, $command)->willReturn($process);
$this->processHelper->expects($this->once())->method('run')->with(
$this->io,
$this->callback(fn (Process $process) => $expectedTimeout === $process->getTimeout()),
)->willReturn($process);

$writeCallMatcher = $this->exactly(2);
$this->io->expects($writeCallMatcher)->method('write')->willReturnCallback(
Expand All @@ -85,14 +88,23 @@ function (string $message) use ($writeCallMatcher, $name, $command): void {
self::assertTrue($this->commandsRunner->execPhpCommand($name, $this->io));
}

public static function provideTimeouts(): iterable
{
yield 'default timeout' => ['bar', 60];
yield 'explicit timeout' => ['foo', 1000];
}

#[Test, DataProvider('provideExtraLines')]
public function returnsWarningWhenProcessFailsButErrorIsAllowed(bool $isVerbose, string $extraLine): void
{
$name = 'bar';
$command = ['php', $name, 'something'];

$process = $this->createProcessMock(false);
$this->processHelper->expects($this->once())->method('run')->with($this->io, $command)->willReturn($process);
$this->processHelper->expects($this->once())->method('run')->with(
$this->io,
$this->isInstanceOf(Process::class),
)->willReturn($process);
$this->io->method('isVerbose')->willReturn($isVerbose);

$writeCallMatcher = $this->exactly(3);
Expand Down Expand Up @@ -125,7 +137,10 @@ public function returnsErrorWhenProcessIsNotProperlyRun(): void
$command = ['php', $name, 'something'];

$process = $this->createProcessMock(false);
$this->processHelper->expects($this->once())->method('run')->with($this->io, $command)->willReturn($process);
$this->processHelper->expects($this->once())->method('run')->with(
$this->io,
$this->isInstanceOf(Process::class),
)->willReturn($process);

$writeCallMatcher = $this->exactly(2);
$this->io->expects($writeCallMatcher)->method('write')->willReturnCallback(
Expand Down

0 comments on commit 25cb9c3

Please sign in to comment.