From 924b5ada547893395f51d7f66c9511ad6510620d Mon Sep 17 00:00:00 2001 From: mscherer Date: Sun, 10 May 2026 03:38:12 +0200 Subject: [PATCH] Bust rector cache when rector version changes The rector analysis cache stores per-file 'no-changes-needed' verdicts keyed by file content. Those verdicts depend on which rector rules exist at analysis time, but the cache key was hashing only rector.php and composer.lock, neither of which change when rector itself releases a new version. As a result, new rules silently slipped past CI on already-cached sources. Fix: install rector first (the rector-setup script was previously chained with rector-check), capture the installed version via 'composer show rector/rector --format=json', and include the version in the cache key. Also include it in restore-keys so we don't restore a cache produced by a different rector version. Spotted while reducing the PHPStan baseline in cakephp/migrations#1083: two pre-existing visibility issues had been hiding behind a stale rector cache and only surfaced when the cache key happened to bust because of source changes. --- .github/workflows/cs-stan.yml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cs-stan.yml b/.github/workflows/cs-stan.yml index c421020..0a8073b 100644 --- a/.github/workflows/cs-stan.yml +++ b/.github/workflows/cs-stan.yml @@ -58,13 +58,22 @@ jobs: if: always() run: vendor/bin/phpcs --report=checkstyle | cs2pr + - name: Install rector + if: ${{ always() && hashFiles('rector.php') }} + run: composer rector-setup + + - name: Get rector version + if: ${{ always() && hashFiles('rector.php') }} + id: rector-version + run: echo "value=$(composer show rector/rector --format=json | jq -r '.versions[0]')" >> "$GITHUB_OUTPUT" + - name: Setup rector cache if: ${{ always() && hashFiles('rector.php') }} uses: actions/cache@v5 with: path: ${{ runner.temp }}/rector - key: ${{ runner.os }}-rector-${{ hashFiles('rector.php', 'composer.lock') }} - restore-keys: ${{ runner.os }}-rector- + key: ${{ runner.os }}-rector-${{ steps.rector-version.outputs.value }}-${{ hashFiles('rector.php', 'composer.lock') }} + restore-keys: ${{ runner.os }}-rector-${{ steps.rector-version.outputs.value }}- - name: Create rector cache dir if: ${{ always() && hashFiles('rector.php') }} @@ -74,4 +83,4 @@ jobs: if: ${{ always() && hashFiles('rector.php') }} env: RECTOR_CACHE_DIR: ${{ runner.temp }}/rector - run: composer rector-setup && composer rector-check + run: composer rector-check