From 7a4da1040b207c3022b4a5767a87b40e3bc1c2e4 Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Thu, 19 Feb 2026 17:04:34 +0100 Subject: [PATCH] [CI] Fix ineffective ccache Cache on GHA is immutable. For this reason, hendrikmuhs/ccache-action creates a new cache entry for each push, each with an appended timestamp, which fills the cache very quickly. In an attempt to fix this, we've disabled the append-timestamp option and appended a hash of php_version.h. Hence, we'll only get a new cache file once this file is touched. However, since this file rarely ever updates for master, we're relying on an extremely outdated cache. To fix this, append the current year+week to rebuild the cache each week instead, as suggested by Tim. Also use major.minor.release version instead of the has of php_version.h for readability. Fixes GH-14154 Closes GH-21258 --- .github/actions/ccache/action.yml | 19 ++++++++++++++++++- .github/workflows/test-suite.yml | 23 ++++++++++++++++++++--- .github/workflows/test.yml | 3 --- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/.github/actions/ccache/action.yml b/.github/actions/ccache/action.yml index fbd8691c927e2..4b06bc90871fa 100644 --- a/.github/actions/ccache/action.yml +++ b/.github/actions/ccache/action.yml @@ -5,9 +5,26 @@ inputs: runs: using: composite steps: + - name: Get cache key + shell: bash + id: cache_key + run: | + major=$(cat main/php_version.h | sed -En 's/^#define PHP_MAJOR_VERSION ([0-9]+)/\1/p') + minor=$(cat main/php_version.h | sed -En 's/^#define PHP_MINOR_VERSION ([0-9]+)/\1/p') + release=$(cat main/php_version.h | sed -En 's/^#define PHP_RELEASE_VERSION ([0-9]+)/\1/p') + week=$(date +"%Y-%W") + prefix="${{ inputs.name }}-$major.$minor.$release" + echo "key=$prefix-$week" >> $GITHUB_OUTPUT + echo "prefix=$prefix-" >> $GITHUB_OUTPUT - name: ccache uses: hendrikmuhs/ccache-action@v1.2 with: - key: "${{ inputs.name }}-${{ hashFiles('main/php_version.h') }}" + key: "${{ steps.cache_key.outputs.key }}" append-timestamp: false + restore-keys: "${{ steps.cache_key.outputs.prefix }}" save: ${{ github.event_name != 'pull_request' }} + - name: Export CC/CXX + shell: bash + run: | + echo "CC=ccache gcc" >> $GITHUB_ENV + echo "CXX=ccache g++" >> $GITHUB_ENV diff --git a/.github/workflows/test-suite.yml b/.github/workflows/test-suite.yml index 97d28253f546f..c206ba4220b41 100644 --- a/.github/workflows/test-suite.yml +++ b/.github/workflows/test-suite.yml @@ -72,6 +72,10 @@ jobs: echo "::group::Show installed package versions" apk list echo "::endgroup::" + - name: ccache + uses: ./.github/actions/ccache + with: + name: "${{ github.job }}" - name: ./configure uses: ./.github/actions/configure-alpine with: @@ -392,6 +396,10 @@ jobs: uses: ./.github/actions/apt-x64 - name: Install gcovr run: sudo -H pip install gcovr + - name: ccache + uses: ./.github/actions/ccache + with: + name: "${{ github.job }}" - name: ./configure uses: ./.github/actions/configure-x64 with: @@ -433,6 +441,10 @@ jobs: ref: ${{ fromJson(inputs.branch).ref }} - name: apt uses: ./.github/actions/apt-x64 + - name: ccache + uses: ./.github/actions/ccache + with: + name: "COMMUNITY_${{ matrix.type }}" - name: ./configure uses: ./.github/actions/configure-x64 with: @@ -635,6 +647,10 @@ jobs: uses: ./.github/actions/setup-mssql - name: apt uses: ./.github/actions/apt-x64 + - name: ccache + uses: ./.github/actions/ccache + with: + name: "${{ github.job }}" - name: ./configure uses: ./.github/actions/configure-x64 with: @@ -692,6 +708,10 @@ jobs: ref: ${{ fromJson(inputs.branch).ref }} - name: apt uses: ./.github/actions/apt-x64 + - name: ccache + uses: ./.github/actions/ccache + with: + name: "${{ github.job }}" - name: ./configure run: | export CC=clang @@ -806,9 +826,6 @@ jobs: PECL: if: ${{ fromJson(inputs.branch).jobs.PECL }} runs-on: ubuntu-24.04 - env: - CC: ccache gcc - CXX: ccache g++ steps: - name: git checkout PHP uses: actions/checkout@v6 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0970975df194f..b08d0031aa111 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,9 +29,6 @@ permissions: concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.url || github.run_id }} cancel-in-progress: true -env: - CC: ccache gcc - CXX: ccache g++ jobs: GENERATE_MATRIX: name: Generate Matrix