CI: Trim cache before saving

This commit is contained in:
Thaddeus Crews
2025-03-13 12:29:42 -05:00
parent 701505eb4f
commit de33bd2b7c
11 changed files with 71 additions and 63 deletions

View File

@@ -19,11 +19,6 @@ inputs:
scons-cache:
description: The SCons cache path.
default: ${{ github.workspace }}/.scons_cache/
scons-cache-limit:
description: The SCons cache size limit.
# actions/cache has 10 GiB limit, and GitHub runners have a 14 GiB disk.
# Limit to 7 GiB to avoid having the extracted cache fill the disk.
default: 7
runs:
using: composite
@@ -33,7 +28,7 @@ runs:
env:
SCONSFLAGS: ${{ inputs.sconsflags }}
run: |
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 }}
echo "Building with flags:" platform=${{ inputs.platform }} target=${{ inputs.target }} tests=${{ inputs.tests }} ${{ env.SCONSFLAGS }} "cache_path=${{ inputs.scons-cache }}"
if [ "${{ inputs.target }}" != "editor" ]; then
# Ensure we don't include editor code in export template builds.
@@ -47,5 +42,5 @@ runs:
export BUILD_NAME="gh"
fi
scons platform=${{ inputs.platform }} target=${{ inputs.target }} tests=${{ inputs.tests }} ${{ env.SCONSFLAGS }} "cache_path=${{ inputs.scons-cache }}" cache_limit=${{ inputs.scons-cache-limit }}
scons platform=${{ inputs.platform }} target=${{ inputs.target }} tests=${{ inputs.tests }} ${{ env.SCONSFLAGS }} "cache_path=${{ inputs.scons-cache }}"
ls -l bin/

View File

@@ -11,42 +11,29 @@ inputs:
runs:
using: composite
steps:
# Because all branches can refer to the repository's default branch's cache, we want it to
# persist as the de-facto fallback. However, it easily expunges in a matter of hours if
# nothing explicitly calls to it, so we work around that by ensuring it's *always* pinged
# prior to any cache operations.
- name: Ping main cache
- name: Restore default cache
uses: actions/cache/restore@v4
id: cache-ping
with:
path: ${{ inputs.scons-cache }}
key: ${{ github.sha }} # Dummy key; we have to rely on the fallback value.
key: ${{ inputs.cache-name }}|${{ github.event.repository.default_branch }}|${{ github.sha }}
restore-keys: ${{ inputs.cache-name }}|${{ github.event.repository.default_branch }}
lookup-only: true
# Fallback access isn't logged, so register an explicit cache-hit if found.
- name: Ping main cache (exact)
if: steps.cache-ping.outputs.cache-matched-key
uses: actions/cache/restore@v4
with:
path: ${{ inputs.scons-cache }}
key: ${{ steps.cache-ping.outputs.cache-matched-key }}
lookup-only: true
- name: Log default cache files
if: github.ref_name != github.event.repository.default_branch
shell: sh
run: find "${{ inputs.scons-cache }}" >> redundant.txt
# We try to match an existing cache to restore from it. Each potential key is checked against
# all existing caches as a prefix. E.g. 'linux-template-minimal' would match any cache that
# starts with "linux-template-minimal", such as
# "linux-template-minimal|master|6588a4a29af1621086feac0117d5d4d37af957fd".
#
# We check these prefixes in this order:
# 1. An exact match for the base branch, reference name, and SHA hash.
# 2. A partial match for the same cache name and reference name.
# 3. A partial match for the same cache name and default branch name.
- name: Restore SCons cache directory
# This is done after pulling the default cache so that PRs can integrate any potential changes
# from the default branch without conflicting with whatever local changes were already made.
- name: Restore local cache
uses: actions/cache/restore@v4
if: github.ref_name != github.event.repository.default_branch
with:
path: ${{ inputs.scons-cache }}
key: ${{ inputs.cache-name }}|${{ github.ref_name }}|${{ github.sha }}
restore-keys: |
${{ inputs.cache-name }}|${{ github.ref_name }}
${{ inputs.cache-name }}|${{ github.event.repository.default_branch }}
restore-keys: ${{ inputs.cache-name }}|${{ github.ref_name }}
- name: Store unix timestamp
shell: sh
run: echo "CACHE_TIMESTAMP=$(date +%s)" >> $GITHUB_ENV

View File

@@ -11,6 +11,10 @@ inputs:
runs:
using: composite
steps:
- name: Purge files before timestamp
shell: sh
run: misc/scripts/purge_cache.py ${{ env.CACHE_TIMESTAMP }} "${{ inputs.scons-cache }}"
- name: Save SCons cache directory
uses: actions/cache/save@v4
with: