Skip to content

Commit 7a371e0

Browse files
authored
Run cpplint only on files that differ from master (#4)
* Run cpplint only on files that differ from master GitHub Action that runs cpplint only on those files that have been modified vs. origin/master This allows for gradual compliance with cpplint as only files added or modified are checked. Other _optional_ filepath verifications are commented out at the end of this file. * Update cpplint_modified_files.yml
1 parent c1d2b3c commit 7a371e0

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# GitHub Action that enables a repo to achieve gradual compliance with cpplint by
2+
# linting only those files that have been added or modified (vs. origin/master).
3+
# 1. runs cpplint only on those files that have been modified vs. origin/master.
4+
# 2. compiles with g++ only those files that have been modified vs. origin/master.
5+
# 3. other optional filepath verifications may be commented out at the end of this file.
6+
7+
name: cpplint_modified_files
8+
on: [push, pull_request]
9+
jobs:
10+
cpplint_modified_files:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v1
14+
- uses: actions/setup-python@v1
15+
- shell: python # Show the version of shell: python and then upgrade shell: python to Python 3.8
16+
run: import sys ; print("Python {}.{}.{}".format(*sys.version_info)) # Legacy Python :-(
17+
- run: sudo update-alternatives --install /usr/bin/python python ${pythonLocation}/bin/python3.8 10
18+
- run: python -m pip install cpplint
19+
- run: git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
20+
- run: git diff origin/master --name-only > git_diff.txt
21+
- name: cpplint_modified_files
22+
shell: python
23+
run: |
24+
import os
25+
import subprocess
26+
import sys
27+
28+
print("Python {}.{}.{}".format(*sys.version_info)) # Python 3.8
29+
with open("git_diff.txt") as in_file:
30+
modified_files = sorted(in_file.read().splitlines())
31+
print("{} files were modified.".format(len(modified_files)))
32+
33+
cpp_exts = tuple(".c .c++ .cc .cpp .cu .cuh .cxx .h .h++ .hh .hpp .hxx".split())
34+
cpp_files = [file for file in modified_files if file.lower().endswith(cpp_exts)]
35+
print(f"{len(cpp_files)} C++ files were modified.")
36+
if not cpp_files:
37+
sys.exit(0)
38+
39+
print("cpplint:")
40+
subprocess.run(["cpplint", "--filter=-legal/copyright"] + cpp_files, check=True, text=True)
41+
42+
print("g++:")
43+
# compile_exts = tuple(".c .c++ .cc .cpp .cu .cxx".split())
44+
# compile_files = [file for file in cpp_files if file.lower().endswith(compile_exts)]
45+
subprocess.run(["g++"] + cpp_files, check=True, text=True)
46+
47+
# upper_files = [file for file in cpp_files if file != file.lower()]
48+
# if upper_files:
49+
# print(f"{len(upper_files)} files contain uppercase characters:")
50+
# print("\n".join(upper_files) + "\n")
51+
52+
# space_files = [file for file in cpp_files if " " in file or "-" in file]
53+
# if space_files:
54+
# print(f"{len(space_files)} files contain space or dash characters:")
55+
# print("\n".join(space_files) + "\n")
56+
57+
# nodir_files = [file for file in cpp_files if file.count(os.sep) != 1]
58+
# if nodir_files:
59+
# print(f"{len(nodir_files)} files are not in one and only one directory:")
60+
# print("\n".join(nodir_files) + "\n")
61+
62+
# bad_files = len(upper_files + space_files + nodir_files)
63+
# if bad_files:
64+
# sys.exit(bad_files)

0 commit comments

Comments
 (0)