|
38 | 38 | # be able to catch any errors for other platforms. |
39 | 39 | run: cmake -B build -S . -DCMAKE_EXPORT_COMPILE_COMMANDS=ON |
40 | 40 | - name: Lint modified files |
41 | | - shell: python |
42 | | - run: | |
43 | | - import os |
44 | | - import subprocess |
45 | | - import sys |
46 | | -
|
47 | | - print("Python {}.{}.{}".format(*sys.version_info)) # Python 3.8 |
48 | | - with open("git_diff.txt") as in_file: |
49 | | - modified_files = sorted(in_file.read().splitlines()) |
50 | | - print("{} files were modified.".format(len(modified_files))) |
51 | | -
|
52 | | - cpp_exts = tuple(".c .c++ .cc .cpp .cu .cuh .cxx .h .h++ .hh .hpp .hxx".split()) |
53 | | - cpp_files = [file for file in modified_files if file.lower().endswith(cpp_exts)] |
54 | | - print(f"{len(cpp_files)} C++ files were modified.") |
55 | | - if not cpp_files: |
56 | | - sys.exit(0) |
57 | | -
|
58 | | - subprocess.run(["clang-tidy", "--fix", "-p=build", "--extra-arg=-std=c++11", *cpp_files, "--"], |
59 | | - check=True, text=True, stderr=subprocess.STDOUT) |
60 | | -
|
61 | | - subprocess.run(["clang-format", "-i", "-style=file", *cpp_files], |
62 | | - check=True, text=True, stderr=subprocess.STDOUT) |
63 | | -
|
64 | | - upper_files = [file for file in cpp_files if file != file.lower()] |
65 | | - if upper_files: |
66 | | - print(f"{len(upper_files)} files contain uppercase characters:") |
67 | | - print("\n".join(upper_files) + "\n") |
68 | | -
|
69 | | - space_files = [file for file in cpp_files if " " in file or "-" in file] |
70 | | - if space_files: |
71 | | - print(f"{len(space_files)} files contain space or dash characters:") |
72 | | - print("\n".join(space_files) + "\n") |
73 | | -
|
74 | | - nodir_files = [file for file in cpp_files if file.count(os.sep) != 1] |
75 | | - if nodir_files: |
76 | | - print(f"{len(nodir_files)} files are not in one and only one directory:") |
77 | | - print("\n".join(nodir_files) + "\n") |
78 | | -
|
79 | | - bad_files = len(upper_files + space_files + nodir_files) |
80 | | - if bad_files: |
81 | | - sys.exit(bad_files) |
| 41 | + shell: bash |
| 42 | + run: python3 scripts/file_linter.py |
82 | 43 | - name: Commit and push changes |
83 | 44 | run: | |
84 | 45 | git diff DIRECTORY.md |
|
0 commit comments