Skip to content

Commit 7a4da10

Browse files
committed
[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
1 parent 636fd34 commit 7a4da10

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

.github/actions/ccache/action.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,26 @@ inputs:
55
runs:
66
using: composite
77
steps:
8+
- name: Get cache key
9+
shell: bash
10+
id: cache_key
11+
run: |
12+
major=$(cat main/php_version.h | sed -En 's/^#define PHP_MAJOR_VERSION ([0-9]+)/\1/p')
13+
minor=$(cat main/php_version.h | sed -En 's/^#define PHP_MINOR_VERSION ([0-9]+)/\1/p')
14+
release=$(cat main/php_version.h | sed -En 's/^#define PHP_RELEASE_VERSION ([0-9]+)/\1/p')
15+
week=$(date +"%Y-%W")
16+
prefix="${{ inputs.name }}-$major.$minor.$release"
17+
echo "key=$prefix-$week" >> $GITHUB_OUTPUT
18+
echo "prefix=$prefix-" >> $GITHUB_OUTPUT
819
- name: ccache
920
uses: hendrikmuhs/ccache-action@v1.2
1021
with:
11-
key: "${{ inputs.name }}-${{ hashFiles('main/php_version.h') }}"
22+
key: "${{ steps.cache_key.outputs.key }}"
1223
append-timestamp: false
24+
restore-keys: "${{ steps.cache_key.outputs.prefix }}"
1325
save: ${{ github.event_name != 'pull_request' }}
26+
- name: Export CC/CXX
27+
shell: bash
28+
run: |
29+
echo "CC=ccache gcc" >> $GITHUB_ENV
30+
echo "CXX=ccache g++" >> $GITHUB_ENV

.github/workflows/test-suite.yml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ jobs:
7272
echo "::group::Show installed package versions"
7373
apk list
7474
echo "::endgroup::"
75+
- name: ccache
76+
uses: ./.github/actions/ccache
77+
with:
78+
name: "${{ github.job }}"
7579
- name: ./configure
7680
uses: ./.github/actions/configure-alpine
7781
with:
@@ -392,6 +396,10 @@ jobs:
392396
uses: ./.github/actions/apt-x64
393397
- name: Install gcovr
394398
run: sudo -H pip install gcovr
399+
- name: ccache
400+
uses: ./.github/actions/ccache
401+
with:
402+
name: "${{ github.job }}"
395403
- name: ./configure
396404
uses: ./.github/actions/configure-x64
397405
with:
@@ -433,6 +441,10 @@ jobs:
433441
ref: ${{ fromJson(inputs.branch).ref }}
434442
- name: apt
435443
uses: ./.github/actions/apt-x64
444+
- name: ccache
445+
uses: ./.github/actions/ccache
446+
with:
447+
name: "COMMUNITY_${{ matrix.type }}"
436448
- name: ./configure
437449
uses: ./.github/actions/configure-x64
438450
with:
@@ -635,6 +647,10 @@ jobs:
635647
uses: ./.github/actions/setup-mssql
636648
- name: apt
637649
uses: ./.github/actions/apt-x64
650+
- name: ccache
651+
uses: ./.github/actions/ccache
652+
with:
653+
name: "${{ github.job }}"
638654
- name: ./configure
639655
uses: ./.github/actions/configure-x64
640656
with:
@@ -692,6 +708,10 @@ jobs:
692708
ref: ${{ fromJson(inputs.branch).ref }}
693709
- name: apt
694710
uses: ./.github/actions/apt-x64
711+
- name: ccache
712+
uses: ./.github/actions/ccache
713+
with:
714+
name: "${{ github.job }}"
695715
- name: ./configure
696716
run: |
697717
export CC=clang
@@ -806,9 +826,6 @@ jobs:
806826
PECL:
807827
if: ${{ fromJson(inputs.branch).jobs.PECL }}
808828
runs-on: ubuntu-24.04
809-
env:
810-
CC: ccache gcc
811-
CXX: ccache g++
812829
steps:
813830
- name: git checkout PHP
814831
uses: actions/checkout@v6

.github/workflows/test.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ permissions:
2929
concurrency:
3030
group: ${{ github.workflow }}-${{ github.event.pull_request.url || github.run_id }}
3131
cancel-in-progress: true
32-
env:
33-
CC: ccache gcc
34-
CXX: ccache g++
3532
jobs:
3633
GENERATE_MATRIX:
3734
name: Generate Matrix

0 commit comments

Comments
 (0)