Skip to content

Commit b17c98f

Browse files
erwei-xilinxclaude
andcommitted
Add code formatting CI with clang-format and black
Add a GitHub Actions workflow that checks C/C++ formatting via clang-format (LLVM style) and Python formatting via black on PRs and pushes to main. Uses reviewdog to post inline PR suggestions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0f2c2d2 commit b17c98f

3 files changed

Lines changed: 97 additions & 0 deletions

File tree

.clang-format

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BasedOnStyle: LLVM
2+
ColumnLimit: 80

.github/workflows/format.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Code Formatting Check
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_dispatch:
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
formatting:
16+
name: Python and C/C++ Format Check
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: write
20+
pull-requests: write
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 2
27+
submodules: "true"
28+
29+
- name: Install clang-format
30+
uses: aminya/setup-cpp@v1
31+
with:
32+
clangformat: 17.0.1
33+
34+
- name: Set up Python
35+
uses: actions/setup-python@v5
36+
with:
37+
python-version: "3.10"
38+
39+
- name: Install black
40+
run: pip install black
41+
42+
- name: Run git-clang-format
43+
id: git-clang-format
44+
run: |
45+
git fetch origin main
46+
git clang-format origin/main || true
47+
git diff > clang-format.diff
48+
cat clang-format.diff
49+
50+
- name: Upload clang-format diff
51+
uses: actions/upload-artifact@v4
52+
with:
53+
path: clang-format.diff
54+
name: clang_format_diffs
55+
56+
- name: Check C/C++ format
57+
uses: reviewdog/action-suggester@v1.22
58+
with:
59+
tool_name: clang-format
60+
level: error
61+
cleanup: true
62+
fail_level: any
63+
64+
- name: Run black format
65+
if: success() || failure()
66+
id: black-format
67+
run: |
68+
black . || true
69+
git diff > black-format.diff
70+
cat black-format.diff
71+
72+
- name: Upload black-format diff
73+
if: success() || failure()
74+
uses: actions/upload-artifact@v4
75+
with:
76+
path: black-format.diff
77+
name: black_format_diffs
78+
79+
- name: Check Python format
80+
if: success() || failure()
81+
uses: reviewdog/action-suggester@v1.22
82+
with:
83+
tool_name: black
84+
level: error
85+
fail_level: any

pyproject.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,13 @@ before-build = [
9696

9797
[tool.setuptools]
9898
packages = []
99+
100+
[tool.black]
101+
line-length = 88
102+
target-version = ["py310"]
103+
extend-exclude = '''
104+
(
105+
third_party/
106+
| build/
107+
)
108+
'''

0 commit comments

Comments
 (0)