Skip to content

Commit 07203f9

Browse files
committed
feat(ci): add GitHub Actions workflows for CI/CD
- Add CI workflow for code quality checks and tests - Add build workflow for cross-platform releases (macOS/Windows) - Update .gitignore to exclude CI/CD artifacts - Add comprehensive documentation for GitHub Actions usage Signed-off-by: junxiang Mu <1948535941@qq.com>
1 parent c468d79 commit 07203f9

File tree

4 files changed

+380
-1
lines changed

4 files changed

+380
-1
lines changed

.github/ACTIONS.md

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# GitHub Actions 自动编译说明
2+
3+
本项目配置了完整的 GitHub Actions CI/CD 流程,支持自动编译和发布。
4+
5+
## 工作流说明
6+
7+
### 1. CI 工作流 (`.github/workflows/ci.yml`)
8+
9+
**触发条件:**
10+
- Push 到 `main` 分支
11+
- 创建或更新 Pull Request
12+
13+
**功能:**
14+
- 代码格式检查 (rustfmt)
15+
- Clippy 代码质量检查
16+
- 前端构建验证
17+
- 单元测试运行
18+
19+
### 2. Build and Release 工作流 (`.github/workflows/build.yml`)
20+
21+
**触发条件:**
22+
- 推送以 `v` 开头的 tag (例如: `v0.1.0`, `v1.0.0`)
23+
- 手动触发 (workflow_dispatch)
24+
25+
**支持平台:**
26+
- **macOS Apple Silicon** (aarch64)
27+
- **macOS Intel** (x86_64)
28+
- **Windows** (x86_64)
29+
30+
**产物类型:**
31+
- macOS: `.dmg` 安装包和 `.app.zip` 压缩包
32+
- Windows: `.msi` 安装包和 `.exe` 安装程序
33+
34+
## 使用方法
35+
36+
### 发布新版本
37+
38+
1. **更新版本号**
39+
40+
编辑以下文件中的版本号:
41+
```
42+
src-tauri/Cargo.toml
43+
src-tauri/tauri.conf.json
44+
```
45+
46+
2. **提交更改**
47+
```bash
48+
git add .
49+
git commit -m "chore: bump version to v0.1.0"
50+
git push origin main
51+
```
52+
53+
3. **创建并推送 tag**
54+
```bash
55+
git tag v0.1.0
56+
git push origin v0.1.0
57+
```
58+
59+
4. **等待编译完成**
60+
61+
访问 GitHub Actions 页面查看编译进度:
62+
```
63+
https://github.com/YOUR_USERNAME/YOUR_REPO/actions
64+
```
65+
66+
5. **发布完成**
67+
68+
编译成功后会自动创建 GitHub Release,包含所有平台的安装包。
69+
70+
### 手动触发编译
71+
72+
1. 访问 GitHub Actions 页面
73+
2. 选择 "Build and Release" 工作流
74+
3. 点击 "Run workflow" 按钮
75+
4. 选择分支并运行
76+
77+
## 编译产物说明
78+
79+
编译完成后,会生成以下文件:
80+
81+
```
82+
RustFS-Launcher-macOS-aarch64/
83+
├── RustFS Launcher.dmg
84+
└── RustFS-Launcher-macOS-aarch64.app.zip
85+
86+
RustFS-Launcher-macOS-x86_64/
87+
├── RustFS Launcher.dmg
88+
└── RustFS-Launcher-macOS-x86_64.app.zip
89+
90+
RustFS-Launcher-Windows-x86_64/
91+
├── RustFS Launcher_x.x.x_x64.msi
92+
└── RustFS Launcher_x.x.x_x64-setup.exe
93+
```
94+
95+
## 常见问题
96+
97+
### 1. 编译失败怎么办?
98+
99+
- 检查 GitHub Actions 日志,查看具体错误信息
100+
- 确保所有依赖都已正确配置
101+
- 验证 RustFS 二进制文件下载链接是否有效
102+
103+
### 2. 如何修改编译目标?
104+
105+
编辑 `.github/workflows/build.yml` 文件中的 `matrix` 配置:
106+
107+
```yaml
108+
strategy:
109+
matrix:
110+
include:
111+
- platform: 'ubuntu-latest' # 添加 Linux 支持
112+
target: 'x86_64-unknown-linux-gnu'
113+
# ...
114+
```
115+
116+
### 3. 如何添加代码签名?
117+
118+
在 GitHub Repository Settings 中添加以下 Secrets:
119+
120+
**macOS:**
121+
- `APPLE_CERTIFICATE`
122+
- `APPLE_CERTIFICATE_PASSWORD`
123+
- `APPLE_SIGNING_IDENTITY`
124+
- `APPLE_ID`
125+
- `APPLE_PASSWORD`
126+
127+
**Windows:**
128+
- `WINDOWS_CERTIFICATE`
129+
- `WINDOWS_CERTIFICATE_PASSWORD`
130+
131+
然后在 workflow 中添加签名步骤。
132+
133+
## 依赖项说明
134+
135+
### 自动下载的依赖:
136+
- RustFS 二进制文件 (从 https://dl.rustfs.com 下载)
137+
138+
### GitHub Actions 使用的组件:
139+
- `dtolnay/rust-toolchain` - Rust 工具链
140+
- `Swatinem/rust-cache` - Rust 缓存加速
141+
- `actions/setup-node` - Node.js 环境
142+
- `actions/upload-artifact` - 构建产物上传
143+
- `softprops/action-gh-release` - 自动创建 Release
144+
145+
## 优化建议
146+
147+
1. **缓存优化**: 已配置 Rust 和 Node.js 缓存,加速编译
148+
2. **并行构建**: 三个平台同时编译,节省时间
149+
3. **失败容错**: 单个平台失败不影响其他平台编译
150+
4. **自动化发布**: Tag 推送后自动发布,无需手动操作
151+
152+
## 维护注意事项
153+
154+
- 定期检查 GitHub Actions 的使用配额
155+
- 保持依赖版本更新
156+
- 监控 RustFS 二进制文件下载地址的可用性
157+
- 及时处理编译失败的通知

.github/workflows/build.yml

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
name: Build and Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
workflow_dispatch:
8+
9+
jobs:
10+
build:
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
include:
15+
- platform: 'macos-latest'
16+
target: 'aarch64-apple-darwin'
17+
rust_target: 'aarch64-apple-darwin'
18+
binary_name: 'rustfs-macos-aarch64'
19+
artifact_name: 'RustFS-Launcher-macOS-aarch64'
20+
21+
- platform: 'macos-13'
22+
target: 'x86_64-apple-darwin'
23+
rust_target: 'x86_64-apple-darwin'
24+
binary_name: 'rustfs-macos-x86_64'
25+
artifact_name: 'RustFS-Launcher-macOS-x86_64'
26+
27+
- platform: 'windows-latest'
28+
target: 'x86_64-pc-windows-msvc'
29+
rust_target: 'x86_64-pc-windows-msvc'
30+
binary_name: 'rustfs-windows-x86_64.exe'
31+
artifact_name: 'RustFS-Launcher-Windows-x86_64'
32+
33+
runs-on: ${{ matrix.platform }}
34+
35+
steps:
36+
- name: Checkout repository
37+
uses: actions/checkout@v4
38+
39+
- name: Setup Rust
40+
uses: dtolnay/rust-toolchain@stable
41+
with:
42+
targets: ${{ matrix.rust_target }}
43+
44+
- name: Setup Rust cache
45+
uses: Swatinem/rust-cache@v2
46+
with:
47+
workspaces: src-tauri
48+
49+
- name: Install dependencies (macOS)
50+
if: runner.os == 'macOS'
51+
run: |
52+
brew install trunk
53+
54+
- name: Install dependencies (Windows)
55+
if: runner.os == 'Windows'
56+
run: |
57+
cargo install trunk
58+
59+
- name: Setup Node.js
60+
uses: actions/setup-node@v4
61+
with:
62+
node-version: '20'
63+
64+
- name: Download RustFS binary (macOS aarch64)
65+
if: matrix.platform == 'macos-latest'
66+
run: |
67+
mkdir -p src-tauri/binaries
68+
curl -L -o rustfs-macos-aarch64.zip https://dl.rustfs.com/artifacts/rustfs/release/rustfs-macos-aarch64-latest.zip
69+
unzip -q rustfs-macos-aarch64.zip -d rustfs-temp
70+
cp rustfs-temp/rustfs src-tauri/binaries/rustfs-macos-aarch64
71+
chmod +x src-tauri/binaries/rustfs-macos-aarch64
72+
rm -rf rustfs-temp rustfs-macos-aarch64.zip
73+
74+
- name: Download RustFS binary (macOS x86_64)
75+
if: matrix.platform == 'macos-13'
76+
run: |
77+
mkdir -p src-tauri/binaries
78+
curl -L -o rustfs-macos-x86_64.zip https://dl.rustfs.com/artifacts/rustfs/release/rustfs-macos-x86_64-latest.zip
79+
unzip -q rustfs-macos-x86_64.zip -d rustfs-temp
80+
cp rustfs-temp/rustfs src-tauri/binaries/rustfs-macos-x86_64
81+
chmod +x src-tauri/binaries/rustfs-macos-x86_64
82+
rm -rf rustfs-temp rustfs-macos-x86_64.zip
83+
84+
- name: Download RustFS binary (Windows)
85+
if: runner.os == 'Windows'
86+
shell: pwsh
87+
run: |
88+
New-Item -ItemType Directory -Force -Path src-tauri\binaries
89+
Invoke-WebRequest -Uri "https://dl.rustfs.com/artifacts/rustfs/release/rustfs-windows-x86_64-latest.zip" -OutFile "rustfs-windows-x86_64.zip"
90+
Expand-Archive -Path "rustfs-windows-x86_64.zip" -DestinationPath "rustfs-temp" -Force
91+
Copy-Item "rustfs-temp\rustfs.exe" -Destination "src-tauri\binaries\rustfs-windows-x86_64.exe"
92+
Remove-Item -Recurse -Force rustfs-temp, rustfs-windows-x86_64.zip
93+
94+
- name: Build Tauri application
95+
run: cargo tauri build --target ${{ matrix.rust_target }}
96+
97+
- name: Prepare artifacts (macOS)
98+
if: runner.os == 'macOS'
99+
run: |
100+
mkdir -p artifacts
101+
if [ -d "src-tauri/target/${{ matrix.rust_target }}/release/bundle/dmg" ]; then
102+
cp src-tauri/target/${{ matrix.rust_target }}/release/bundle/dmg/*.dmg artifacts/ || true
103+
fi
104+
if [ -d "src-tauri/target/${{ matrix.rust_target }}/release/bundle/macos" ]; then
105+
cd src-tauri/target/${{ matrix.rust_target }}/release/bundle/macos
106+
zip -r "$GITHUB_WORKSPACE/artifacts/${{ matrix.artifact_name }}.app.zip" *.app
107+
fi
108+
109+
- name: Prepare artifacts (Windows)
110+
if: runner.os == 'Windows'
111+
shell: pwsh
112+
run: |
113+
New-Item -ItemType Directory -Force -Path artifacts
114+
$msiFiles = Get-ChildItem -Path "src-tauri/target/${{ matrix.rust_target }}/release/bundle/msi" -Filter "*.msi" -ErrorAction SilentlyContinue
115+
if ($msiFiles) {
116+
Copy-Item $msiFiles.FullName -Destination artifacts/
117+
}
118+
$exeFiles = Get-ChildItem -Path "src-tauri/target/${{ matrix.rust_target }}/release/bundle/nsis" -Filter "*.exe" -ErrorAction SilentlyContinue
119+
if ($exeFiles) {
120+
Copy-Item $exeFiles.FullName -Destination artifacts/
121+
}
122+
123+
- name: Upload artifacts
124+
uses: actions/upload-artifact@v4
125+
with:
126+
name: ${{ matrix.artifact_name }}
127+
path: artifacts/*
128+
if-no-files-found: error
129+
130+
release:
131+
needs: build
132+
runs-on: ubuntu-latest
133+
if: startsWith(github.ref, 'refs/tags/v')
134+
135+
permissions:
136+
contents: write
137+
138+
steps:
139+
- name: Download all artifacts
140+
uses: actions/download-artifact@v4
141+
with:
142+
path: artifacts
143+
144+
- name: Display structure of downloaded files
145+
run: ls -R artifacts
146+
147+
- name: Create Release
148+
uses: softprops/action-gh-release@v1
149+
with:
150+
draft: false
151+
prerelease: false
152+
files: artifacts/**/*
153+
env:
154+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/ci.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
check:
11+
name: Check and Test
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Rust
19+
uses: dtolnay/rust-toolchain@stable
20+
with:
21+
components: rustfmt, clippy
22+
23+
- name: Setup Rust cache
24+
uses: Swatinem/rust-cache@v2
25+
with:
26+
workspaces: src-tauri
27+
28+
- name: Install Trunk
29+
run: cargo install trunk
30+
31+
- name: Setup Node.js
32+
uses: actions/setup-node@v4
33+
with:
34+
node-version: '20'
35+
36+
- name: Install system dependencies
37+
run: |
38+
sudo apt-get update
39+
sudo apt-get install -y \
40+
libwebkit2gtk-4.1-dev \
41+
build-essential \
42+
curl \
43+
wget \
44+
file \
45+
libssl-dev \
46+
libayatana-appindicator3-dev \
47+
librsvg2-dev
48+
49+
- name: Check Rust formatting
50+
run: cargo fmt --all --check
51+
working-directory: src-tauri
52+
53+
- name: Run Clippy
54+
run: cargo clippy --all-targets --all-features -- -D warnings
55+
working-directory: src-tauri
56+
57+
- name: Build frontend
58+
run: trunk build
59+
60+
- name: Run tests
61+
run: cargo test --all-features
62+
working-directory: src-tauri

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,10 @@
66
# Downloaded binaries (use build.sh to download)
77
src-tauri/binaries/rustfs-*
88
!src-tauri/binaries/.gitkeep
9-
temp_downloads/
9+
temp_downloads/
10+
11+
# CI/CD artifacts
12+
artifacts/
13+
*.dmg
14+
*.msi
15+
*.app.zip

0 commit comments

Comments
 (0)