Skip to content

Commit f02a7a1

Browse files
Pre release/v0.3.0 (#23)
* optimize: hook update and better check for 404 * english translation; better README * import the pr time check
1 parent 82dfb40 commit f02a7a1

75 files changed

Lines changed: 26800 additions & 384 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/pre-commit

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
ROOT="$(git rev-parse --show-toplevel)"
6+
cd "$ROOT"
7+
8+
log() {
9+
printf '[pre-commit] %s\n' "$1"
10+
}
11+
12+
fail() {
13+
printf '[pre-commit] ERROR: %s\n' "$1" >&2
14+
exit 1
15+
}
16+
17+
mapfile -t STAGED_FILES < <(git diff --cached --name-only --diff-filter=ACMR)
18+
19+
if [ "${#STAGED_FILES[@]}" -eq 0 ]; then
20+
log "No staged files. Nothing to check."
21+
exit 0
22+
fi
23+
24+
mapfile -t CPP_FILES < <(
25+
printf '%s\n' "${STAGED_FILES[@]}" |
26+
grep -E '\.(c|cc|cpp|cxx|h|hh|hpp|hxx)$' || true
27+
)
28+
29+
if [ "${#CPP_FILES[@]}" -gt 0 ]; then
30+
command -v clang-format >/dev/null 2>&1 ||
31+
fail "clang-format is required to commit C/C++ files."
32+
33+
DIRTY_CPP_FILES=()
34+
for file in "${CPP_FILES[@]}"; do
35+
if ! git diff --quiet -- "$file"; then
36+
DIRTY_CPP_FILES+=("$file")
37+
fi
38+
done
39+
40+
if [ "${#DIRTY_CPP_FILES[@]}" -gt 0 ]; then
41+
printf '[pre-commit] These staged C/C++ files also have unstaged changes:\n' >&2
42+
printf ' %s\n' "${DIRTY_CPP_FILES[@]}" >&2
43+
fail "stage or stash those unstaged changes before committing so the hook does not include them accidentally."
44+
fi
45+
46+
log "Formatting ${#CPP_FILES[@]} staged C/C++ file(s) with clang-format..."
47+
clang-format -i -- "${CPP_FILES[@]}"
48+
git add -- "${CPP_FILES[@]}"
49+
fi
50+
51+
command -v python3 >/dev/null 2>&1 ||
52+
fail "python3 is required to update translation coverage."
53+
54+
if ! git diff --quiet -- README.md; then
55+
fail "README.md has unstaged changes; stage or stash them before committing so coverage updates stay explicit."
56+
fi
57+
58+
log "Updating translation coverage in README.md..."
59+
python3 scripts/coverage.py --update
60+
git add README.md
61+
62+
log "Done."

.github/workflows/build-check.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Build Check
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Setup Node.js
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: '22'
21+
22+
- name: Setup pnpm
23+
uses: pnpm/action-setup@v4
24+
with:
25+
version: 10
26+
27+
- name: Install dependencies
28+
run: pnpm install --frozen-lockfile
29+
30+
- name: Restore build cache
31+
uses: actions/cache@v4
32+
with:
33+
path: site/.vitepress/.build-cache
34+
key: vitepress-build-${{ hashFiles('documents/**') }}
35+
restore-keys: vitepress-build-
36+
37+
- name: Build
38+
run: pnpm build
39+
env:
40+
NODE_OPTIONS: --max-old-space-size=6144
41+
BUILD_CONCURRENCY: 8

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Pre-commit hooks configuration
2-
# Install: pip install pre-commit
3-
# Enable: pre-commit install
1+
# Optional pre-commit framework checks.
2+
# The default one-step commit automation lives in .githooks/pre-commit.
3+
# Install the native Git hook with: pnpm hooks:install
44

55
repos:
66
# Markdown linting

CONTRIBUTING.md

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,38 @@
66

77
1. Fork 本仓库
88
2. 创建你的特性分支 (`git switch -c feature/amazing-feature`)
9-
3. 提交更改 (`git commit -m '添加某功能'`)
10-
4. 推送到分支 (`git push origin feature/amazing-feature`)
11-
5. 创建 Pull Request
9+
3. 安装本地 Git hook (`pnpm hooks:install``scripts/setup_precommit.sh`)
10+
4. 提交更改 (`git commit -m '添加某功能'`)
11+
5. 推送到分支 (`git push origin feature/amazing-feature`)
12+
6. 创建 Pull Request
13+
14+
## 提交前自动化
15+
16+
本仓库使用可追踪的原生 Git hook,配置位于 `.githooks/pre-commit`。安装后,每次 `git commit` 前会自动执行:
17+
18+
- 对已暂存的 C/C++ 源文件和头文件运行 `clang-format -i`
19+
- 运行 `python3 scripts/coverage.py --update` 检查英文翻译覆盖率并更新 `README.md`
20+
- 对 hook 自动修改的文件执行 `git add`,因此通常不需要因为格式化或覆盖率徽章变化再次手动提交
21+
22+
首次克隆仓库后运行:
23+
24+
```bash
25+
pnpm install
26+
pnpm hooks:install
27+
```
28+
29+
如果不使用 pnpm,也可以直接运行:
30+
31+
```bash
32+
scripts/setup_precommit.sh
33+
```
34+
35+
hook 依赖本机已安装:
36+
37+
- `python3`:用于翻译覆盖率统计
38+
- `clang-format`:用于 C/C++ 代码格式化
39+
40+
为了避免把未准备提交的内容一起带入 commit,如果已暂存的 C/C++ 文件或 `README.md` 同时还有未暂存改动,hook 会停止并提示先整理工作区。确实需要临时跳过 hook 时,可以使用 `git commit --no-verify`,但不建议在 PR 提交中长期绕过。
1241

1342
## 文章规范
1443

0 commit comments

Comments
 (0)