diff --git a/.github/workflows/clang-format-check.yml b/.github/workflows/clang-format-check.yml deleted file mode 100644 index e0f35c0..0000000 --- a/.github/workflows/clang-format-check.yml +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright (c) Brandon Pacewic -# SPDX-License-Identifier: MIT - -name: Clang Format Check -on: - push: - branches: - - '**' # All branches - pull_request: - branches: - - 'mega' -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - - uses: jannekem/run-python-script-action@v1 - with: - script: | - import os - result = os.system('python3 tests/clang_format_test.py') - if result != 0: - exit(1) - else: - exit(0) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..53a0ffa --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,21 @@ +# Copyright (c) Brandon Pacewic +# SPDX-License-Identifier: MIT + +name: Lint +on: + pull_request: + branches: + - mega +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Check Formatting + run: | + find cpl/inc cpl/src tests/cpl -regex '.*\.\(cpp\|h\|hpp\)' -exec clang-format -i --style=file {} + + git diff --exit-code || (echo 'Formatting issues found. Please run clang-format.' && exit 1) diff --git a/tests/clang_format_test.py b/tests/clang_format_test.py deleted file mode 100644 index 7abbd24..0000000 --- a/tests/clang_format_test.py +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright (c) Brandon Pacewic -# SPDX-License-Identifier: MIT - -import os -import sys - -FILES_DIRS = ["cpl/inc", "cpl/src", "tests/cpl"] -FILE_TARGETS = (".cpp", ".h", ".hpp") -FORMAT_COMMAND = "clang-format -i -style=file" - -def main(): - if not os.path.exists(os.path.join(os.getcwd(), ".clang-format")): - while True: - os.chdir("../") - if os.path.exists(os.path.join(os.getcwd(), ".clang-format")): - print(f"Found root of project at {os.getcwd()}") - break - - files = [] - for file_dir in FILES_DIRS: - for root, dirs, file_names in os.walk(file_dir): - for file_name in file_names: - if file_name.endswith(FILE_TARGETS): - files.append(os.path.join(root, file_name)) - - for file in files: - previous_file_state = open(file, "r").read() - os.system(f"{FORMAT_COMMAND} {file}") - new_file_state = open(file, "r").read() - - if previous_file_state != new_file_state: - print(f"File {file} is not formatted correctly!") - sys.exit(1) - - print("All files formatted correctly") - - -if __name__ == "__main__": - main()