Skip to content

Commit 659e99c

Browse files
committed
Merge branch 'version2-beta'
2 parents 9e2b103 + 75484c4 commit 659e99c

62 files changed

Lines changed: 8109 additions & 2679 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.githooks/README.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Git Hooks
2+
3+
此目录包含项目的 Git Hooks 脚本,用于自动化代码质量检查。
4+
5+
## 安装
6+
7+
在首次克隆仓库或更新 hooks 后,需要运行安装脚本:
8+
9+
```bash
10+
bash .githooks/install.sh
11+
```
12+
13+
或者使用 Git 配置自动使用此目录(Git 2.9+):
14+
15+
```bash
16+
git config core.hooksPath .githooks
17+
```
18+
19+
## 可用的 Hooks
20+
21+
### pre-commit
22+
23+
`git commit` 之前自动执行:
24+
25+
- **功能**:自动格式化待提交的 Swift 代码
26+
- **工具**:使用 Apple 官方的 `swift-format` 进行格式化
27+
- **行为**
28+
- 检测所有待提交的 `.swift` 文件
29+
- 使用 `swift-format` 格式化这些文件
30+
- 自动将格式化后的文件重新暂存
31+
- 如果未安装 `swift-format`,会给出警告但不会阻止提交
32+
33+
## 安装 swift-format
34+
35+
### 使用 Homebrew(推荐)
36+
37+
```bash
38+
brew install swift-format
39+
```
40+
41+
### 使用 Mint
42+
43+
```bash
44+
mint install apple/swift-format
45+
```
46+
47+
### 从源码构建
48+
49+
```bash
50+
git clone https://github.com/apple/swift-format.git
51+
cd swift-format
52+
swift build -c release
53+
```
54+
55+
## 配置
56+
57+
`swift-format` 使用 Apple 官方的默认规则,也可以在项目根目录创建 `.swift-format` 配置文件进行自定义。
58+
59+
## 跳过 Hook 检查
60+
61+
如果需要暂时跳过 hook 检查(不推荐):
62+
63+
```bash
64+
git commit --no-verify
65+
```
66+
67+
或使用简写:
68+
69+
```bash
70+
git commit -n
71+
```
72+
73+
## 卸载
74+
75+
删除已安装的 hooks:
76+
77+
```bash
78+
rm -rf .git/hooks/pre-commit
79+
```
80+
81+
## 故障排查
82+
83+
### Hook 没有执行
84+
85+
1. 检查 hook 是否有执行权限:
86+
```bash
87+
ls -l .git/hooks/pre-commit
88+
```
89+
90+
2. 重新安装:
91+
```bash
92+
bash .githooks/install.sh
93+
```
94+
95+
### swift-format 找不到
96+
97+
确保 `swift-format` 在 PATH 中:
98+
99+
```bash
100+
which swift-format
101+
```
102+
103+
如果没有,请重新安装或将其添加到 PATH。
104+
105+
## 维护
106+
107+
更新 hooks 后,团队成员需要重新运行安装脚本:
108+
109+
```bash
110+
bash .githooks/install.sh
111+
```

.githooks/install.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
# Git Hooks 安装脚本
4+
# 将 .githooks 目录中的钩子复制到 .git/hooks
5+
6+
echo "📦 安装 Git Hooks..."
7+
8+
# 获取脚本所在目录
9+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
10+
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
11+
12+
# 创建 .git/hooks 目录(如果不存在)
13+
mkdir -p "$PROJECT_ROOT/.git/hooks"
14+
15+
# 复制所有 hook 文件
16+
for hook in "$SCRIPT_DIR"/*; do
17+
# 跳过安装脚本本身和 README
18+
if [[ "$(basename "$hook")" == "install.sh" ]] || [[ "$(basename "$hook")" == "README.md" ]]; then
19+
continue
20+
fi
21+
22+
hook_name=$(basename "$hook")
23+
echo " ✓ 安装 $hook_name"
24+
25+
# 复制并设置执行权限
26+
cp "$hook" "$PROJECT_ROOT/.git/hooks/$hook_name"
27+
chmod +x "$PROJECT_ROOT/.git/hooks/$hook_name"
28+
done
29+
30+
echo ""
31+
echo "✅ Git Hooks 安装完成!"
32+
echo ""
33+
echo "提示:"
34+
echo " • 如需跳过 hook 检查: git commit --no-verify"
35+
echo " • 安装 swift-format: brew install swift-format"
36+
echo ""

.githooks/pre-commit

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
# Pre-commit hook for Swift code formatting
6+
# 在提交前自动格式化 Swift 代码
7+
8+
REPO_ROOT="$(git rev-parse --show-toplevel)"
9+
CONFIG_FILE="$REPO_ROOT/.swift-format"
10+
11+
if ! command -v swift-format >/dev/null 2>&1; then
12+
echo "⚠️ 未找到 swift-format,跳过格式化"
13+
echo " 安装方法: brew install swift-format"
14+
echo ""
15+
echo " 或者跳过此检查: git commit --no-verify"
16+
exit 0
17+
fi
18+
19+
SWIFT_FILES=()
20+
while IFS= read -r -d '' file; do
21+
SWIFT_FILES+=("$file")
22+
done < <(git diff --cached --name-only --diff-filter=ACM -z -- '*.swift')
23+
24+
if [ "${#SWIFT_FILES[@]}" -eq 0 ]; then
25+
exit 0
26+
fi
27+
28+
echo "🔍 检测到 Swift 文件变更,开始格式化..."
29+
30+
FORMATTED_COUNT=0
31+
for file in "${SWIFT_FILES[@]}"; do
32+
if [ -f "$file" ]; then
33+
echo " 📝 格式化: $file"
34+
swift-format format --configuration "$CONFIG_FILE" --in-place "$file"
35+
git add "$file"
36+
FORMATTED_COUNT=$((FORMATTED_COUNT + 1))
37+
fi
38+
done
39+
40+
echo "✅ 格式化完成 ($FORMATTED_COUNT 个文件)"
41+
echo ""

.github/FUNDING.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# These are supported funding model platforms
22

33
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4-
patreon: fatbobman
4+
patreon: #
55
open_collective: # Replace with a single Open Collective username
66
ko_fi: # Replace with a single Ko-fi username
77
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel

.github/workflows/ci.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- version2-beta
8+
pull_request:
9+
workflow_dispatch:
10+
11+
jobs:
12+
build-and-test:
13+
name: Build and Test
14+
runs-on: macos-15
15+
env:
16+
DEVELOPER_DIR: /Applications/Xcode_26.3.0.app/Contents/Developer
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
22+
- name: Show Xcode Version
23+
run: xcodebuild -version
24+
25+
- name: Show Swift Version
26+
run: swift --version
27+
28+
- name: Build
29+
run: swift build --enable-experimental-prebuilts
30+
31+
- name: Test (Parallel)
32+
run: bash test.sh --enable-experimental-prebuilts

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
.DS_Store
22
/.build
33
/Packages
4+
/.swiftpm
5+
Package.resolved
46
/*.xcodeproj
57
xcuserdata/
68
DerivedData/
79
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
10+
/.vscode
11+
/.claude

.swift-format

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"version" : 1,
3+
"indentation" : {
4+
"spaces" : 2
5+
},
6+
"lineLength" : 100,
7+
"maximumBlankLines" : 1,
8+
"multiElementCollectionTrailingCommas" : true,
9+
"respectsExistingLineBreaks" : true,
10+
"indentConditionalCompilationBlocks" : true,
11+
"lineBreakBeforeControlFlowKeywords" : false,
12+
"lineBreakBeforeEachArgument" : false,
13+
"spacesAroundRangeFormationOperators" : false,
14+
"rules" : {
15+
"DoNotUseSemicolons" : true,
16+
"NoEmptyTrailingClosureParentheses" : true,
17+
"NoParensAroundConditions" : true,
18+
"OrderedImports" : true,
19+
"ReturnVoidInsteadOfEmptyTuple" : true,
20+
"UseShorthandTypeNames" : true,
21+
"UseTripleSlashForDocumentationComments" : true
22+
}
23+
}

0 commit comments

Comments
 (0)