Replace actions/cache@v5 with local implementation, simplify key inputs
- Remove actions/cache@v5 dependency, implement cache API calls directly using curl, tar, and zstd against Gitea's /_apis/artifactcache/ API - Drop 'key' input, add required 'key-prefix' and 'key-file' inputs - Cache key is generated as key-prefix-<sha256-of-key-file> - Update README with revised inputs and Rust-only examples
This commit is contained in:
@@ -1,40 +1,27 @@
|
||||
Cache Action
|
||||
============
|
||||
|
||||
A Gitea Action that caches build files under `~/.cache/` using a key file hash. This action uses `actions/cache@v5` under the hood and automatically saves the cache when the job completes successfully.
|
||||
A Gitea Action that caches build files under `~/.cache/` using a key file hash. Implements the Gitea artifact cache API directly with curl, tar, and zstd — no external actions required.
|
||||
|
||||
## Inputs
|
||||
|
||||
| Input | Description | Required | Default |
|
||||
|-------|-------------|----------|---------|
|
||||
| `path` | Files/directories to cache | No | `~/.cache/` |
|
||||
| `key` | Explicit cache key | No | Auto-generated from hash |
|
||||
| `key-file` | File to hash for cache key generation | No | Auto-detects lockfiles |
|
||||
| `restore-keys` | Fallback prefix-matched keys | No | `{os}-cache-` |
|
||||
| `key-prefix` | Prefix for the cache key | Yes | — |
|
||||
| `key-file` | File to hash for the cache key | Yes | — |
|
||||
| `restore-keys` | Fallback prefix-matched keys | No | — |
|
||||
|
||||
## Outputs
|
||||
|
||||
| Output | Description |
|
||||
|--------|-------------|
|
||||
| `cache-hit` | `true` if exact key match found, `false` otherwise |
|
||||
| `cache-primary-key` | The primary key used for cache lookup |
|
||||
| `cache-matched-key` | The key of the cache entry that was restored |
|
||||
|
||||
## Quick Start
|
||||
|
||||
### Basic Usage
|
||||
|
||||
```yaml
|
||||
name: Build with Cache
|
||||
on: push
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: Actions/Cache@main
|
||||
- run: echo "Cache restored, proceeding with build..."
|
||||
```
|
||||
|
||||
### Rust Example
|
||||
|
||||
```yaml
|
||||
@@ -52,6 +39,7 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: Actions/Cache@main
|
||||
with:
|
||||
key-prefix: 'rust'
|
||||
key-file: 'Cargo.lock'
|
||||
path: |
|
||||
~/.cache/
|
||||
@@ -77,6 +65,7 @@ jobs:
|
||||
- uses: Actions/Cache@main
|
||||
id: cache
|
||||
with:
|
||||
key-prefix: 'rust'
|
||||
key-file: 'Cargo.lock'
|
||||
- name: Install dependencies
|
||||
if: steps.cache.outputs.cache-hit != 'true'
|
||||
@@ -87,14 +76,11 @@ jobs:
|
||||
|
||||
## How It Works
|
||||
|
||||
1. **Cache Key Generation**: If no explicit `key` is provided, the action auto-generates one by:
|
||||
- Hashing the specified `key-file` if provided
|
||||
- Otherwise, hashing all detected lockfiles (package-lock.json, Cargo.lock, go.mod, etc.)
|
||||
- Falls back to hashing all non-git files if no lockfiles found
|
||||
1. **Cache Key Generation**: Combines `key-prefix` with the SHA-256 hash of `key-file` (e.g. `rust-<hash>`).
|
||||
|
||||
2. **Cache Restore**: Uses `actions/cache@v5` to restore the cache from `~/.cache/`
|
||||
2. **Cache Restore**: Calls the Gitea artifact cache API (`/_apis/artifactcache/cache`) to find a matching entry, downloads the archive, and extracts it.
|
||||
|
||||
3. **Cache Save**: Automatically saves the cache when the job completes successfully (handled by `actions/cache@v5`)
|
||||
3. **Cache Save**: Runs on job completion (`if: always()`), creates a zstd-compressed tar archive, reserves a cache entry via the API, uploads it, and commits it. Skipped if there was a cache hit on the primary key.
|
||||
|
||||
## Cache Scope
|
||||
|
||||
@@ -102,6 +88,6 @@ The cache is scoped to the key, version, and branch. The default branch cache is
|
||||
|
||||
## Remarks
|
||||
|
||||
- Requires Gitea Actions runner version >= 2.327.1 for `actions/cache@v5`
|
||||
- The cache server must be enabled on your Gitea instance
|
||||
- Requires `curl`, `tar`, and `sha256sum` on the runner (zstd is optional, falls back to gzip)
|
||||
- Maximum cache size per repository is 10GB
|
||||
|
||||
Reference in New Issue
Block a user