Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
cfc5467
feat: 添加 Go 版本重写的基础框架
YewFence Jan 16, 2026
a47d10d
feat(go): 添加日志文件输出、Gist上传和并行服务管理
YewFence Jan 16, 2026
d3f4f16
chore: 删除 kopia 维护相关命令
YewFence Jan 16, 2026
33f3879
test: 添加单测
YewFence Jan 16, 2026
b267075
feat(go): 添加交叉编译 Makefile 和 CI/CD 工作流
YewFence Jan 16, 2026
c376a78
docs: 更新 README 添加 Go 版本说明
YewFence Jan 16, 2026
a83d73b
refactor: 优化配置加载和日志捕获,增强并发安全性
YewFence Jan 16, 2026
45bdc34
chore: 删除 latest 版本发布 Action
YewFence Jan 16, 2026
7ee4b01
refactor: 改进 LoadConfig 函数的错误处理逻辑,增强配置文件加载的健壮性
YewFence Jan 16, 2026
c58324e
fix: 修复异步执行通知发送时程序退出过快导致通知无法发送的问题
YewFence Jan 16, 2026
f869827
chore: 增加二进制文件名的gitignore
YewFence Jan 16, 2026
3a59a83
chore: 增加代码块说明
YewFence Jan 16, 2026
44b649e
test: 增加不合法配置默认值回退测试
YewFence Jan 16, 2026
c4a5e88
ci: 增加静态链接编译选项
YewFence Jan 16, 2026
0aadfee
feat: 增加 Docker 命令超时时间配置,优化服务管理
YewFence Jan 16, 2026
b3e3937
feat: 增强远程路径校验,只需要确保引号包裹期望远程路径即可
YewFence Jan 16, 2026
276722c
fix: 修复当 .env 不存在时,go test失败的问题
YewFence Jan 16, 2026
727dd2e
fix: 增加 docker compose ps 命令失败时报错的功能
YewFence Jan 18, 2026
9e12cf0
feat: 检测不到配置文件时显式输出日志
YewFence Jan 18, 2026
b1b6baf
feat: 补充 Windows 环境中 sh 执行权限检测逻辑
YewFence Jan 18, 2026
37334a3
fix: 修复和文档不一致的错误配置
YewFence Jan 18, 2026
1e649b0
refactor: 简化 yes 判断逻辑
YewFence Jan 18, 2026
a68f299
chore: 删除多余的引号
YewFence Jan 18, 2026
032ab5f
docs: 更新环境变量表格,增加 Shell 和 Go 版本支持说明
YewFence Jan 18, 2026
35d92a2
refactor: 引入 ServiceError 结构体以显式提取错误服务名
YewFence Jan 18, 2026
6ef1527
ci: 去除了推送即构建的功能
YewFence Jan 18, 2026
615db93
ci: 增加手动选择分支构建功能
YewFence Jan 18, 2026
211a03b
ci: 增加 go 版本的应用选择单个平台构建的功能
YewFence Jan 18, 2026
1f00b1f
feat: 将依赖检查提前至交互式确认之前
YewFence Jan 18, 2026
79f6c2f
ci: 把输出目录改浅一点
YewFence Jan 18, 2026
6aa05b5
test: 增加 docker main 模块的测试
YewFence Jan 18, 2026
bc2cf5c
test: 增加 orchestrator 测试
YewFence Jan 18, 2026
054e85e
feat: 统一使用 UTC 时间
YewFence Jan 18, 2026
5552b0b
feat: 增加 kopia 仓库状态检测,使用--json参数直接解析 json, 增加健壮性
YewFence Jan 18, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions .github/workflows/build-artifact.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
name: Build Artifact

on:
push:
branches-ignore:
- main
pull_request:
branches:
- main
paths:
- 'src/**'
workflow_dispatch:
inputs:
ref:
description: '要构建的分支或标签'
required: true
default: 'main'

permissions:
contents: read
Expand All @@ -16,7 +21,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

with:
ref: ${{ inputs.ref || github.ref }}
- name: Run make
run: |
make
Expand Down
30 changes: 0 additions & 30 deletions .github/workflows/dev-release.yml

This file was deleted.

61 changes: 61 additions & 0 deletions .github/workflows/go-build-artifact.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Go Build Artifact

on:
pull_request:
branches:
- main
paths:
- 'go/**'
workflow_dispatch:
inputs:
ref:
description: '要构建的分支或标签'
required: true
default: 'main'
platform:
description: '选择构建平台'
required: true
default: 'all'
type: choice
options:
- all
- linux
- darwin
- windows

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref || github.ref }}

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'

- name: Run tests
working-directory: go
run: go test -v ./...

- name: Build selected platform
working-directory: go
run: make ${{ inputs.platform || 'all' }}

- name: Prepare artifact root
run: |
mkdir -p artifacts
cp go/dist/* artifacts/

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: yewresin-go-${{ github.sha }}
path: |
artifacts/*
retention-days: 7
38 changes: 38 additions & 0 deletions .github/workflows/go-prod-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Go Production Release

on:
push:
tags:
- "v2*"

permissions:
contents: write

jobs:
build-and-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'

- name: Run tests
working-directory: go
run: go test -v ./...

- name: Build all platforms
working-directory: go
run: VERSION=${{ github.ref_name }} make all

- name: Create Tagged Release
uses: softprops/action-gh-release@v2
with:
files: |
go/dist/*
.env.example
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
76 changes: 76 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## 项目概述

YewResin 是一个 Docker Compose 服务的自动化备份脚本,使用 Kopia + rclone 实现本地快照与云端同步。脚本会依次停止所有 Docker 服务,创建一致性快照,然后按优先级恢复服务。

## 构建命令

```bash
# 合并 src/ 模块生成 yewresin.sh(必须在修改代码后执行)
make build

# 清理生成的脚本
make clean
```

## 架构

脚本采用模块化设计,源代码在 `src/` 目录下,按数字前缀顺序拼接:

| 模块 | 职责 |
|------|------|
| `00-header.sh` | shebang、set -eo pipefail、记录开始时间 |
| `01-logging.sh` | 日志输出(tee 到文件和终端)、`log()` 函数 |
| `02-args.sh` | 命令行参数解析(`--dry-run`、`-y`、`--help`) |
| `03-config.sh` | 配置加载(从 `.env` 读取)、默认值、`print_config()` |
| `04-utils.sh` | 通用工具函数 |
| `05-notification.sh` | Apprise 通知发送 |
| `06-gist.sh` | GitHub Gist 日志上传和清理 |
| `07-dependencies.sh` | 依赖检查(rclone、kopia) |
| `08-services.sh` | Docker 服务管理:停止、启动、状态检查、cleanup |
| `09-main.sh` | 主流程:停止服务 → Kopia 快照 → 启动服务 |

**核心函数在 `08-services.sh`:**
- `stop_all_services()` / `start_all_services()` - 批量服务管理
- `is_service_running()` - 检测服务运行状态
- `cleanup()` - 异常退出时自动恢复服务(trap EXIT)

**服务启停优先级逻辑:**
- 优先服务(`PRIORITY_SERVICES`):最后停止,最先启动(如网关 caddy/nginx)
- 普通服务:先停止,后启动
- 只恢复原本在运行的服务(通过 `RUNNING_SERVICES` 关联数组追踪)

## 开发流程

1. 修改 `src/` 下的模块文件
2. 执行 `make build` 重新生成 `yewresin.sh`
3. 提交 `src/`、`Makefile` 和 `yewresin.sh`

## 运行与测试

```bash
# 本地模拟运行(不执行实际操作)
./yewresin.sh --dry-run

# 执行备份(需确认)
./yewresin.sh

# 跳过确认(用于 cron)
./yewresin.sh -y
```

## 配置

必须在 `.env` 中设置:
- `BASE_DIR` - Docker Compose 项目总目录
- `EXPECTED_REMOTE` - Kopia 远程路径(如 `gdrive:backup`)

可参考 `.env.example` 查看完整配置项。

## CI/CD

- `dev-release.yml` - main 分支推送后自动构建并发布到 `latest` tag
- `prod-release.yml` - 手动触发正式版本发布
Loading
Loading