File tree Expand file tree Collapse file tree 3 files changed +60
-0
lines changed Expand file tree Collapse file tree 3 files changed +60
-0
lines changed Original file line number Diff line number Diff line change 11
11
build /
12
12
* /build /
13
13
out /
14
+
15
+ # Python
16
+ .mypy_cache
17
+ * .pyc
18
+ __pycache__
Original file line number Diff line number Diff line change 94
94
language : script
95
95
files : \.md$
96
96
exclude : vendor\/.*$
97
+
98
+ - id : check-terratest-skip-env
99
+ name : check-terratest-skip-env
100
+ description : Check all go source files for any uncommented os.Setenv calls setting a terratest SKIP environment.
101
+ entry : ./hooks/check_skip_env.py
102
+ language : python
103
+ files : \.go$
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python
2
+ import re
3
+ import sys
4
+ import argparse
5
+ import logging
6
+
7
+
8
+ logging .basicConfig (format = '%(asctime)s [%(levelname)s] %(message)s' , level = logging .INFO )
9
+
10
+
11
+ def has_setenv_skip (fpath ):
12
+ with open (fpath ) as f :
13
+ for line in f :
14
+ if re .match (r'^\s+os.Setenv\(\"SKIP_' , line ):
15
+ return True
16
+ return False
17
+
18
+
19
+ def parse_args ():
20
+ parser = argparse .ArgumentParser (
21
+ description = (
22
+ 'A CLI for checking to make sure no uncommented os.Setenv calls are '
23
+ 'committed in test golang files. Each positional argument should be a golang source file.'
24
+ ),
25
+ )
26
+ parser .add_argument (
27
+ 'files' ,
28
+ metavar = 'FILE' ,
29
+ type = str ,
30
+ nargs = '+' ,
31
+ help = 'The file to check.' ,
32
+ )
33
+ args = parser .parse_args ()
34
+ return args
35
+
36
+
37
+ def main ():
38
+ args = parse_args ()
39
+ files_with_setenv_skip = [fpath for fpath in args .files if has_setenv_skip (fpath )]
40
+ if files_with_setenv_skip :
41
+ logging .error ('Found files with os.Setenv calls setting terratest SKIP environment variables.' )
42
+ for f in files_with_setenv_skip :
43
+ logging .error ('- {}' .format (f ))
44
+ sys .exit (1 )
45
+
46
+
47
+ if __name__ == '__main__' :
48
+ main ()
You can’t perform that action at this time.
0 commit comments