Skip to content
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
41 changes: 41 additions & 0 deletions .github/workflows/compiled_rector_cache.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions e2e/compiled-rector-cache/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/vendor
/cache
13 changes: 13 additions & 0 deletions e2e/compiled-rector-cache/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"require": {
"php": "^8.2"
},
"require-dev": {
"phpunit/phpunit": "^11.5"
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
}
}
12 changes: 12 additions & 0 deletions e2e/compiled-rector-cache/rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;

return RectorConfig::configure()
->withPaths([__DIR__ . '/src'])
// the PHPUnit set puts PHPStan types in the configuration, which the cache hashes
->withComposerBased(phpunit: true)
->withParallel()
->withCache(__DIR__ . '/cache');
18 changes: 18 additions & 0 deletions e2e/compiled-rector-cache/src/Customer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace App;

final class Customer
{
public function __construct(
private readonly string $name,
) {
}

public function getName(): string
{
return $this->name;
}
}
18 changes: 18 additions & 0 deletions e2e/compiled-rector-cache/src/Invoice.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace App;

final class Invoice
{
public function __construct(
private readonly string $name,
) {
}

public function getName(): string
{
return $this->name;
}
}
18 changes: 18 additions & 0 deletions e2e/compiled-rector-cache/src/Order.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace App;

final class Order
{
public function __construct(
private readonly string $name,
) {
}

public function getName(): string
{
return $this->name;
}
}
5 changes: 4 additions & 1 deletion src/DependencyInjection/RectorContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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);
Expand Down
Loading