Update README with two-step usage pattern (restore before build, save after)
This commit is contained in:
@@ -23,6 +23,13 @@ A Gitea Action that caches build files as `tar.xz` archives on the runner filesy
|
|||||||
2. Stores archives at `~/.cache/.cache-store/<key>.tar.xz`
|
2. Stores archives at `~/.cache/.cache-store/<key>.tar.xz`
|
||||||
3. Restores by extracting the archive to `/`, saves by creating one
|
3. Restores by extracting the archive to `/`, saves by creating one
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
This action must be used **twice** in your workflow:
|
||||||
|
|
||||||
|
1. **Before build** — restores cache if it exists
|
||||||
|
2. **After build** — saves the cache archive (only on cache miss)
|
||||||
|
|
||||||
## Rust Example
|
## Rust Example
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
@@ -38,13 +45,24 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- 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
|
- uses: Actions/Cache@main
|
||||||
with:
|
with:
|
||||||
key-prefix: 'cargo-registry'
|
key-prefix: 'cargo-registry'
|
||||||
key-file: 'Cargo.lock'
|
key-file: 'Cargo.lock'
|
||||||
path: '~/.cargo/registry'
|
path: '~/.cargo/registry'
|
||||||
- name: Build
|
|
||||||
run: cargo build --release
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Skip Steps on Cache Hit
|
## Skip Steps on Cache Hit
|
||||||
@@ -62,15 +80,26 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
# 1. Restore cache
|
||||||
- uses: Actions/Cache@main
|
- uses: Actions/Cache@main
|
||||||
id: cache
|
id: cache
|
||||||
with:
|
with:
|
||||||
key-prefix: 'rust'
|
key-prefix: 'rust'
|
||||||
key-file: 'Cargo.lock'
|
key-file: 'Cargo.lock'
|
||||||
path: '~/.cargo/registry'
|
path: '~/.cargo/registry'
|
||||||
|
|
||||||
- name: Fetch dependencies
|
- name: Fetch dependencies
|
||||||
if: steps.cache.outputs.cache-hit != 'true'
|
if: steps.cache.outputs.cache-hit != 'true'
|
||||||
run: cargo fetch
|
run: cargo fetch
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: cargo build --release
|
run: cargo build --release
|
||||||
|
|
||||||
|
# 2. Save cache
|
||||||
|
- uses: Actions/Cache@main
|
||||||
|
with:
|
||||||
|
key-prefix: 'rust'
|
||||||
|
key-file: 'Cargo.lock'
|
||||||
|
path: '~/.cargo/registry'
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user