Repository: symplify/symplify (php)

Issue:
[CI] Add automated Rector + CS as in Rector repository
See https://github.com/rectorphp/rector/blob/27daba1fb3fe0a188f7257b8f42022c3671b4d2e/.github/workflows/rector_ci.yaml#L43-L78

Pull request:
[CI] Add Rector CI
Closes #2059 

Patch:
diff --git a/.github/workflows/rector_ci.yaml b/.github/workflows/rector_ci.yaml
new file mode 100644
index 000000000..5102bffe6
--- /dev/null
+++ b/.github/workflows/rector_ci.yaml
@@ -0,0 +1,79 @@
+####
+# Due to some Github Actions limitations, we are running realtime fixes (commits) only for self-owned-pr
+#
+# Current limitations:
+# - Secrets (ACCESS_TOKEN) are not available in PRs from forks
+# - Github Token has Read-only access (can not commit), Personal Access Token must be used instead
+# - Github Token does not trigger workflows after push
+#
+# So we basically have chicken-egg problem here
+#
+# https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token#permissions-for-the-github_token
+####
+name: Rector CI
+
+on:
+    pull_request: null
+    push:
+        branches:
+            - master
+
+jobs:
+    rector-ci:
+        runs-on: ubuntu-latest
+        if: github.event.pull_request.head.repo.full_name == github.repository
+        steps:
+            -
+                uses: actions/checkout@v2
+                with:
+                    # Solves the not "You are not currently on a branch" problem, see https://github.com/actions/checkout/issues/124#issuecomment-586664611
+                    ref: ${{ github.event.pull_request.head.ref }}
+                    # Must be used to trigger workflow after push
+                    token: ${{ secrets.ACCESS_TOKEN }}
+
+            -
+                uses: shivammathur/setup-php@v1
+                with:
+                    php-version: 7.4
+                    coverage: none
+
+            -   run: composer install --no-progress --ansi
+
+            ## First run Rector without --dry-run, it would stop the process with exit 1 here
+            -   run: vendor/bin/rector process --config rector-ci.php --ansi
+
+            -
+                name: Check for Rector modified files
+                id: rector-git-check
+                run: echo ::set-output name=modified::$(if git diff --exit-code --no-patch; then echo "false"; else echo "true"; fi)
+
+            -   name: Git config
+                if: steps.rector-git-check.outputs.modified == 'true'
+                run: |
+                    git config --global user.name 'rector-bot'
+                    git config --global user.email 'tomas@getrector.org'
+                    echo ::set-env name=COMMIT_MESSAGE::$(git log -1 --pretty=format:"%s")
+
+            -   name: Commit Rector changes
+                if: steps.rector-git-check.outputs.modified == 'true'
+                run: git commit -am "[rector] ${COMMIT_MESSAGE}"
+
+            ## Now, there might be coding standard issues after running Rector
+            -
+                if: steps.rector-git-check.outputs.modified == 'true'
+                run: composer fix-cs
+
+            -
+                name: Check for CS modified files
+                if: steps.rector-git-check.outputs.modified == 'true'
+                id: cs-git-check
+                run: echo ::set-output name=modified::$(if git diff --exit-code --no-patch; then echo "false"; else echo "true"; fi)
+
+            -   name: Commit CS changes
+                if: steps.cs-git-check.outputs.modified == 'true'
+                run: git commit -am "[cs] ${COMMIT_MESSAGE}"
+
+            -   name: Push changes
+                if: steps.rector-git-check.outputs.modified == 'true'
+                run: git push
+                # In case we want to fail this job when there are changed files, just add "exit 1"
diff --git a/composer.json b/composer.json
index 39a0c5cd8..b386296fe 100644
--- a/composer.json
+++ b/composer.json
@@ -48,11 +48,12 @@
         "ergebnis/phpstan-rules": "^0.15.0",
         "migrify/class-presence": "^0.3.6",
         "migrify/config-transformer": "^0.3.6",
+        "migrify/easy-ci": "^0.3.25",
         "nette/application": "^3.0",
         "nette/bootstrap": "^3.0",
         "nikic/php-parser": "^4.7",
         "phpunit/phpunit": "^8.5|^9.0",
-        "rector/rector": "^0.7.62",
+        "rector/rector": "dev-master",
         "slam/phpstan-extensions": "^5.0",
         "symfony/framework-bundle": "^4.4|^5.0",
         "symfony/templating": "^4.4|^5.0",
@@ -135,25 +136,25 @@
         }
     },
     "replace": {
-        "symplify/auto-bind-parameter": "8.1.19",
-        "symplify/autodiscovery": "8.1.19",
-        "symplify/autowire-array-parameter": "8.1.19",
-        "symplify/changelog-linker": "8.1.19",
-        "symplify/coding-standard": "8.1.19",
-        "symplify/composer-json-manipulator": "8.1.19",
-        "symplify/console-color-diff": "8.1.19",
-        "symplify/easy-coding-standard": "8.1.19",
-        "symplify/easy-coding-standard-compiler": "8.1.19",
-        "symplify/easy-coding-standard-tester": "8.1.19",
-        "symplify/easy-hydrator": "8.1.19",
-        "symplify/easy-testing": "8.1.19",
-        "symplify/flex-loader": "8.1.19",
-        "symplify/monorepo-builder": "8.1.19",
-        "symplify/package-builder": "8.1.19",
-        "symplify/phpstan-extensions": "8.1.19",
-        "symplify/set-config-resolver": "8.1.19",
-        "symplify/smart-file-system": "8.1.19",
-        "symplify/symfony-static-dumper": "8.1.19"
+        "symplify/auto-bind-parameter": "8.2.2",
+        "symplify/autodiscovery": "8.2.2",
+        "symplify/autowire-array-parameter": "8.2.2",
+        "symplify/changelog-linker": "8.2.2",
+        "symplify/coding-standard": "8.2.2",
+        "symplify/composer-json-manipulator": "8.2.2",
+        "symplify/console-color-diff": "8.2.2",
+        "symplify/easy-coding-standard": "8.2.2",
+        "symplify/easy-coding-standard-compiler": "8.2.2",
+        "symplify/easy-coding-standard-tester": "8.2.2",
+        "symplify/easy-hydrator": "8.2.2",
+        "symplify/easy-testing": "8.2.2",
+        "symplify/flex-loader": "8.2.2",
+        "symplify/monorepo-builder": "8.2.2",
+        "symplify/package-builder": "8.2.2",
+        "symplify/phpstan-extensions": "8.2.2",
+        "symplify/set-config-resolver": "8.2.2",
+        "symplify/smart-file-system": "8.2.2",
+        "symplify/symfony-static-dumper": "8.2.2"
     },
     "scripts": {
         "complete-check": [
diff --git a/rector-ci.php b/rector-ci.php
index 39804e093..cf66b10ab 100644
--- a/rector-ci.php
+++ b/rector-ci.php
@@ -24,10 +24,16 @@ return static function (ContainerConfigurator $containerConfigurator): void {
     $parameters = $containerConfigurator->parameters();
 
     $parameters->set(Option::AUTO_IMPORT_NAMES, true);
-
     $parameters->set(Option::AUTOLOAD_PATHS, [__DIR__ . '/tests/bootstrap.php', __DIR__ . '/ecs.php']);
 
-    $parameters->set(Option::SETS, [SetList::CODE_QUALITY, SetList::DEAD_CODE, SetList::CODING_STYLE, SetList::PHP_70, SetList::PHP_71, SetList::PHP_72]);
+    $parameters->set(Option::SETS, [
+        SetList::CODE_QUALITY,
+        SetList::DEAD_CODE,
+        SetList::CODING_STYLE,
+        SetList::PHP_70,
+        SetList::PHP_71,
+        SetList::PHP_72,
+    ]);
 
     $parameters->set(Option::PATHS, [__DIR__ . '/packages']);
 


Test patch:
diff --git a/packages/monorepo-builder/packages/merge/tests/ComposerJsonDecorator/RemoverComposerJsonDecorator/RemoverComposerJsonDecoratorTest.php b/packages/monorepo-builder/packages/merge/tests/ComposerJsonDecorator/RemoverComposerJsonDecorator/RemoverComposerJsonDecoratorTest.php
index 8bab69e54..b3556ad64 100644
--- a/packages/monorepo-builder/packages/merge/tests/ComposerJsonDecorator/RemoverComposerJsonDecorator/RemoverComposerJsonDecoratorTest.php
+++ b/packages/monorepo-builder/packages/merge/tests/ComposerJsonDecorator/RemoverComposerJsonDecorator/RemoverComposerJsonDecoratorTest.php
@@ -13,7 +13,7 @@ use Symplify\MonorepoBuilder\Merge\Tests\ComposerJsonDecorator\AbstractComposerJ
 final class RemoverComposerJsonDecoratorTest extends AbstractComposerJsonDecoratorTest
 {
     /**
-     * @var string[][]|string[][][]
+     * @var array<string, string>[]|string[][][]
      */
     private const COMPOSER_JSON_DATA = [
         'require' => [