Skip to content

Commit de33bd2

Browse files
committed
CI: Trim cache before saving
1 parent 701505e commit de33bd2

File tree

11 files changed

+71
-63
lines changed

11 files changed

+71
-63
lines changed

.github/actions/godot-build/action.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ inputs:
1919
scons-cache:
2020
description: The SCons cache path.
2121
default: ${{ github.workspace }}/.scons_cache/
22-
scons-cache-limit:
23-
description: The SCons cache size limit.
24-
# actions/cache has 10 GiB limit, and GitHub runners have a 14 GiB disk.
25-
# Limit to 7 GiB to avoid having the extracted cache fill the disk.
26-
default: 7
2722

2823
runs:
2924
using: composite
@@ -33,7 +28,7 @@ runs:
3328
env:
3429
SCONSFLAGS: ${{ inputs.sconsflags }}
3530
run: |
36-
echo "Building with flags:" platform=${{ inputs.platform }} target=${{ inputs.target }} tests=${{ inputs.tests }} ${{ env.SCONSFLAGS }} "cache_path=${{ inputs.scons-cache }}" cache_limit=${{ inputs.scons-cache-limit }}
31+
echo "Building with flags:" platform=${{ inputs.platform }} target=${{ inputs.target }} tests=${{ inputs.tests }} ${{ env.SCONSFLAGS }} "cache_path=${{ inputs.scons-cache }}"
3732
3833
if [ "${{ inputs.target }}" != "editor" ]; then
3934
# Ensure we don't include editor code in export template builds.
@@ -47,5 +42,5 @@ runs:
4742
export BUILD_NAME="gh"
4843
fi
4944
50-
scons platform=${{ inputs.platform }} target=${{ inputs.target }} tests=${{ inputs.tests }} ${{ env.SCONSFLAGS }} "cache_path=${{ inputs.scons-cache }}" cache_limit=${{ inputs.scons-cache-limit }}
45+
scons platform=${{ inputs.platform }} target=${{ inputs.target }} tests=${{ inputs.tests }} ${{ env.SCONSFLAGS }} "cache_path=${{ inputs.scons-cache }}"
5146
ls -l bin/

.github/actions/godot-cache-restore/action.yml

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,42 +11,29 @@ inputs:
1111
runs:
1212
using: composite
1313
steps:
14-
# Because all branches can refer to the repository's default branch's cache, we want it to
15-
# persist as the de-facto fallback. However, it easily expunges in a matter of hours if
16-
# nothing explicitly calls to it, so we work around that by ensuring it's *always* pinged
17-
# prior to any cache operations.
18-
- name: Ping main cache
14+
- name: Restore default cache
1915
uses: actions/cache/restore@v4
2016
id: cache-ping
2117
with:
2218
path: ${{ inputs.scons-cache }}
23-
key: ${{ github.sha }} # Dummy key; we have to rely on the fallback value.
19+
key: ${{ inputs.cache-name }}|${{ github.event.repository.default_branch }}|${{ github.sha }}
2420
restore-keys: ${{ inputs.cache-name }}|${{ github.event.repository.default_branch }}
25-
lookup-only: true
2621

27-
# Fallback access isn't logged, so register an explicit cache-hit if found.
28-
- name: Ping main cache (exact)
29-
if: steps.cache-ping.outputs.cache-matched-key
30-
uses: actions/cache/restore@v4
31-
with:
32-
path: ${{ inputs.scons-cache }}
33-
key: ${{ steps.cache-ping.outputs.cache-matched-key }}
34-
lookup-only: true
22+
- name: Log default cache files
23+
if: github.ref_name != github.event.repository.default_branch
24+
shell: sh
25+
run: find "${{ inputs.scons-cache }}" >> redundant.txt
3526

36-
# We try to match an existing cache to restore from it. Each potential key is checked against
37-
# all existing caches as a prefix. E.g. 'linux-template-minimal' would match any cache that
38-
# starts with "linux-template-minimal", such as
39-
# "linux-template-minimal|master|6588a4a29af1621086feac0117d5d4d37af957fd".
40-
#
41-
# We check these prefixes in this order:
42-
# 1. An exact match for the base branch, reference name, and SHA hash.
43-
# 2. A partial match for the same cache name and reference name.
44-
# 3. A partial match for the same cache name and default branch name.
45-
- name: Restore SCons cache directory
27+
# This is done after pulling the default cache so that PRs can integrate any potential changes
28+
# from the default branch without conflicting with whatever local changes were already made.
29+
- name: Restore local cache
4630
uses: actions/cache/restore@v4
31+
if: github.ref_name != github.event.repository.default_branch
4732
with:
4833
path: ${{ inputs.scons-cache }}
4934
key: ${{ inputs.cache-name }}|${{ github.ref_name }}|${{ github.sha }}
50-
restore-keys: |
51-
${{ inputs.cache-name }}|${{ github.ref_name }}
52-
${{ inputs.cache-name }}|${{ github.event.repository.default_branch }}
35+
restore-keys: ${{ inputs.cache-name }}|${{ github.ref_name }}
36+
37+
- name: Store unix timestamp
38+
shell: sh
39+
run: echo "CACHE_TIMESTAMP=$(date +%s)" >> $GITHUB_ENV

.github/actions/godot-cache-save/action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ inputs:
1111
runs:
1212
using: composite
1313
steps:
14+
- name: Purge files before timestamp
15+
shell: sh
16+
run: misc/scripts/purge_cache.py ${{ env.CACHE_TIMESTAMP }} "${{ inputs.scons-cache }}"
17+
1418
- name: Save SCons cache directory
1519
uses: actions/cache/save@v4
1620
with:

.github/workflows/android_builds.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,18 @@ jobs:
2020
target: editor
2121
tests: false
2222
sconsflags: arch=arm64 production=yes swappy=yes
23-
cache-limit: 1
2423

2524
- name: Template arm32 (target=template_release, arch=arm32)
2625
cache-name: android-template-arm32
2726
target: template_release
2827
tests: false
2928
sconsflags: arch=arm32 swappy=yes
30-
cache-limit: 1
3129

3230
- name: Template arm64 (target=template_release, arch=arm64)
3331
cache-name: android-template-arm64
3432
target: template_release
3533
tests: false
3634
sconsflags: arch=arm64 swappy=yes
37-
cache-limit: 1
3835

3936
steps:
4037
- name: Checkout
@@ -75,7 +72,6 @@ jobs:
7572
platform: android
7673
target: ${{ matrix.target }}
7774
tests: ${{ matrix.tests }}
78-
scons-cache-limit: ${{ matrix.cache-limit }}
7975

8076
- name: Save Godot build cache
8177
uses: ./.github/actions/godot-cache-save

.github/workflows/ios_builds.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ jobs:
3232
platform: ios
3333
target: template_release
3434
tests: false
35-
scons-cache-limit: 1
3635

3736
- name: Save Godot build cache
3837
uses: ./.github/actions/godot-cache-save

.github/workflows/linux_builds.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ jobs:
3434
artifact: true
3535
# Validate godot-cpp compatibility on one arbitrary editor build.
3636
godot-cpp: true
37-
cache-limit: 2
3837

3938
- name: Editor with doubles and GCC sanitizers (target=editor, tests=yes, dev_build=yes, scu_build=yes, precision=double, use_asan=yes, use_ubsan=yes, linker=gold)
4039
cache-name: linux-editor-double-sanitizers
@@ -47,7 +46,6 @@ jobs:
4746
proj-test: true
4847
# Skip 2GiB artifact speeding up action.
4948
artifact: false
50-
cache-limit: 7
5149

5250
- name: Editor with clang sanitizers (target=editor, tests=yes, dev_build=yes, use_asan=yes, use_ubsan=yes, use_llvm=yes, linker=lld)
5351
cache-name: linux-editor-llvm-sanitizers
@@ -60,7 +58,6 @@ jobs:
6058
artifact: false
6159
# Test our oldest supported SCons/Python versions on one arbitrary editor build.
6260
legacy-scons: true
63-
cache-limit: 7
6461

6562
- name: Editor with ThreadSanitizer (target=editor, tests=yes, dev_build=yes, use_tsan=yes, use_llvm=yes, linker=lld)
6663
cache-name: linux-editor-thread-sanitizer
@@ -71,7 +68,6 @@ jobs:
7168
build-mono: false
7269
# Skip 2GiB artifact speeding up action.
7370
artifact: false
74-
cache-limit: 5
7571

7672
- name: Template w/ Mono, release (target=template_release, tests=yes)
7773
cache-name: linux-template-mono
@@ -81,7 +77,6 @@ jobs:
8177
build-mono: false
8278
tests: true
8379
artifact: true
84-
cache-limit: 1
8580

8681
- name: Template w/ Mono, debug (target=template_debug, tests=yes)
8782
cache-name: linux-template-mono-debug
@@ -91,7 +86,6 @@ jobs:
9186
build-mono: false
9287
tests: true
9388
artifact: true
94-
cache-limit: 1
9589

9690
- name: Minimal template (target=template_release, tests=yes, everything disabled)
9791
cache-name: linux-template-minimal
@@ -100,7 +94,6 @@ jobs:
10094
bin: ./bin/godot.linuxbsd.template_release.x86_64
10195
tests: true
10296
artifact: true
103-
cache-limit: 1
10497

10598
steps:
10699
- name: Checkout
@@ -165,7 +158,6 @@ jobs:
165158
platform: linuxbsd
166159
target: ${{ matrix.target }}
167160
tests: ${{ matrix.tests }}
168-
scons-cache-limit: ${{ matrix.cache-limit }}
169161

170162
- name: Compilation (godot-cpp)
171163
uses: ./.github/actions/godot-cpp-build

.github/workflows/macos_builds.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@ jobs:
2020
target: editor
2121
tests: true
2222
bin: ./bin/godot.macos.editor.universal
23-
cache-limit: 1
2423

2524
- name: Template (target=template_release, tests=yes)
2625
cache-name: macos-template
2726
target: template_release
2827
tests: true
2928
sconsflags: debug_symbols=no
3029
bin: ./bin/godot.macos.template_release.universal
31-
cache-limit: 1
3230

3331
steps:
3432
- name: Checkout
@@ -56,7 +54,6 @@ jobs:
5654
platform: macos
5755
target: ${{ matrix.target }}
5856
tests: ${{ matrix.tests }}
59-
scons-cache-limit: 0 # Only cap on second run to avoid purging unnecessarily
6057

6158
- name: Compilation (arm64)
6259
uses: ./.github/actions/godot-build
@@ -65,7 +62,6 @@ jobs:
6562
platform: macos
6663
target: ${{ matrix.target }}
6764
tests: ${{ matrix.tests }}
68-
scons-cache-limit: ${{ matrix.cache-limit }}
6965

7066
- name: Save Godot build cache
7167
uses: ./.github/actions/godot-cache-save

.github/workflows/web_builds.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ jobs:
6262
platform: web
6363
target: ${{ matrix.target }}
6464
tests: ${{ matrix.tests }}
65-
scons-cache-limit: 0.5
6665

6766
- name: Save Godot build cache
6867
uses: ./.github/actions/godot-cache-save

.github/workflows/windows_builds.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ jobs:
2626
sconsflags: debug_symbols=no vsproj=yes vsproj_gen_only=no windows_subsystem=console
2727
bin: ./bin/godot.windows.editor.x86_64.exe
2828
compiler: msvc
29-
cache-limit: 2
3029

3130
- name: Editor w/ clang-cl (target=editor, tests=yes, use_llvm=yes)
3231
cache-name: windows-editor-clang
@@ -35,7 +34,6 @@ jobs:
3534
sconsflags: debug_symbols=no windows_subsystem=console use_llvm=yes
3635
bin: ./bin/godot.windows.editor.x86_64.llvm.exe
3736
compiler: clang
38-
cache-limit: 1
3937

4038
- name: Template (target=template_release, tests=yes)
4139
cache-name: windows-template
@@ -44,7 +42,6 @@ jobs:
4442
sconsflags: debug_symbols=no
4543
bin: ./bin/godot.windows.template_release.x86_64.console.exe
4644
compiler: msvc
47-
cache-limit: 2
4845

4946
- name: Template w/ GCC (target=template_release, tests=yes, use_mingw=yes)
5047
cache-name: windows-template-gcc
@@ -54,7 +51,6 @@ jobs:
5451
sconsflags: debug_symbols=no use_mingw=yes
5552
bin: ./bin/godot.windows.template_release.x86_64.console.exe
5653
compiler: gcc
57-
cache-limit: 1
5854

5955
steps:
6056
- name: Checkout
@@ -92,7 +88,6 @@ jobs:
9288
platform: windows
9389
target: ${{ matrix.target }}
9490
tests: ${{ matrix.tests }}
95-
scons-cache-limit: ${{ matrix.cache-limit }}
9691

9792
- name: Save Godot build cache
9893
uses: ./.github/actions/godot-cache-save

methods.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -897,11 +897,9 @@ def prepare_cache(env) -> None:
897897
# Convert GiB to bytes; treat negative numbers as 0 (unlimited).
898898
cache_limit = max(0, int(cache_limit * 1024 * 1024 * 1024))
899899
if env["verbose"]:
900-
print(
901-
"Current cache limit is {} (used: {})".format(
902-
convert_size(cache_limit) if cache_limit else "∞",
903-
convert_size(get_size(cache_path)),
904-
)
900+
print_info(
901+
f"Current cache size is {convert_size(get_size(cache_path))}"
902+
+ (f" (limit: {convert_size(cache_limit)})" if cache_limit else "")
905903
)
906904

907905
atexit.register(clean_cache, cache_path, cache_limit, env["verbose"])

0 commit comments

Comments
 (0)