Skip to content

Commit 34062bc

Browse files
committed
[cache] Cache unchanged files on --dry-run v2
1 parent 6103045 commit 34062bc

File tree

8 files changed

+73
-4
lines changed

8 files changed

+73
-4
lines changed

.github/workflows/e2e_consecutive_changes.yaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,20 @@ jobs:
4343
run: composer install --ansi
4444
working-directory: ${{ matrix.directory }}
4545

46+
# run e2e test with dry run, we expect non-zero exit code
47+
- run: php ../e2eTestChangingRunnerWithCache.php -o expected-output-1-dry-run.diff --dry-run
48+
working-directory: ${{ matrix.directory }}
49+
continue-on-error: true
50+
51+
# run e2e test with dry run once more, we expect non-zero exit code again
52+
- run: php ../e2eTestChangingRunnerWithCache.php -o expected-output-2-dry-run.diff --dry-run
53+
working-directory: ${{ matrix.directory }}
54+
continue-on-error: true
55+
4656
# run e2e test
47-
- run: php ../e2eTestChangingRunnerWithCache.php -o expected-output-1.diff
57+
- run: php ../e2eTestChangingRunnerWithCache.php -o expected-output-3.diff
4858
working-directory: ${{ matrix.directory }}
4959

5060
# this tests that a 2nd run with cache and consecutive changes works, see https://github.com/rectorphp/rector-src/pull/3614#issuecomment-1507742338
51-
- run: php ../e2eTestChangingRunnerWithCache.php -o expected-output-2.diff
61+
- run: php ../e2eTestChangingRunnerWithCache.php -o expected-output-4.diff
5262
working-directory: ${{ matrix.directory }}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
1 file with changes
2+
===================
3+
4+
1) src/Source.php:1
5+
6+
---------- begin diff ----------
7+
@@ @@
8+
9+
$a = true;
10+
$b = true;
11+
-
12+
-if ($a && $b) {
13+
- return true;
14+
+if (!$a) {
15+
+ return;
16+
}
17+
+if (!$b) {
18+
+ return;
19+
+}
20+
+return true;
21+
----------- end diff -----------
22+
23+
Applied rules:
24+
* ChangeAndIfToEarlyReturnRector
25+
26+
27+
[OK] 1 file would have changed (dry-run) by Rector
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
1 file with changes
2+
===================
3+
4+
1) src/Source.php:1
5+
6+
---------- begin diff ----------
7+
@@ @@
8+
9+
$a = true;
10+
$b = true;
11+
-
12+
-if ($a && $b) {
13+
- return true;
14+
+if (!$a) {
15+
+ return;
16+
}
17+
+if (!$b) {
18+
+ return;
19+
+}
20+
+return true;
21+
----------- end diff -----------
22+
23+
Applied rules:
24+
* ChangeAndIfToEarlyReturnRector
25+
26+
27+
[OK] 1 file would have changed (dry-run) by Rector

e2e/e2eTestChangingRunnerWithCache.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
$expectedDiff = 'expected-output.diff';
2626
}
2727

28+
if (isset($argv[3]) && $argv[3] === '--dry-run') {
29+
$e2eCommand .= ' --dry-run';
30+
}
31+
2832
exec($e2eCommand, $output, $exitCode);
2933
$output = trim(implode("\n", $output));
3034
$output = str_replace(__DIR__, '.', $output);

packages/Parallel/WorkerRunner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function run(Encoder $encoder, Decoder $decoder, Configuration $configura
9595

9696
if ($errorAndFileDiffs[Bridge::SYSTEM_ERRORS] !== []) {
9797
$this->invalidateFile($file);
98-
} elseif (! $configuration->isDryRun()) {
98+
} else if (! $configuration->isDryRun() || $errorAndFileDiffs[Bridge::FILE_DIFFS] === []) {
9999
$this->changedFilesDetector->cacheFileWithDependencies($file->getFilePath());
100100
}
101101
} catch (Throwable $throwable) {

phpstan.neon

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ parameters:
5656
- tests/DependencyInjection/config
5757

5858
ignoreErrors:
59+
- '#Cognitive complexity for "Rector\\Parallel\\WorkerRunner\:\:run\(\)" is 12, keep it under 11#'
5960
- '#Cognitive complexity for "Rector\\Php80\\NodeResolver\\SwitchExprsResolver\:\:resolve\(\)" is (.*?), keep it under 11#'
6061

6162
-
@@ -687,4 +688,4 @@ parameters:
687688
- """
688689
#^Fetching class constant class of deprecated class Rector\\\\CodingStyle\\\\Rector\\\\ClassConst\\\\VarConstantCommentRector\\:
689690
The doc block types are not reliable, and typed constants are comming to PHP 8\\.3, use those instead\\.$#
690-
"""
691+
"""

0 commit comments

Comments
 (0)