-
Notifications
You must be signed in to change notification settings - Fork 4
[CI] Add codestyle check workflow #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
206ffb0
[CI] Add CI workflows on Cpp test repo
SigureMo b9942c2
add .yamlfmt
SigureMo 6f2cd68
add ruff config
SigureMo f4af88b
Update .github/workflows/codestyle-check.yml
SigureMo 23f8c6c
use setup-uv@v7
SigureMo 6d4b3d2
remove yapf config
SigureMo 25c1083
pre install cpplint and clang-format
SigureMo 8aa6e9a
add --system
SigureMo c3f9c6d
create venv
SigureMo 593b855
fix venv
SigureMo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # EditorConfig is a cross-editor configuration file | ||
| # that helps to unify code styles for multiple | ||
| # developers collaborative projects. | ||
| # See more at https://editorconfig.org/ | ||
|
|
||
| root = true | ||
|
|
||
| [*] | ||
| indent_style = space | ||
| end_of_line = lf | ||
| charset = utf-8 | ||
| trim_trailing_whitespace = true | ||
| insert_final_newline = true | ||
|
|
||
| [*.{c,cc,cxx,cpp,cu,cuh,h,hpp,hxx,kps,yml,yaml}] | ||
| indent_size = 2 | ||
|
|
||
| [*.{py,pyi,java,r,toml}] | ||
| indent_size = 4 | ||
|
|
||
| [Dockerfile.*] | ||
| indent_size = 4 | ||
|
|
||
| [*.go] | ||
| indent_style = tab | ||
| indent_size = 4 |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| workflow-name: | ||
| required: true | ||
| type: string | ||
| secrets: | ||
| github-token: | ||
| required: true | ||
| outputs: | ||
| can-skip: | ||
| description: "Whether the workflow can be skipped." | ||
| value: ${{ jobs.check-bypass.outputs.can-skip }} | ||
|
|
||
| jobs: | ||
| check-bypass: | ||
| name: Check bypass | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| env: | ||
| CI_TEAM_MEMBERS: '["SigureMo", "BingooYang", "yongqiangma"]' | ||
| outputs: | ||
| can-skip: ${{ steps.check-bypass.outputs.can-skip }} | ||
| steps: | ||
| - id: check-bypass | ||
| name: Check Bypass | ||
| uses: PFCCLab/ci-bypass@v2 | ||
| with: | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| non-pull-request-event-strategy: "never-skipped" | ||
| type: "composite" | ||
| composite-rule: | | ||
| { | ||
| "any": [ | ||
| { | ||
| "type": "labeled", | ||
| "label": ["skip-ci: ${{ inputs.workflow-name }}", "skip-ci: all"], | ||
| "username": ${{ env.CI_TEAM_MEMBERS }} | ||
| }, | ||
| { | ||
| "type": "commented", | ||
| "comment-pattern": [".*/skip-ci ${{ inputs.workflow-name }}.*", ".*/skip-ci all.*"], | ||
| "username": ${{ env.CI_TEAM_MEMBERS }} | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| name: codestyle-check | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: ["master"] | ||
|
|
||
| jobs: | ||
| check-bypass: | ||
| name: Check bypass | ||
| uses: ./.github/workflows/check-bypass.yml | ||
| with: | ||
| workflow-name: "codestyle" | ||
| secrets: | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| pre-commit: | ||
| name: Run pre-commit checks | ||
| needs: check-bypass | ||
| if: ${{ github.repository_owner == 'PFCCLab' && needs.check-bypass.outputs.can-skip != 'true' }} | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| PR_ID: ${{ github.event.pull_request.number }} | ||
|
|
||
| steps: | ||
| - name: Checkout base repo | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| ref: ${{ github.event.pull_request.base.ref }} | ||
| fetch-depth: 200 | ||
|
|
||
| - name: Merge PR to test branch | ||
| run: | | ||
| git fetch origin pull/${PR_ID}/merge | ||
| git checkout -b test FETCH_HEAD | ||
|
|
||
| - name: Install uv | ||
| uses: astral-sh/setup-uv@v7 | ||
| with: | ||
| python-version: "3.14" | ||
| enable-cache: true | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| uv venv -p 3.14 | ||
| source .venv/bin/activate | ||
| uv pip install cpplint==1.6.0 clang-format==13.0.0 | ||
|
|
||
| - name: Install prek | ||
| run: | | ||
| uv tool install prek | ||
|
|
||
| - name: Run prek | ||
| run: | | ||
| source .venv/bin/activate | ||
| prek run --all-files |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,90 +1,77 @@ | ||
| repos: | ||
| # Common hooks | ||
| - repo: https://github.com/pre-commit/pre-commit-hooks | ||
| rev: v4.1.0 | ||
| # Common hooks | ||
| - repo: https://github.com/pre-commit/pre-commit-hooks | ||
| rev: v4.4.0 | ||
| hooks: | ||
| - id: check-added-large-files | ||
| - id: check-merge-conflict | ||
| - id: check-symlinks | ||
| - id: detect-private-key | ||
| - id: end-of-file-fixer | ||
| - id: trailing-whitespace | ||
| 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)$ | ||
| - repo: https://github.com/Lucas-C/pre-commit-hooks.git | ||
| rev: v1.1.14 | ||
| - id: check-added-large-files | ||
| - id: check-merge-conflict | ||
| - id: check-symlinks | ||
| - id: detect-private-key | ||
| - id: end-of-file-fixer | ||
| - id: sort-simple-yaml | ||
| files: (ops|backward|op_[a-z_]+)\.yaml$ | ||
| - id: trailing-whitespace | ||
| - repo: https://github.com/Lucas-C/pre-commit-hooks.git | ||
| rev: v1.5.1 | ||
| hooks: | ||
| - id: remove-crlf | ||
| - id: remove-tabs | ||
| - id: remove-crlf | ||
| - id: remove-tabs | ||
| name: Tabs remover (C++) | ||
| files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|xpu|kps)$ | ||
| files: \.(c|cc|cxx|cpp|cu|h|cuh|hpp|hxx|xpu|kps)$ | ||
| args: [--whitespaces-count, '2'] | ||
| - id: remove-tabs | ||
| - id: remove-tabs | ||
| name: Tabs remover (Python) | ||
| files: (.*\.(py|bzl)|BUILD|.*\.BUILD|WORKSPACE)$ | ||
| args: [--whitespaces-count, '4'] | ||
| # For Python files | ||
| - repo: https://github.com/psf/black.git | ||
| rev: 22.8.0 | ||
| # For Python files | ||
| - repo: https://github.com/astral-sh/ruff-pre-commit | ||
| rev: v0.14.4 | ||
| hooks: | ||
| - id: black | ||
| files: (.*\.(py|pyi|bzl)|BUILD|.*\.BUILD|WORKSPACE)$ | ||
| - repo: https://github.com/PyCQA/flake8 | ||
| rev: 4.0.1 | ||
| - id: ruff-check | ||
| args: [--fix, --exit-non-zero-on-fix, --no-cache] | ||
| - id: ruff-format | ||
| # For C++ files | ||
| - repo: local | ||
| hooks: | ||
| - id: flake8 | ||
| - repo: https://github.com/PyCQA/autoflake | ||
| rev: v1.7.7 | ||
| hooks: | ||
| - id: autoflake | ||
| args: | ||
| - --in-place | ||
| - --remove-all-unused-imports | ||
| - --ignore-pass-after-docstring | ||
| - --ignore-init-module-imports | ||
| - --exclude=python/paddle/fluid/[!t]**,python/paddle/fluid/tra** | ||
| - repo: local | ||
| hooks: | ||
| - id: pylint-doc-string | ||
| name: pylint | ||
| description: Check python docstring style using docstring_checker. | ||
| entry: bash ./tools/codestyle/pylint_pre_commit.hook | ||
| language: system | ||
| files: \.(py)$ | ||
| # For C++ files | ||
| - repo: local | ||
| hooks: | ||
| - id: clang-format | ||
| - id: clang-format | ||
| name: clang-format | ||
| description: Format files with ClangFormat. | ||
| entry: bash ./tools/codestyle/clang_format.hook -i | ||
| entry: bash ./tools/codestyle/clang_format.sh -i | ||
| language: system | ||
| files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|xpu|kps|mm|m|scpp)$ | ||
| - repo: local | ||
| files: \.(c|cc|cxx|cpp|cu|h|cuh|hpp|hxx|xpu|kps)$ | ||
| - repo: local | ||
| hooks: | ||
| - id: cpplint-cpp-source | ||
| - id: cpplint-cpp-source | ||
| name: cpplint | ||
| description: Check C++ code style using cpplint.py. | ||
| entry: bash ./tools/codestyle/cpplint_pre_commit.hook | ||
| entry: bash ./tools/codestyle/cpplint_pre_commit.sh | ||
| language: system | ||
| files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|scpp)$ | ||
| files: \.(cc|cxx|cpp|cu|h|hpp|hxx)$ | ||
| args: | ||
| - --extensions=c,cc,cxx,cpp,cu,cuh,h,hpp,hxx,kps | ||
| - --filter=-readability/fn_size,-build/include_what_you_use,-build/c++11,-whitespace/parens,-legal/copyright | ||
| - --quiet | ||
| # For CMake files | ||
| - repo: local | ||
| hooks: | ||
| - id: auto-generate-cmakelists | ||
| name: auto-generate-cmakelists | ||
| entry: bash ./tools/gen_ut_cmakelists.hook | ||
| language: system | ||
| files: testslist.csv$ | ||
| - repo: https://github.com/cheshirekow/cmake-format-precommit | ||
| - --extensions=cc,cxx,cpp,cu,cuh,h,hpp,hxx,kps | ||
| - --filter=-readability/fn_size,-build/include_what_you_use,-build/c++11,-whitespace/parens,-legal/copyright | ||
| - --quiet | ||
| # For CMake files | ||
| - repo: https://github.com/cheshirekow/cmake-format-precommit | ||
| rev: v0.6.13 | ||
| hooks: | ||
| - id: cmake-format | ||
| - repo: https://github.com/cmake-lint/cmake-lint | ||
| rev: 1.4.2 | ||
| - id: cmake-format | ||
| - repo: https://github.com/PFCCLab/cmake-lint-paddle | ||
| rev: v1.5.1 | ||
| hooks: | ||
| - id: cmakelint | ||
| - id: cmakelint | ||
| args: [--config=./tools/codestyle/.cmakelintrc] | ||
| # For YAML files | ||
| - repo: https://github.com/PFCCLab/yamlfmt-pre-commit-mirror.git | ||
| rev: v0.16.0 | ||
| hooks: | ||
| - id: yamlfmt | ||
| files: | | ||
| (?x)^( | ||
| \.github/.+\.(yaml|yml)| | ||
| \.pre-commit-config\.yaml| | ||
| \.yamlfmt| | ||
| sgconfig\.yml| | ||
| ci/rules/.+\.yml| | ||
| ci/rule-tests/.+\.yml | ||
| ) | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| formatter: | ||
| indent: 2 | ||
| type: basic | ||
| retain_line_breaks: true | ||
| scan_folded_as_literal: true |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an inconsistency in file patterns between clang-format and cpplint. The clang-format hook (line 41) includes '.c' and '.kps' files in its pattern, but cpplint (line 49) excludes them. Additionally, cpplint's extension arguments (line 51) include 'kps' but the file pattern doesn't match '.kps' files. Consider aligning these patterns to ensure consistent code style checking.