Run rector only on changed files in Gitlab

Rector changed files only:
  stage: analyze
  interruptible: true
  dependencies: [ "Install Composer dependencies" ]
  needs: [ "Install Composer dependencies" ]
    - export MERGE_BASE=$(git merge-base origin/$CI_COMMIT_BRANCH origin/develop)
    - export FILES=$(git diff $MERGE_BASE...$CI_COMMIT_SHA --name-only --diff-filter=d | grep .php)
    - if [ -z "$FILES" ]; then echo "No PHP-Files to scan"; exit 0; fi;
    - echo $FILES;
    - vendor/bin/rector process --dry-run $FILES || exit 1;
    - develop
    - master

If you have a large PHP project and use Rector for automated refactoring, it might become very slow or run in memory or timeout limits.

To prevent this, you could run rector only on changed files

Gitlab Pipeline with fast running rector

Article relase date: / Last update: