Skip to content

Commit 6e7d15d

Browse files
SigureMoCopilot
andauthored
[CI] Add codestyle check workflow (#20)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 7481523 commit 6e7d15d

16 files changed

+383
-215
lines changed

.clang-format

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
# The basic usage is,
77
# clang-format -i -style=file PATH/TO/SOURCE/CODE
88
#
9-
# The -style=file implicit use ".clang-format" file located in one of
10-
# parent directory.
9+
# The -style=file implicit use ".clang-format" file located in one of
10+
# parent directory.
1111
# The -i means inplace change.
1212
#
13-
# The document of clang-format is
13+
# The document of clang-format is
1414
# http://clang.llvm.org/docs/ClangFormat.html
1515
# http://clang.llvm.org/docs/ClangFormatStyleOptions.html
1616
---
@@ -20,7 +20,7 @@ IndentWidth: 2
2020
TabWidth: 2
2121
ContinuationIndentWidth: 4
2222
AccessModifierOffset: -1 # The private/protected/public has no indent in class
23-
Standard: Cpp11
23+
Standard: Cpp11
2424
AllowAllParametersOfDeclarationOnNextLine: true
2525
BinPackParameters: false
2626
BinPackArguments: false

.editorconfig

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# EditorConfig is a cross-editor configuration file
2+
# that helps to unify code styles for multiple
3+
# developers collaborative projects.
4+
# See more at https://editorconfig.org/
5+
6+
root = true
7+
8+
[*]
9+
indent_style = space
10+
end_of_line = lf
11+
charset = utf-8
12+
trim_trailing_whitespace = true
13+
insert_final_newline = true
14+
15+
[*.{c,cc,cxx,cpp,cu,cuh,h,hpp,hxx,kps,yml,yaml}]
16+
indent_size = 2
17+
18+
[*.{py,pyi,java,r,toml}]
19+
indent_size = 4
20+
21+
[Dockerfile.*]
22+
indent_size = 4
23+
24+
[*.go]
25+
indent_style = tab
26+
indent_size = 4

.flake8

Lines changed: 0 additions & 22 deletions
This file was deleted.

.github/workflows/check-bypass.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
on:
2+
workflow_call:
3+
inputs:
4+
workflow-name:
5+
required: true
6+
type: string
7+
secrets:
8+
github-token:
9+
required: true
10+
outputs:
11+
can-skip:
12+
description: "Whether the workflow can be skipped."
13+
value: ${{ jobs.check-bypass.outputs.can-skip }}
14+
15+
jobs:
16+
check-bypass:
17+
name: Check bypass
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: read
21+
env:
22+
CI_TEAM_MEMBERS: '["SigureMo", "BingooYang", "yongqiangma"]'
23+
outputs:
24+
can-skip: ${{ steps.check-bypass.outputs.can-skip }}
25+
steps:
26+
- id: check-bypass
27+
name: Check Bypass
28+
uses: PFCCLab/ci-bypass@v2
29+
with:
30+
github-token: ${{ secrets.GITHUB_TOKEN }}
31+
non-pull-request-event-strategy: "never-skipped"
32+
type: "composite"
33+
composite-rule: |
34+
{
35+
"any": [
36+
{
37+
"type": "labeled",
38+
"label": ["skip-ci: ${{ inputs.workflow-name }}", "skip-ci: all"],
39+
"username": ${{ env.CI_TEAM_MEMBERS }}
40+
},
41+
{
42+
"type": "commented",
43+
"comment-pattern": [".*/skip-ci ${{ inputs.workflow-name }}.*", ".*/skip-ci all.*"],
44+
"username": ${{ env.CI_TEAM_MEMBERS }}
45+
}
46+
]
47+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: codestyle-check
2+
3+
on:
4+
pull_request:
5+
branches: ["master"]
6+
7+
jobs:
8+
check-bypass:
9+
name: Check bypass
10+
uses: ./.github/workflows/check-bypass.yml
11+
with:
12+
workflow-name: "codestyle"
13+
secrets:
14+
github-token: ${{ secrets.GITHUB_TOKEN }}
15+
16+
pre-commit:
17+
name: Run pre-commit checks
18+
needs: check-bypass
19+
if: ${{ github.repository_owner == 'PFCCLab' && needs.check-bypass.outputs.can-skip != 'true' }}
20+
runs-on: ubuntu-latest
21+
env:
22+
PR_ID: ${{ github.event.pull_request.number }}
23+
24+
steps:
25+
- name: Checkout base repo
26+
uses: actions/checkout@v6
27+
with:
28+
ref: ${{ github.event.pull_request.base.ref }}
29+
fetch-depth: 200
30+
31+
- name: Merge PR to test branch
32+
run: |
33+
git fetch origin pull/${PR_ID}/merge
34+
git checkout -b test FETCH_HEAD
35+
36+
- name: Install uv
37+
uses: astral-sh/setup-uv@v7
38+
with:
39+
python-version: "3.14"
40+
enable-cache: true
41+
42+
- name: Install dependencies
43+
run: |
44+
uv venv -p 3.14
45+
source .venv/bin/activate
46+
uv pip install cpplint==1.6.0 clang-format==13.0.0
47+
48+
- name: Install prek
49+
run: |
50+
uv tool install prek
51+
52+
- name: Run prek
53+
run: |
54+
source .venv/bin/activate
55+
prek run --all-files

.pre-commit-config.yaml

Lines changed: 55 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,77 @@
11
repos:
2-
# Common hooks
3-
- repo: https://github.com/pre-commit/pre-commit-hooks
4-
rev: v4.1.0
2+
# Common hooks
3+
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
rev: v4.4.0
55
hooks:
6-
- id: check-added-large-files
7-
- id: check-merge-conflict
8-
- id: check-symlinks
9-
- id: detect-private-key
10-
- id: end-of-file-fixer
11-
- id: trailing-whitespace
12-
files: (.*\.(py|bzl|md|rst|c|cc|cxx|cpp|cu|h|hpp|hxx|xpu|kps|cmake|yaml|yml|hook|scpp)|BUILD|.*\.BUILD|WORKSPACE|CMakeLists\.txt)$
13-
- repo: https://github.com/Lucas-C/pre-commit-hooks.git
14-
rev: v1.1.14
6+
- id: check-added-large-files
7+
- id: check-merge-conflict
8+
- id: check-symlinks
9+
- id: detect-private-key
10+
- id: end-of-file-fixer
11+
- id: sort-simple-yaml
12+
files: (ops|backward|op_[a-z_]+)\.yaml$
13+
- id: trailing-whitespace
14+
- repo: https://github.com/Lucas-C/pre-commit-hooks.git
15+
rev: v1.5.1
1516
hooks:
16-
- id: remove-crlf
17-
- id: remove-tabs
17+
- id: remove-crlf
18+
- id: remove-tabs
1819
name: Tabs remover (C++)
19-
files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|xpu|kps)$
20+
files: \.(c|cc|cxx|cpp|cu|h|cuh|hpp|hxx|xpu|kps)$
2021
args: [--whitespaces-count, '2']
21-
- id: remove-tabs
22+
- id: remove-tabs
2223
name: Tabs remover (Python)
2324
files: (.*\.(py|bzl)|BUILD|.*\.BUILD|WORKSPACE)$
2425
args: [--whitespaces-count, '4']
25-
# For Python files
26-
- repo: https://github.com/psf/black.git
27-
rev: 22.8.0
26+
# For Python files
27+
- repo: https://github.com/astral-sh/ruff-pre-commit
28+
rev: v0.14.4
2829
hooks:
29-
- id: black
30-
files: (.*\.(py|pyi|bzl)|BUILD|.*\.BUILD|WORKSPACE)$
31-
- repo: https://github.com/PyCQA/flake8
32-
rev: 4.0.1
30+
- id: ruff-check
31+
args: [--fix, --exit-non-zero-on-fix, --no-cache]
32+
- id: ruff-format
33+
# For C++ files
34+
- repo: local
3335
hooks:
34-
- id: flake8
35-
- repo: https://github.com/PyCQA/autoflake
36-
rev: v1.7.7
37-
hooks:
38-
- id: autoflake
39-
args:
40-
- --in-place
41-
- --remove-all-unused-imports
42-
- --ignore-pass-after-docstring
43-
- --ignore-init-module-imports
44-
- --exclude=python/paddle/fluid/[!t]**,python/paddle/fluid/tra**
45-
- repo: local
46-
hooks:
47-
- id: pylint-doc-string
48-
name: pylint
49-
description: Check python docstring style using docstring_checker.
50-
entry: bash ./tools/codestyle/pylint_pre_commit.hook
51-
language: system
52-
files: \.(py)$
53-
# For C++ files
54-
- repo: local
55-
hooks:
56-
- id: clang-format
36+
- id: clang-format
5737
name: clang-format
5838
description: Format files with ClangFormat.
59-
entry: bash ./tools/codestyle/clang_format.hook -i
39+
entry: bash ./tools/codestyle/clang_format.sh -i
6040
language: system
61-
files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|xpu|kps|mm|m|scpp)$
62-
- repo: local
41+
files: \.(c|cc|cxx|cpp|cu|h|cuh|hpp|hxx|xpu|kps)$
42+
- repo: local
6343
hooks:
64-
- id: cpplint-cpp-source
44+
- id: cpplint-cpp-source
6545
name: cpplint
6646
description: Check C++ code style using cpplint.py.
67-
entry: bash ./tools/codestyle/cpplint_pre_commit.hook
47+
entry: bash ./tools/codestyle/cpplint_pre_commit.sh
6848
language: system
69-
files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|scpp)$
49+
files: \.(cc|cxx|cpp|cu|h|hpp|hxx)$
7050
args:
71-
- --extensions=c,cc,cxx,cpp,cu,cuh,h,hpp,hxx,kps
72-
- --filter=-readability/fn_size,-build/include_what_you_use,-build/c++11,-whitespace/parens,-legal/copyright
73-
- --quiet
74-
# For CMake files
75-
- repo: local
76-
hooks:
77-
- id: auto-generate-cmakelists
78-
name: auto-generate-cmakelists
79-
entry: bash ./tools/gen_ut_cmakelists.hook
80-
language: system
81-
files: testslist.csv$
82-
- repo: https://github.com/cheshirekow/cmake-format-precommit
51+
- --extensions=cc,cxx,cpp,cu,cuh,h,hpp,hxx,kps
52+
- --filter=-readability/fn_size,-build/include_what_you_use,-build/c++11,-whitespace/parens,-legal/copyright
53+
- --quiet
54+
# For CMake files
55+
- repo: https://github.com/cheshirekow/cmake-format-precommit
8356
rev: v0.6.13
8457
hooks:
85-
- id: cmake-format
86-
- repo: https://github.com/cmake-lint/cmake-lint
87-
rev: 1.4.2
58+
- id: cmake-format
59+
- repo: https://github.com/PFCCLab/cmake-lint-paddle
60+
rev: v1.5.1
8861
hooks:
89-
- id: cmakelint
62+
- id: cmakelint
9063
args: [--config=./tools/codestyle/.cmakelintrc]
64+
# For YAML files
65+
- repo: https://github.com/PFCCLab/yamlfmt-pre-commit-mirror.git
66+
rev: v0.16.0
67+
hooks:
68+
- id: yamlfmt
69+
files: |
70+
(?x)^(
71+
\.github/.+\.(yaml|yml)|
72+
\.pre-commit-config\.yaml|
73+
\.yamlfmt|
74+
sgconfig\.yml|
75+
ci/rules/.+\.yml|
76+
ci/rule-tests/.+\.yml
77+
)

.style.yapf

Lines changed: 0 additions & 3 deletions
This file was deleted.

.yamlfmt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
formatter:
2+
indent: 2
3+
type: basic
4+
retain_line_breaks: true
5+
scan_folded_as_literal: true

0 commit comments

Comments
 (0)