Skip to content

Cache Management

Cache Management #8

Workflow file for this run

name: Cache Warmup
on:
schedule:
- cron: '0 0 */3 * *'
workflow_dispatch:
jobs:
cleanup-cache:
runs-on: ubuntu-latest
permissions:
actions: write
steps:
- name: Cleanup old caches
uses: actions/github-script@v7
with:
script: |
const retentionDays = 2; // Keep caches for 2 days
const caches = await github.rest.actions.getActionsCacheList({
owner: context.repo.owner,
repo: context.repo.repo
});
// Group caches by their prefix pattern (e.g., sccache-Windows-cuda-main)
const cacheGroups = {};
for (const cache of caches.data.actions_caches) {
if (cache.key.startsWith('sccache-')) {
// Extract the prefix pattern (everything before the last hyphen + timestamp)
const prefixPattern = cache.key.replace(/-\d+$/, '');
if (!cacheGroups[prefixPattern]) {
cacheGroups[prefixPattern] = [];
}
cacheGroups[prefixPattern].push(cache);
}
}
const now = new Date();
// Process each group of caches
for (const prefix in cacheGroups) {
// Sort caches by creation date (newest first)
const sortedCaches = cacheGroups[prefix].sort((a, b) =>
new Date(b.created_at) - new Date(a.created_at));
// Skip the most recent cache
for (let i = 1; i < sortedCaches.length; i++) {
const cache = sortedCaches[i];
const createdAt = new Date(cache.created_at);
const ageInDays = (now - createdAt) / (1000 * 60 * 60 * 24);
if (ageInDays > retentionDays) {
console.log(`Deleting old cache: ${cache.key}, created ${ageInDays.toFixed(1)} days ago`);
await github.rest.actions.deleteActionsCacheByKey({
owner: context.repo.owner,
repo: context.repo.repo,
key: cache.key
});
} else {
console.log(`Keeping cache: ${cache.key}, created ${ageInDays.toFixed(1)} days ago`);
}
}
// Always log the kept most recent cache
if (sortedCaches.length > 0) {
const newestCache = sortedCaches[0];
const createdAt = new Date(newestCache.created_at);
const ageInDays = (now - createdAt) / (1000 * 60 * 60 * 24);
console.log(`Keeping most recent cache: ${newestCache.key}, created ${ageInDays.toFixed(1)} days ago`);
}
}
warmup-unix:
needs: cleanup-cache
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-22.04, macos-15]
device: [cpu, metal, cuda]
exclude:
- os: macos-15
device: cpu
- os: macos-15
device: cuda
# TODO: Remove on release
- os: macos-15
device: metal
- os: ubuntu-22.04
device: metal
container: ${{ matrix.device == 'cuda' && 'nvidia/cuda:12.8.0-devel-ubuntu22.04' || '' }}
steps:
- uses: actions/checkout@v4
- name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.7
- name: Configure sccache
id: sccache
run: |
mkdir -p "$PWD/bindings/.sccache"
export SCCACHE_DIR="$PWD/bindings/.sccache"
echo "SCCACHE_DIR=$SCCACHE_DIR" >> $GITHUB_ENV
- name: Cache sccache storage
uses: actions/cache@v4
with:
path: ${{ env.SCCACHE_DIR }}
key: sccache-${{ runner.os }}-${{ matrix.device }}-${{ github.ref_name }}-${{ github.run_id }}
restore-keys: |
sccache-${{ runner.os }}-${{ matrix.device }}-${{ github.ref_name }}-
sccache-${{ runner.os }}-${{ matrix.device }}-
warmup-win:
needs: cleanup-cache
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-2022]
device: [cpu, cuda]
steps:
- uses: actions/checkout@v4
- name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.7
- name: Configure sccache
run: |
New-Item -ItemType Directory -Force -Path "$PWD/bindings/.sccache"
$env:SCCACHE_DIR="$PWD/bindings/.sccache"
echo "SCCACHE_DIR=$env:SCCACHE_DIR" >> $env:GITHUB_ENV
- name: Cache sccache storage
uses: actions/cache@v4
with:
path: ${{ env.SCCACHE_DIR }}
key: sccache-${{ runner.os }}-${{ matrix.device }}-${{ github.ref_name }}-${{ github.run_id }}
restore-keys: |
sccache-${{ runner.os }}-${{ matrix.device }}-${{ github.ref_name }}-
sccache-${{ runner.os }}-${{ matrix.device }}-