Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 10 additions & 46 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,12 @@ on:

jobs:

clang_format_check:
pre_commit:
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use pre-commit for CI to shorten the CI file.


runs-on: ubuntu-latest

if: ${{ github.event_name != 'schedule' || (github.event_name == 'schedule' && vars.MMGH_NIGHTLY == 'enable') }}

strategy:
matrix:
path:
- 'cpp'
- 'gtests'

steps:

- uses: actions/checkout@v6
Expand All @@ -28,29 +22,15 @@ jobs:
run: |
echo "github.event_name: ${{ github.event_name }}"

- name: Add 8G swap (Ubuntu)
# Prevent hitting runner's resource limits
if: runner.os == 'Linux'
run: |
# Remove /swapfile first to avoid "fallocate: Text file busy" error
sudo swapoff -a
sudo rm -f /swapfile
sudo fallocate -l 8G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
free -h

- name: Run clang-format style check for C/C++/Protobuf programs.
uses: jidicula/clang-format-action@v4.16.0
- uses: actions/setup-python@v5
with:
clang-format-version: '20'
check-path: ${{ matrix.path }}
fallback-style: 'LLVM' # optional
python-version: '3.x'

- uses: pre-commit/action@v3.0.1

tidy_flake8:
clang_tidy:

name: Run clang-tidy and flake8 on ${{ matrix.os }}
name: Run clang-tidy on ${{ matrix.os }}

if: ${{ github.event_name != 'schedule' || (github.event_name == 'schedule' && vars.MMGH_NIGHTLY == 'enable') }}

Expand Down Expand Up @@ -103,15 +83,6 @@ jobs:
restore-keys: ${{ runner.os }}-tidy-${{ matrix.cmake_build_type }}
create-symlink: true

- name: make cinclude (check_include)
run: make cinclude

- name: make checkascii (check ASCII-only characters)
run: make checkascii

- name: make checktws (check trailing whitespace)
run: make checktws

- name: make pilot USE_PYTEST_HELPER_BINDING=OFF
run: |
make pilot \
Expand All @@ -135,22 +106,15 @@ jobs:
CMAKE_BUILD_TYPE=${{ matrix.cmake_build_type }} \
CMAKE_ARGS="-DPYTHON_EXECUTABLE=$(which python3) -DUSE_PYTEST_HELPER_BINDING=ON"

- name: make flake8
run: |
make flake8 \
${JOB_MAKE_ARGS} \
CMAKE_BUILD_TYPE=${{ matrix.cmake_build_type }} \
CMAKE_ARGS="-DPYTHON_EXECUTABLE=$(which python3)"

send_email_on_failure:
needs: [clang_format_check, tidy_flake8]
needs: [pre_commit, clang_tidy]
# Run if any of the dependencies failed in master branch
if: ${{ always() && contains(needs.*.result, 'failure') && github.ref_name == 'master' && github.event.repository.fork == false }}
uses: ./.github/workflows/send_email_on_fail.yml
with:
job_results: |
- clang_format_check: ${{ needs.clang_format_check.result }}
- tidy_flake8: ${{ needs.tidy_flake8.result }}
- pre_commit: ${{ needs.pre_commit.result }}
- clang_tidy: ${{ needs.clang_tidy.result }}
secrets:
EMAIL_USERNAME: ${{ secrets.EMAIL_USERNAME }}
EMAIL_PASSWORD: ${{ secrets.EMAIL_PASSWORD }}
50 changes: 50 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright (c) 2026, An-Chi Liu <phy.tiger@gmail.com>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI files do not need copyright.

# BSD-style license; see COPYING
#
# See https://pre-commit.com for more information
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure an additional dependency for running the check is good.

# Run `pre-commit install` to set up the git hooks.
# Run `pre-commit run --all-files` to check the entire project.
# Run `pre-commit autoupdate` to update hook versions.
repos:
# C++ formatting
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v20.1.0
hooks:
- id: clang-format
files: ^(cpp|gtests)/.*\.[ch]pp$

# Python linting
- repo: https://github.com/PyCQA/flake8
rev: 7.3.0
hooks:
- id: flake8
exclude: ^(thirdparty|tmp|_deps)/

# Project-specific checks
- repo: local
hooks:
# Ensure C++ files use angle brackets for includes, not quotes
- id: cinclude
name: check-include-quotes
description: Ensure C++ includes use angle brackets, not quotes
entry: '#include\s*"'
language: pygrep
files: ^cpp/

# Ensure source files contain only ASCII characters
- id: checkascii
name: check-ascii
description: Ensure source files contain only ASCII characters
entry: python3 contrib/lint/check_ascii.py
language: system
files: \.(py|cpp|hpp|c|h|cxx|hxx|sh|yml|yaml)$|(^|/)(CMakeLists\.txt|[Mm]akefile)$
exclude: ^(tmp|_deps|build)/

# Ensure source files have no trailing whitespace
- id: checktws
name: check-trailing-whitespace
description: Ensure source files have no trailing whitespace
entry: python3 contrib/lint/check_ascii.py --check-tws
language: system
files: \.(py|cpp|hpp|c|h|cxx|hxx|sh|yml|yaml)$|(^|/)(CMakeLists\.txt|[Mm]akefile)$
exclude: ^(tmp|_deps|build)/
14 changes: 14 additions & 0 deletions contrib/prompt/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ make flake8 # Python style check
make checkascii # ASCII character check
```

### Pre-commit
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let AI use pre-commit before it pushes the code.

```bash
# Run all pre-commit hooks on staged files
pre-commit run

# Run all pre-commit hooks on the entire project
pre-commit run --all-files
```

**IMPORTANT**: Always run `pre-commit run --all-files` before committing and
pushing changes. This ensures clang-format, flake8, include-quote checks,
ASCII-only characters, and trailing whitespace checks all pass locally before
CI runs.

### Cleanup
```bash
# Clean build artifacts
Expand Down
Loading