-
Notifications
You must be signed in to change notification settings - Fork 0
41 lines (36 loc) · 1.12 KB
/
format.yml
File metadata and controls
41 lines (36 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
name: Format C++ Code
on:
push:
pull_request:
types:
- opened
- synchronize
- reopened
jobs:
format:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
# 关键:获取完整的 git 历史和分支信息
fetch-depth: 0
# 确保有推送权限
token: ${{ secrets.GITHUB_TOKEN }}
# 检出 PR 的 head 分支,而不是 merge commit
ref: ${{ github.head_ref }}
- name: Install clang-format
run: sudo apt-get update && sudo apt-get install -y clang-format
- name: Run clang-format
run: find src -name "*.h" -o -name "*.hpp" -o -name "*.cpp" | xargs clang-format -i --style=file
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v6
with:
commit_message: "style: format code with clang-format"
branch: ${{ github.head_ref }}
# 确保获取最新状态
skip_fetch: false
# 只格式化 src 目录的文件
file_pattern: "src/"