Skip to content

Commit 805b2a4

Browse files
authored
Fix parameter merge priority to allow user configs to override defaults and invalid disable default workers config (#96)
* Fix parameter merge priority to allow user configs to override defaults * Fix invalid disable default workers config
1 parent eef024e commit 805b2a4

File tree

4 files changed

+56
-7
lines changed

4 files changed

+56
-7
lines changed

config/config.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,10 @@
5555
__DIR__ . '/../packages/Release/ReleaseWorker',
5656
]);
5757

58-
if (! $mbConfig->isDisableDefaultWorkers()) {
59-
// add default for easy tag and push without need to make configs
60-
$services->set(TagVersionReleaseWorker::class);
61-
$services->set(PushTagReleaseWorker::class);
62-
}
58+
// Always register default workers here. They will be removed by
59+
// RemoveDefaultWorkersCompilerPass if user called disableDefaultWorkers()
60+
$services->set(TagVersionReleaseWorker::class);
61+
$services->set(PushTagReleaseWorker::class);
6362

6463
$services->load('Symplify\MonorepoBuilder\\', __DIR__ . '/../src')
6564
->exclude([

src-deps/package-builder/src/DependencyInjection/FileLoader/ParameterMergingPhpFileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function load(mixed $resource, ?string $type = null): mixed
5656
foreach ($oldParameters as $key => $oldValue) {
5757
if ($this->container->hasParameter($key)) {
5858
$currentParameterValue = $this->container->getParameter($key);
59-
$newValue = $this->parametersMerger->merge($oldValue, $currentParameterValue);
59+
$newValue = $this->parametersMerger->merge($currentParameterValue, $oldValue);
6060
$this->container->setParameter($key, $newValue);
6161
}
6262
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symplify\MonorepoBuilder\DependencyInjection\CompilerPass;
6+
7+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
8+
use Symfony\Component\DependencyInjection\ContainerBuilder;
9+
use Symplify\MonorepoBuilder\Config\MBConfig;
10+
use Symplify\MonorepoBuilder\Release\ReleaseWorker\PushTagReleaseWorker;
11+
use Symplify\MonorepoBuilder\Release\ReleaseWorker\TagVersionReleaseWorker;
12+
13+
/**
14+
* Removes default release workers from the container if MBConfig::disableDefaultWorkers() was called.
15+
* This needs to happen in a compiler pass rather than during config loading because:
16+
* 1. Default config is loaded before user config (to allow parameter overriding)
17+
* 2. User config calls disableDefaultWorkers() after default config has already registered workers
18+
* 3. Compiler passes run after all configs are loaded, so they can see the final state
19+
*/
20+
final readonly class RemoveDefaultWorkersCompilerPass implements CompilerPassInterface
21+
{
22+
public function process(ContainerBuilder $containerBuilder): void
23+
{
24+
// Check if user disabled default workers in their config
25+
if (! MBConfig::isDisableDefaultWorkers()) {
26+
return;
27+
}
28+
29+
// Remove the default workers from the container
30+
$defaultWorkers = [
31+
TagVersionReleaseWorker::class,
32+
PushTagReleaseWorker::class,
33+
];
34+
35+
foreach ($defaultWorkers as $defaultWorker) {
36+
if ($containerBuilder->hasDefinition($defaultWorker)) {
37+
$containerBuilder->removeDefinition($defaultWorker);
38+
}
39+
}
40+
}
41+
}

src/Kernel/MonorepoBuilderKernel.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Psr\Container\ContainerInterface;
88
use Symplify\MonorepoBuilder\Contract\Git\TagResolverInterface;
9+
use Symplify\MonorepoBuilder\DependencyInjection\CompilerPass\RemoveDefaultWorkersCompilerPass;
910
use Symplify\MonorepoBuilder\Release\Contract\ReleaseWorker\ReleaseWorkerInterface;
1011
use Symplify\PackageBuilder\DependencyInjection\CompilerPass\AutowireInterfacesCompilerPass;
1112
use Symplify\PackageBuilder\ValueObject\ConsoleColorDiffConfig;
@@ -26,7 +27,15 @@ public function createFromConfigs(array $configFiles): ContainerInterface
2627
ReleaseWorkerInterface::class,
2728
TagResolverInterface::class,
2829
]);
29-
$compilerPasses = [$autowireInterfacesCompilerPass];
30+
31+
// This compiler pass must run after all configs are loaded
32+
// to properly detect if user called disableDefaultWorkers()
33+
$removeDefaultWorkersCompilerPass = new RemoveDefaultWorkersCompilerPass();
34+
35+
$compilerPasses = [
36+
$autowireInterfacesCompilerPass,
37+
$removeDefaultWorkersCompilerPass,
38+
];
3039

3140
return $this->create($configFiles, $compilerPasses, []);
3241
}

0 commit comments

Comments
 (0)