Skip to content

Warm caches

Warm caches #14

Workflow file for this run

# Warms the llama.cpp build cache FROM THE DEFAULT BRANCH so release runs can
# actually hit it.
#
# Why this exists: GitHub Actions cache scoping — a cache is only visible to
# runs on the same ref or on the default branch. Release runs each execute on
# their own tag ref (v1.0.4+159, v1.0.5+160, …), so a cache saved by one tag's
# run is INVISIBLE to every later tag: the release workflow's own save can
# never help a future release. Saving the identical key from a main-branch run
# makes it visible to all refs, cutting the release's ~40-65 min llama compile
# to seconds.
#
# Triggers: any main push that changes the llama pin or its build flags, a
# weekly refresh (caches are evicted after 7 days unused), and manual dispatch.
name: Warm caches
on:
push:
branches: [main]
paths:
- "third_party/llama.cpp"
- "scripts/build-llama.sh"
- ".github/workflows/warm-caches.yml"
schedule:
- cron: "0 5 * * 1,4" # Mon+Thu 05:00 UTC — keeps the cache from aging out
workflow_dispatch:
permissions:
contents: read
jobs:
llama-cache:
name: warm llama.cpp build cache
runs-on: macos-14
timeout-minutes: 90
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Select Xcode
uses: maxim-lobanov/setup-xcode@60606e260d2fc5762a71e64e74b2174e8ea3c8bd # v1.6.0
with:
xcode-version: latest-stable
- name: Compute llama.cpp cache key
id: llama-key
run: echo "sha=$(git submodule status third_party/llama.cpp | awk '{print $1}' | tr -d '+-')" >> "$GITHUB_OUTPUT"
# ccache is the cache that actually works across runs: the build-dir cache
# restores object files, but a fresh checkout gives sources NEWER mtimes,
# so make recompiles everything anyway (observed in v1.0.6: 60min llama
# build on a successful build-dir restore). ccache hashes content, so the
# recompiles become sub-second lookups. This job ALWAYS builds (cheap once
# ccache is warm) so the main-ref ccache stays fresh for tag runs, which
# can't see caches saved by other tags.
- name: Install ccache
run: brew install ccache 2>/dev/null || true
- name: Restore ccache
uses: actions/cache/restore@v4
with:
path: ~/Library/Caches/ccache
key: ccache-${{ runner.os }}-${{ steps.llama-key.outputs.sha }}
restore-keys: |
ccache-${{ runner.os }}-
# Key MUST stay identical to release.yml's — that's the whole point.
- name: Restore llama.cpp build cache
id: llama-cache
uses: actions/cache/restore@v4
with:
path: third_party/llama.cpp/build
key: llama-build-${{ runner.os }}-${{ steps.llama-key.outputs.sha }}-${{ hashFiles('scripts/build-llama.sh') }}
- name: Build llama.cpp (submodule)
run: ./scripts/build-llama.sh
- name: Save llama.cpp build cache
if: steps.llama-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: third_party/llama.cpp/build
key: llama-build-${{ runner.os }}-${{ steps.llama-key.outputs.sha }}-${{ hashFiles('scripts/build-llama.sh') }}
- name: Save ccache
uses: actions/cache/save@v4
with:
path: ~/Library/Caches/ccache
key: ccache-${{ runner.os }}-${{ steps.llama-key.outputs.sha }}-${{ github.run_id }}
- name: Report ccache stats
run: ccache -s || true