Record last use by touching the archive so the retention policy can expire by access time, and run prune.sh after every restore (even on miss) to keep the shared store trimmed: keep the 3 newest archives per key-prefix family, expire anything older than 7 days, hard-cap the store at 2 GB (oldest first, trumping the keep set), never touch files younger than 1h, and drop stale run workspaces under ~/.cache/act older than 2 days.
3.2 KiB
3.2 KiB
Cache Action
A Gitea Action that caches build files as tar.xz archives on the runner filesystem. Simple, fast, no external dependencies.
Inputs
| Input | Description | Required | Default |
|---|---|---|---|
path |
Single directory to cache | No | ~/.cache/ |
key-prefix |
Prefix for the cache key | Yes | — |
key-file |
File to hash (SHA-256) for the cache key | Yes | — |
Outputs
| Output | Description |
|---|---|
cache-hit |
true if exact key match found, false otherwise |
How It Works
- Hashes
key-filewith SHA-256, combines withkey-prefixas<prefix>-<hash> - Stores archives at
~/.cache/.cache-store/<key>.tar.xz - Restores by extracting the archive to
/, saves by creating one - Touches the archive on every hit, so the retention policy can expire by last use
Cache Retention
Archives are content-addressed, so old keys are never needed again — the store is pruned automatically on every restore/save (best-effort, safe under concurrent runners):
- The newest
CACHE_KEEP_N(default3) archives per key-prefix family are always kept, so reverting e.g.Cargo.lockstill hits an older key - Anything older than
CACHE_TTL_DAYS(default7) outside the keep set is deleted - A hard size cap
CACHE_CAP_GB(default2) deletes oldest-first when exceeded - Files younger than 1 hour are never touched (in-flight save protection)
- Stale run workspaces under
~/.cache/act/*/hostexecutorolder thanCACHE_WORKSPACE_TTL_DAYS(default2) are removed
Override the defaults per-job via env: (e.g. env: { CACHE_KEEP_N: 5 }).
Usage
This action must be used twice in your workflow:
- Before build — restores cache if it exists
- After build — saves the cache archive (only on cache miss)
Rust Example
name: Rust Build
on: push
defaults:
run:
shell: bash
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# 1. Restore cache before build
- uses: Actions/Cache@main
id: cache
with:
key-prefix: 'cargo-registry'
key-file: 'Cargo.lock'
path: '~/.cargo/registry'
- name: Build
run: cargo build --release
# 2. Save cache after build
- uses: Actions/Cache@main
with:
key-prefix: 'cargo-registry'
key-file: 'Cargo.lock'
path: '~/.cargo/registry'
Skip Steps on Cache Hit
name: Build with Conditional Steps
on: push
defaults:
run:
shell: bash
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# 1. Restore cache
- uses: Actions/Cache@main
id: cache
with:
key-prefix: 'rust'
key-file: 'Cargo.lock'
path: '~/.cargo/registry'
- name: Fetch dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: cargo fetch
- name: Build
run: cargo build --release
# 2. Save cache
- uses: Actions/Cache@main
with:
key-prefix: 'rust'
key-file: 'Cargo.lock'
path: '~/.cargo/registry'