From 030b3e17f14af22aee7703c4adb5974ddd2d0815 Mon Sep 17 00:00:00 2001 From: Yanis002 <35189056+Yanis002@users.noreply.github.com> Date: Fri, 14 Feb 2025 15:24:31 +0100 Subject: [PATCH] add format rule and fix CI --- .github/workflows/ci.yml | 31 ------------------------------- .github/workflows/format.yml | 32 ++++++++++++++++++++++++++++++++ .pre-commit-config.yaml | 24 ------------------------ tools/configure.py | 18 ++++++++++++++++++ tools/requirements.txt | 2 +- 5 files changed, 51 insertions(+), 56 deletions(-) delete mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/format.yml delete mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index e24acd17..00000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: CI -on: - push: - branches: - - main - pull_request: -jobs: - lint: - name: Linting/style checks - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.13' - check-latest: true - - - name: Install pre-commit - run: pip install pre-commit - - - name: Cache pre-commit hooks - uses: actions/cache@v4 - with: - path: ~/.cache/pre-commit/ - # Invalidate the cache if the pre-commit config changes or the Python version changes - key: pre-commit-cache|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }} - - - name: Run pre-commit checks - run: pre-commit run --all-files --verbose diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 00000000..9aadbd32 --- /dev/null +++ b/.github/workflows/format.yml @@ -0,0 +1,32 @@ +name: Check Format + +on: + push: + pull_request: + +jobs: + format: + runs-on: ubuntu-24.04 + defaults: + run: + shell: bash + + steps: + # Checkout the repository (shallow clone) + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: recursive + + # Set Git config + - name: Git config + run: git config --global --add safe.directory "$GITHUB_WORKSPACE" + + # Run formatter + - name: Run clang-format + run: find include libs src -name *.h -o -name *.c -o -name *.hpp -o -name *.cpp | xargs clang-format -i + + # Cancel if there's a diff + - name: Check status + run: git diff --name-only --exit-code diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml deleted file mode 100644 index 8b2ebb4c..00000000 --- a/.pre-commit-config.yaml +++ /dev/null @@ -1,24 +0,0 @@ -repos: - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v5.0.0 - hooks: - - id: check-case-conflict - - id: check-executables-have-shebangs - - id: check-illegal-windows-names - - id: check-json - - id: check-merge-conflict - - id: check-yaml - args: - - --allow-multiple-documents - - id: debug-statements - - id: destroyed-symlinks - - id: mixed-line-ending - - id: requirements-txt-fixer - - id: trailing-whitespace - args: - - --markdown-linebreak-ext=md - - - repo: https://github.com/pre-commit/mirrors-clang-format - rev: v19.1.5 - hooks: - - id: clang-format diff --git a/tools/configure.py b/tools/configure.py index dffbc9f4..407690f1 100644 --- a/tools/configure.py +++ b/tools/configure.py @@ -100,6 +100,11 @@ match platform.machine().lower(): PYTHON = sys.executable +FORMAT_SETTINGS = { + "version": "19", + "folders": ["include", "libs", "src"], + "files": ["*.h", "*.c", "*.hpp", "*.cpp"], +} def main(): @@ -186,6 +191,13 @@ def main(): ) n.newline() + find_cmd = f"find {' '.join(FORMAT_SETTINGS['folders'])} {' -o '.join(f'-name {f}' for f in FORMAT_SETTINGS['files'])}" + n.rule( + name="format_exec", + command=f"{find_cmd} | xargs clang-format-{FORMAT_SETTINGS['version']} -i" + ) + n.newline() + game_build = build_path / game_version game_extract = extract_path / game_version @@ -266,6 +278,12 @@ def add_mwld_and_rom_builds(n: ninja_syntax.Writer, game_build: Path, game_confi ) n.newline() + n.build( + # inputs="format_exec", + rule="format_exec", + outputs="format", + ) + n.newline() def add_mwcc_builds(n: ninja_syntax.Writer, game_version: str, game_build: Path, mwcc_implicit: list[Path]): for source_file in get_c_cpp_files([src_path, libs_path]): diff --git a/tools/requirements.txt b/tools/requirements.txt index c0988481..7edbb58e 100644 --- a/tools/requirements.txt +++ b/tools/requirements.txt @@ -1,2 +1,2 @@ -requests pyperclip +requests