2
2
import os
3
3
import re
4
4
import sys
5
+ from collections import OrderedDict
5
6
6
7
7
8
def is_suppressed (line ):
@@ -18,37 +19,43 @@ def is_suppressed(line):
18
19
return False
19
20
20
21
21
- def warnings_count (filename , verbose ):
22
+ def warnings_count (filename , verbose , direct ):
22
23
rx = re .compile (r'warning[: ]' , re .I )
23
- warnings = 0
24
+ warnings = OrderedDict ()
24
25
suppressed = 0
25
26
total = 0
26
27
for line in open (filename ):
27
28
total += 1
28
29
match = rx .search (line )
30
+ val = line .rstrip ()
29
31
if match :
30
32
if is_suppressed (line ):
31
33
suppressed += 1
32
34
else :
33
- print ("::warning::{}" .format (line .rstrip ()), flush = True )
34
- warnings += 1
35
+ warnings [val ] = warnings .get (val , 0 ) + 1
36
+ if direct :
37
+ print ("::warning::{}" .format (val ), flush = True )
35
38
continue
36
39
if verbose :
37
- print (line .rstrip ())
40
+ print (val )
41
+ if not direct :
42
+ for k , v in warnings .items ():
43
+ print ("::warning::(x {}) {}" .format (v , k ), flush = True )
38
44
return total , suppressed , warnings
39
45
40
46
if __name__ == '__main__' :
41
47
42
48
parser = argparse .ArgumentParser (description = 'Check warnings produced during build' )
43
49
parser .add_argument ('filename' , help = 'Path to the log file.' , default = 'build-log.txt' )
50
+ parser .add_argument ('--direct' , action = 'store_true' , help = 'Print warnings as they are found, do not count duplicates' )
44
51
parser .add_argument ('-v' , '--verbose' , action = 'store_true' , help = 'Print all lines and mark warnings' )
45
52
args = parser .parse_args ()
46
53
47
54
print ("::group::Warning check" , flush = True )
48
- total , suppressed , warnings = warnings_count (args .filename , args .verbose )
55
+ total , suppressed , warnings = warnings_count (args .filename , args .verbose , args . direct )
49
56
print ("::endgroup::" , flush = True )
50
- print ("::notice::Warning stats => total lines: {}, suppressed: {}, warnings: {}" .format (total , suppressed , warnings ), flush = True )
57
+ print ("::notice::Warning stats => total lines: {}, suppressed: {}, warnings: {}" .format (total , suppressed , len ( warnings ) ), flush = True )
51
58
52
- if warnings != 0 :
59
+ if len ( warnings ) != 0 :
53
60
sys .exit (1 )
54
61
sys .exit (0 )
0 commit comments