forked from ArtificialAmateur/cpp-linter-action
-
Notifications
You must be signed in to change notification settings - Fork 2
/
find_changed_files.py
58 lines (43 loc) · 1.63 KB
/
find_changed_files.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import subprocess
import sys
def find_files(SHAs=None):
diff_command = ['git', 'diff', '--name-only']
if SHAs is not None:
diff_command += SHAs
stdout, stderr = subprocess.Popen(diff_command,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT).communicate()
if stderr is not None:
raise Exception('git diff encountered an error')
files = [f for f in stdout.decode('utf-8').strip().split('\n')
if f[:6] == 'Source']
print(files)
# look for whether any files have changed in these directories
flag_dirs = {'diffusion': ('USE_DIFFUSION', 'science/flame_wave'),
'gravity': ('USE_GRAVITY', 'science/flame_wave'),
'mhd': ('USE_MHD', 'mhd_tests/BrioWu'),
'radiation': ('USE_RADIATION', 'radiation_tests/Rad2Tshock'),
'sdc': ('USE_TRUE_SDC', 'reacting_tests/reacting_convergence')}
# see which directories contain changed files
changed_directories = set()
for f in files:
d = f.split('/')[1]
if d in flag_dirs:
changed_directories.add(d)
problems = {}
for d in changed_directories:
flag, prob = flag_dirs[d]
if prob in problems:
problems[prob] += f' {flag}=TRUE'
else:
problems[prob] = f'{flag}=TRUE'
# no special flags, use default
if not problems:
problems['science/flame_wave'] = ""
print(problems)
return problems
if __name__ == '__main__':
if len(sys.argv) > 1:
find_files(sys.argv[1:])
else:
find_files()