-
-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the possibility to process files in batches
- Loading branch information
1 parent
a1cbff4
commit 404775e
Showing
20 changed files
with
381 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Test workflow to show how this feature works. DO NOT MERGE, REMOVE IN FINAL VERSION OF PR | ||
name: Rector | ||
|
||
on: | ||
pull_request: null | ||
|
||
jobs: | ||
no_batch_rector: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- | ||
uses: actions/checkout@v4 | ||
|
||
- | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: 8.2 | ||
coverage: none | ||
|
||
- run: composer install --no-progress --ansi | ||
|
||
- run: bin/rector process --ansi | ||
batch_rector: | ||
strategy: | ||
matrix: | ||
batches: [0, 1, 2, 3] | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- | ||
uses: actions/checkout@v4 | ||
|
||
- | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: 8.2 | ||
coverage: none | ||
|
||
- run: composer install --no-progress --ansi | ||
|
||
- run: bin/rector process --batch-index=${{ strategy.job-index }} --batch-total=${{ strategy.job-total }} --ansi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# This workflow runs system tests: Use the Rector application from the source | ||
# checkout to process "fixture" projects in e2e/batch-run directory | ||
# to see if those can be processed successfully in batches | ||
name: End to End tests with batches | ||
|
||
on: | ||
pull_request: null | ||
|
||
env: | ||
# see https://github.com/composer/composer/issues/9368#issuecomment-718112361 | ||
COMPOSER_ROOT_VERSION: "dev-main" | ||
|
||
jobs: | ||
end_to_end: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 3 | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
batches: [0, 1] | ||
|
||
name: End to end test with batches - batch ${{ strategy.job-index }} | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: 8.2 | ||
coverage: none | ||
|
||
# run in root rector-src | ||
- run: composer install --ansi | ||
|
||
# run in e2e subdir | ||
- | ||
run: composer install --ansi | ||
working-directory: e2e/batch-run | ||
|
||
# run e2e test | ||
- run: php ../e2eTestRunnerWithBatches.php ${{ strategy.job-index }} ${{ strategy.job-total }} | ||
working-directory: e2e/batch-run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"require": { | ||
"php": "^8.1" | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
1 file with changes | ||
=================== | ||
|
||
1) src/RenameDocblock.php:0 | ||
|
||
---------- begin diff ---------- | ||
@@ @@ | ||
<?php | ||
|
||
/** | ||
- * @param DateTime $someOldClass | ||
+ * @param \DateTimeInterface $someOldClass | ||
*/ | ||
function someFunction($someOldClass) | ||
{ | ||
----------- end diff ----------- | ||
|
||
Applied rules: | ||
* RenameClassRector | ||
|
||
|
||
[OK] 1 file would have been changed (dry-run) by Rector |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
1 file with changes | ||
=================== | ||
|
||
1) src/UselessVarTag.php:1 | ||
|
||
---------- begin diff ---------- | ||
@@ @@ | ||
|
||
final class UselessVarTag | ||
{ | ||
- /** | ||
- * @var string | ||
- */ | ||
public string $name = 'name'; | ||
} | ||
----------- end diff ----------- | ||
|
||
Applied rules: | ||
* RemoveUselessVarTagRector | ||
|
||
|
||
[OK] 1 file would have been changed (dry-run) by Rector |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector; | ||
use Rector\DowngradePhp80\Rector\Class_\DowngradeAttributeToAnnotationRector; | ||
use Rector\DowngradePhp80\ValueObject\DowngradeAttributeToAnnotation; | ||
use Rector\Renaming\Rector\Name\RenameClassRector; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->paths([ | ||
__DIR__ . '/src', | ||
]); | ||
|
||
$rectorConfig->ruleWithConfiguration(RenameClassRector::class, [ | ||
'DateTime' => 'DateTimeInterface' | ||
]); | ||
$rectorConfig->ruleWithConfiguration(DowngradeAttributeToAnnotationRector::class, [ | ||
new DowngradeAttributeToAnnotation('Symfony\Component\Routing\Annotation\Route') | ||
]); | ||
|
||
$rectorConfig->rule(RemoveUselessVarTagRector::class); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
/** | ||
* @param DateTimeInterface $someOldClass | ||
*/ | ||
function someFunction($someOldClass) | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
/** | ||
* @param DateTime $someOldClass | ||
*/ | ||
function someFunction($someOldClass) | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
final class UselessVarTag | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
public string $name = 'name'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
// runs a rector e2e test. | ||
// checks whether we expect a certain output, or alternatively that rector just processed everything without errors | ||
|
||
use Rector\Console\Formatter\ColorConsoleDiffFormatter; | ||
use Rector\Console\Formatter\ConsoleDiffer; | ||
use Rector\Console\Style\SymfonyStyleFactory; | ||
use Rector\Util\Reflection\PrivatesAccessor; | ||
use Symfony\Component\Console\Command\Command; | ||
|
||
$projectRoot = __DIR__ .'/..'; | ||
$rectorBin = $projectRoot . '/bin/rector'; | ||
$autoloadFile = $projectRoot . '/vendor/autoload.php'; | ||
|
||
// so we can use helper classes here | ||
require_once __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$batchIndex = $argv[1]; | ||
$batchTotal = $argv[2]; | ||
|
||
$e2eCommand = 'php '. $rectorBin .' process --dry-run --no-ansi -a '. $autoloadFile | ||
. ' --batch-index=' . $batchIndex . ' --batch-total=' . $batchTotal; | ||
|
||
exec($e2eCommand, $output, $exitCode); | ||
$output = trim(implode("\n", $output)); | ||
$output = str_replace(__DIR__, '.', $output); | ||
|
||
$expectedDiff = 'expected-output-' . $batchIndex . '.diff'; | ||
if (!file_exists($expectedDiff)) { | ||
echo $output; | ||
exit($exitCode); | ||
} | ||
|
||
$symfonyStyleFactory = new SymfonyStyleFactory(new PrivatesAccessor()); | ||
$symfonyStyle = $symfonyStyleFactory->create(); | ||
|
||
$matchedExpectedOutput = false; | ||
$expectedOutput = trim(file_get_contents($expectedDiff)); | ||
if ($output === $expectedOutput) { | ||
$symfonyStyle->success('End-to-end test successfully completed'); | ||
exit(Command::SUCCESS); | ||
} | ||
|
||
// print color diff, to make easy find the differences | ||
$consoleDiffer = new ConsoleDiffer(new ColorConsoleDiffFormatter()); | ||
$diff = $consoleDiffer->diff($output, $expectedOutput); | ||
$symfonyStyle->writeln($diff); | ||
|
||
exit(Command::FAILURE); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.