From cad22294e6a5720590cd4c60e1f1f905c2df9d13 Mon Sep 17 00:00:00 2001 From: Ngo Quoc Dat Date: Mon, 17 Aug 2026 21:55:00 +0700 Subject: [PATCH] ci: cache Composer downloads, so a codeload outage stops taking the build down MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every PHP job downloads its dependencies from scratch on every run. npm has been cached since the workflows were written; Composer never was. When GitHub's codeload started answering 429 this afternoon, all three PHP jobs died at "Install PHP dependencies" before a single test executed — 108 rate-limit responses and zero assertions run, on a commit that was green locally. Caches the Composer files directory rather than vendor/. The files cache holds the downloaded archives, so `composer install` still resolves and extracts normally and cannot be fooled by a partially restored vendor tree; it simply finds every archive on disk instead of reaching for the network. Keyed on composer.lock, so a dependency change invalidates it exactly, with a restore-key so a changed lock still reuses every archive that did not move and only fetches the delta. Applied at all four install sites: both jobs in tests.yml, plus lint.yml and og.yml, each placed after setup-php so composer is on PATH when the cache directory is resolved. The key deliberately omits the PHP version — the matrix jobs download identical archives, so 8.4 and 8.5 share one cache. This does not rescue a cold cache: the first run after this merge still has to download, and will still fail if the incident is ongoing. It stops the second one from depending on GitHub being healthy. --- .github/workflows/lint.yml | 11 +++++++++++ .github/workflows/og.yml | 11 +++++++++++ .github/workflows/tests.yml | 22 ++++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 3d71b14..5f7903a 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -25,6 +25,17 @@ jobs: php-version: "8.4" tools: composer:v2 + - name: Resolve the Composer cache directory + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT" + + - name: Cache Composer downloads + uses: actions/cache@v4 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: composer-${{ runner.os }}-${{ hashFiles('composer.lock') }} + restore-keys: composer-${{ runner.os }}- + - name: Install dependencies run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist diff --git a/.github/workflows/og.yml b/.github/workflows/og.yml index cb5a898..78b5535 100644 --- a/.github/workflows/og.yml +++ b/.github/workflows/og.yml @@ -41,6 +41,17 @@ jobs: with: node-version: "22" + - name: Resolve the Composer cache directory + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT" + + - name: Cache Composer downloads + uses: actions/cache@v4 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: composer-${{ runner.os }}-${{ hashFiles('composer.lock') }} + restore-keys: composer-${{ runner.os }}- + - name: Install dependencies run: composer install --no-interaction --prefer-dist diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 13f7f1d..b72fc6b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -30,6 +30,17 @@ jobs: tools: composer:v2 coverage: none + - name: Resolve the Composer cache directory + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT" + + - name: Cache Composer downloads + uses: actions/cache@v4 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: composer-${{ runner.os }}-${{ hashFiles('composer.lock') }} + restore-keys: composer-${{ runner.os }}- + - name: Install dependencies run: composer install --no-interaction --prefer-dist --optimize-autoloader @@ -89,6 +100,17 @@ jobs: node-version: "22" cache: npm + - name: Resolve the Composer cache directory + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT" + + - name: Cache Composer downloads + uses: actions/cache@v4 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: composer-${{ runner.os }}-${{ hashFiles('composer.lock') }} + restore-keys: composer-${{ runner.os }}- + - name: Install PHP dependencies run: composer install --no-interaction --prefer-dist --optimize-autoloader