Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK-5621 Avoid integrator lock updates #165

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
*/
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 @@
$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.']);

Check warning on line 51 in src/IntegratorLock/IntegratorLockCleaner.php

View check run for this annotation

Codecov / codecov/patch

src/IntegratorLock/IntegratorLockCleaner.php#L50-L51

Added lines #L50 - L51 were not covered by tests
}

/**
* @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
Loading