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