diff --git a/.github/workflows/compiled_rector_cache.yaml b/.github/workflows/compiled_rector_cache.yaml new file mode 100644 index 00000000000..db9363ef03f --- /dev/null +++ b/.github/workflows/compiled_rector_cache.yaml @@ -0,0 +1,41 @@ +# Runs the compiled rector/rector on a small project twice, to check that the cache survives a run. +# The compiled build is published from main, so this runs after a merge, not on a pull request. +name: Compiled Rector Cache + +on: + push: + branches: + - main + schedule: + - cron: '0 6 * * *' + workflow_dispatch: null + +jobs: + compiled_rector_cache: + runs-on: ubuntu-latest + timeout-minutes: 5 + + steps: + - uses: actions/checkout@v5 + + - + uses: shivammathur/setup-php@v2 + with: + php-version: 8.4 + coverage: none + + - run: composer require --dev rector/rector:dev-main --ansi + working-directory: e2e/compiled-rector-cache + + - run: vendor/bin/rector process --dry-run --ansi + working-directory: e2e/compiled-rector-cache + + # a run that clears the cache also removes this marker + - run: touch cache/marker + working-directory: e2e/compiled-rector-cache + + - run: vendor/bin/rector process --dry-run --ansi + working-directory: e2e/compiled-rector-cache + + - run: test -f cache/marker || (echo "The second run cleared the cache" && exit 1) + working-directory: e2e/compiled-rector-cache diff --git a/e2e/compiled-rector-cache/.gitignore b/e2e/compiled-rector-cache/.gitignore new file mode 100644 index 00000000000..e2d5bf368e0 --- /dev/null +++ b/e2e/compiled-rector-cache/.gitignore @@ -0,0 +1,2 @@ +/vendor +/cache diff --git a/e2e/compiled-rector-cache/composer.json b/e2e/compiled-rector-cache/composer.json new file mode 100644 index 00000000000..bde01e54aa4 --- /dev/null +++ b/e2e/compiled-rector-cache/composer.json @@ -0,0 +1,13 @@ +{ + "require": { + "php": "^8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.5" + }, + "autoload": { + "psr-4": { + "App\\": "src/" + } + } +} diff --git a/e2e/compiled-rector-cache/rector.php b/e2e/compiled-rector-cache/rector.php new file mode 100644 index 00000000000..6753e3bc537 --- /dev/null +++ b/e2e/compiled-rector-cache/rector.php @@ -0,0 +1,12 @@ +withPaths([__DIR__ . '/src']) + // the PHPUnit set puts PHPStan types in the configuration, which the cache hashes + ->withComposerBased(phpunit: true) + ->withParallel() + ->withCache(__DIR__ . '/cache'); diff --git a/e2e/compiled-rector-cache/src/Customer.php b/e2e/compiled-rector-cache/src/Customer.php new file mode 100644 index 00000000000..52f7f56c71a --- /dev/null +++ b/e2e/compiled-rector-cache/src/Customer.php @@ -0,0 +1,18 @@ +name; + } +} diff --git a/e2e/compiled-rector-cache/src/Invoice.php b/e2e/compiled-rector-cache/src/Invoice.php new file mode 100644 index 00000000000..7f333b6888b --- /dev/null +++ b/e2e/compiled-rector-cache/src/Invoice.php @@ -0,0 +1,18 @@ +name; + } +} diff --git a/e2e/compiled-rector-cache/src/Order.php b/e2e/compiled-rector-cache/src/Order.php new file mode 100644 index 00000000000..5f84c510daf --- /dev/null +++ b/e2e/compiled-rector-cache/src/Order.php @@ -0,0 +1,18 @@ +name; + } +} diff --git a/src/DependencyInjection/RectorContainerFactory.php b/src/DependencyInjection/RectorContainerFactory.php index 0373854a1ae..601c0281a1e 100644 --- a/src/DependencyInjection/RectorContainerFactory.php +++ b/src/DependencyInjection/RectorContainerFactory.php @@ -9,6 +9,7 @@ use Rector\Config\RectorConfig; use Rector\NodeTypeResolver\DependencyInjection\PHPStanServicesFactory; use Rector\ValueObject\Bootstrap\BootstrapConfigs; +use Symfony\Component\Console\Input\ArgvInput; final class RectorContainerFactory { @@ -18,7 +19,9 @@ public function createFromBootstrapConfigs(BootstrapConfigs $bootstrapConfigs): $mainConfigFile = $bootstrapConfigs->getMainConfigFile(); - if ($mainConfigFile !== null) { + // only the main process checks the configuration: the parallel workers share its cache directory, + // and a worker that clears the cache would delete files the other workers are writing + if ($mainConfigFile !== null && new ArgvInput()->getFirstArgument() !== 'worker') { /** @var ChangedFilesDetector $changedFilesDetector */ $changedFilesDetector = $rectorConfig->make(ChangedFilesDetector::class); $changedFilesDetector->setFirstResolvedConfigFileInfo($mainConfigFile);