cache/README.md

57 lines
1.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 缓存插件
这是一个Gitea Actions缓存插件用于在CI/CD流程中缓存指定目录以提高构建效率减少重复下载和计算时间。
## 功能特点
- 支持多目录缓存
- 基于文件哈希自动更新缓存
- 支持不同操作系统环境
- 提供缓存命中状态输出
## 输入参数
| 参数名 | 必需 | 描述 | 默认值 |
|-------|------|------|-------|
| key | 是 | 缓存压缩标识 | `${{ gitea.repository }}` |
| mount | 是 | 挂载缓存目录(支持多行输入) | - |
| hash_files | 否 | 缓存命中文件(支持多行输入,用于生成哈希) | - |
## 输出参数
| 参数名 | 描述 |
|-------|------|
| cache_init | 是否缓存命中("true"或"false" |
## 使用示例
```yaml
- name: 缓存依赖
uses: actions/cache@master
with:
key: node-modules
mount: |
node_modules
hash_files: |
package.json
yarn.lock
```
## 工作原理
1. **恢复缓存restore**在作业开始时根据提供的key和hash_files生成缓存键尝试恢复缓存
2. **保存缓存save**:在作业成功完成后,如果缓存未命中或内容发生变化,则保存新的缓存
缓存键生成规则:`${操作系统}-${key}-${文件哈希值}`
## 安装和构建
```bash
# 安装依赖
yarn install
# 构建插件
yarn build
```
构建后的文件将输出到`dist/restore/`和`dist/save/`目录中。