Cache in CI
While parsing your application code, Rector generates objects representing that code. It caches these objects to a directory for later reuse, so it doesn't have to parse the entire application again, by detecting which files have changed since the last Rector run.
When running Rector in a Continuous Integration (CI) system such as GitHub Actions, set a stable cache directory that you can persist between jobs. Without it, each job parses all code from scratch.
<?php
use Rector\Config\RectorConfig;
return RectorConfig::configure()
->withCache(
// specify a path that works locally as well as on CI job runners
cacheDirectory: '/tmp/rector'
);
The actual path, when not specified, may vary per (runner) OS, so set it explicitly to keep it the same on CI and development.
Debugging the Cache Locally
Generate the cache on your development machine, by running the command:
vendor/bin/rector process --dry-run
You can find it in /tmp/rector, containing folders like 0a, 0b, 0c, ... containing the cache objects representing the latest run.
This, preferably prepended with php , command is also what your CI action should run, after mapping the cache directory from an earlier run.
GitHub Actions
On GitHub Actions, you can use the built-in cache action as a step to point to a path that you want cached between jobs:
- name: Rector Cache
uses: actions/cache@v4
with:
path: /tmp/rector
key: ${{ runner.os }}-rector-${{ github.run_id }}
restore-keys: ${{ runner.os }}-rector-
- run: mkdir -p /tmp/rector
- name: Rector Dry Run
run: php vendor/bin/rector process --dry-run --config=rector.php
In this key configuration, runs on branches inherit the cache from their parent, if any.