Skip to content

Commit

Permalink
SDK-5621 Avoid integrator lock updates. #165 from spryker-sdk/bugfix/…
Browse files Browse the repository at this point in the history
…sdk-5621-avoid-integrator-lock-updates

SDK-5621 Avoid integrator lock updates
  • Loading branch information
pavelmaksimov25 authored Dec 4, 2023
2 parents 6563df9 + 3ac8df9 commit a451860
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/IntegratorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
use SprykerSdk\Integrator\Executor\ManifestExecutorInterface;
use SprykerSdk\Integrator\Executor\Module\ModuleManifestExecutor;
use SprykerSdk\Integrator\Executor\Module\ModuleManifestExecutorInterface;
use SprykerSdk\Integrator\Executor\ProcessExecutor;
use SprykerSdk\Integrator\Executor\ReleaseGroup\DiffGenerator;
use SprykerSdk\Integrator\FileStorage\BucketFileStorage;
use SprykerSdk\Integrator\FileStorage\BucketFileStorageInterface;
Expand Down Expand Up @@ -249,7 +250,7 @@ public function createIntegratorLockWriter(): IntegratorLockWriterInterface
*/
public function createIntegratorLockCleaner(): IntegratorLockCleanerInterface
{
return new IntegratorLockCleaner($this->getConfig());
return new IntegratorLockCleaner($this->getConfig(), new ProcessExecutor());
}

/**
Expand Down
29 changes: 28 additions & 1 deletion src/IntegratorLock/IntegratorLockCleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace SprykerSdk\Integrator\IntegratorLock;

use SprykerSdk\Integrator\Executor\ProcessExecutor;
use SprykerSdk\Integrator\IntegratorConfig;

class IntegratorLockCleaner implements IntegratorLockCleanerInterface
Expand All @@ -18,12 +19,19 @@ class IntegratorLockCleaner implements IntegratorLockCleanerInterface
*/
protected IntegratorConfig $config;

/**
* @var \SprykerSdk\Integrator\Executor\ProcessExecutor
*/
protected ProcessExecutor $processExecutor;

/**
* @param \SprykerSdk\Integrator\IntegratorConfig $config
* @param \SprykerSdk\Integrator\Executor\ProcessExecutor $processExecutor
*/
public function __construct(IntegratorConfig $config)
public function __construct(IntegratorConfig $config, ProcessExecutor $processExecutor)
{
$this->config = $config;
$this->processExecutor = $processExecutor;
}

/**
Expand All @@ -34,5 +42,24 @@ public function deleteLock(): void
$lockFilePath = $this->config->getIntegratorLockFilePath();

unlink($lockFilePath);

if (!$this->isLockFileChangeTrackedByGit($lockFilePath)) {
return;
}

$this->processExecutor->execute(['git', 'add', $lockFilePath]);
$this->processExecutor->execute(['git', 'commit', '-m', 'Removed `integrator.lock` file.']);
}

/**
* @param string $filepath
*
* @return bool
*/
protected function isLockFileChangeTrackedByGit(string $filepath): bool
{
$process = $this->processExecutor->execute(['git', 'status', '--porcelain', $filepath]);

return $process->getOutput() !== '';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace SprykerSdkTest\Integrator\IntegratorLock;

use SprykerSdk\Integrator\Executor\ProcessExecutor;
use SprykerSdk\Integrator\IntegratorConfig;
use SprykerSdk\Integrator\IntegratorLock\IntegratorLockCleaner;
use SprykerSdk\Integrator\IntegratorLock\IntegratorLockReader;
Expand Down Expand Up @@ -108,7 +109,7 @@ private function createIntegratorLockReader(string $tmpIntegratorLockFilePath):
*/
private function createIntegratorLockCleaner(string $tmpIntegratorLockFilePath): IntegratorLockCleaner
{
return new IntegratorLockCleaner($this->mockIntegratorConfig($tmpIntegratorLockFilePath));
return new IntegratorLockCleaner($this->mockIntegratorConfig($tmpIntegratorLockFilePath), new ProcessExecutor());
}

/**
Expand Down

0 comments on commit a451860

Please sign in to comment.