Skip to content

Commit d86b026

Browse files
Add ruby checkers
Signed-off-by: Andy Scherzinger <[email protected]>
1 parent 79d631b commit d86b026

File tree

2 files changed

+234
-0
lines changed

2 files changed

+234
-0
lines changed

scripts/analysis/lint-up.rb

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
## Script from https://github.com/tir38/android-lint-entropy-reducer at 07.05.2017
2+
# adapts to drone, use git username / token as parameter
3+
4+
# TODO cleanup this script, it has a lot of unused stuff
5+
6+
7+
Encoding.default_external = Encoding::UTF_8
8+
Encoding.default_internal = Encoding::UTF_8
9+
10+
puts "=================== starting Android Lint Entropy Reducer ===================="
11+
12+
# ======================== SETUP ============================
13+
14+
# User name for git commits made by this script.
15+
TRAVIS_GIT_USERNAME = String.new("Drone CI server")
16+
17+
# File name and relative path of generated Lint report. Must match build.gradle file:
18+
# lintOptions {
19+
# htmlOutput file("[FILE_NAME].html")
20+
# }
21+
LINT_REPORT_FILE = String.new("app/build/reports/lint/lint.html")
22+
23+
# File name and relative path of previous results of this script.
24+
PREVIOUS_LINT_RESULTS_FILE=String.new("scripts/analysis/lint-results.txt")
25+
26+
# Flag to evaluate warnings. true = check warnings; false = ignore warnings
27+
CHECK_WARNINGS = true
28+
29+
# File name and relative path to custom lint rules; Can be null or "".
30+
CUSTOM_LINT_FILE = String.new("")
31+
32+
# ================ SETUP DONE; DON'T TOUCH ANYTHING BELOW ================
33+
34+
require 'fileutils'
35+
require 'pathname'
36+
require 'open3'
37+
38+
# since we need the xml-simple gem, and we want this script self-contained, let's grab it just when we need it
39+
begin
40+
gem "xml-simple"
41+
rescue LoadError
42+
system("gem install --user-install xml-simple")
43+
Gem.clear_paths
44+
end
45+
46+
require 'xmlsimple'
47+
48+
# add custom Lint jar
49+
if !CUSTOM_LINT_FILE.nil? &&
50+
CUSTOM_LINT_FILE.length > 0
51+
52+
ENV["ANDROID_LINT_JARS"] = Dir.pwd + "/" + CUSTOM_LINT_FILE
53+
puts "adding custom lint rules to default set: "
54+
puts ENV["ANDROID_LINT_JARS"]
55+
end
56+
57+
# run Lint
58+
puts "running Lint..."
59+
system './gradlew clean lintGplayDebug 1>/dev/null'
60+
61+
# confirm that Lint ran w/out error
62+
result = $?.to_i
63+
if result != 0
64+
puts "FAIL: failed to run ./gradlew clean lintGplayDebug"
65+
exit 1
66+
end
67+
68+
# find Lint report file
69+
lint_reports = Dir.glob(LINT_REPORT_FILE)
70+
if lint_reports.length == 0
71+
puts "Lint HTML report not found."
72+
exit 1
73+
end
74+
lint_report = String.new(lint_reports[0])
75+
76+
# find error/warning count string in HTML report
77+
error_warning_string = ""
78+
File.open lint_report do |file|
79+
error_warning_string = file.find { |line| line =~ /([0-9]* error[s]? and )?[0-9]* warning[s]?/ }
80+
end
81+
82+
# find number of errors
83+
error_string = error_warning_string.match(/[0-9]* error[s]?/)
84+
85+
if (error_string.nil?)
86+
current_error_count = 0
87+
else
88+
current_error_count = error_string[0].match(/[0-9]*/)[0].to_i
89+
end
90+
91+
puts "found errors: " + current_error_count.to_s
92+
93+
# find number of warnings
94+
if CHECK_WARNINGS == true
95+
warning_string = error_warning_string.match(/[0-9]* warning[s]?/)[0]
96+
current_warning_count = warning_string.match(/[0-9]*/)[0].to_i
97+
puts "found warnings: " + current_warning_count.to_s
98+
end
99+
100+
# get previous error and warning counts from last successful build
101+
102+
previous_results = false
103+
104+
previous_lint_reports = Dir.glob(PREVIOUS_LINT_RESULTS_FILE)
105+
if previous_lint_reports.nil? ||
106+
previous_lint_reports.length == 0
107+
108+
previous_lint_report = File.new(PREVIOUS_LINT_RESULTS_FILE, "w") # create for writing to later
109+
else
110+
previous_lint_report = String.new(previous_lint_reports[0])
111+
112+
previous_error_warning_string = ""
113+
File.open previous_lint_report do |file|
114+
previous_error_warning_string = file.find { |line| line =~ /([0-9]* error[s]? and )?[0-9]* warning[s]?/ }
115+
end
116+
117+
unless previous_error_warning_string.nil?
118+
previous_results = true
119+
120+
previous_error_string = previous_error_warning_string.match(/[0-9]* error[s]?/)
121+
if previous_error_string.nil?
122+
previous_error_string = "0 errors"
123+
else
124+
previous_error_string = previous_error_string[0]
125+
end
126+
previous_error_count = previous_error_string.match(/[0-9]*/)[0].to_i
127+
puts "previous errors: " + previous_error_count.to_s
128+
129+
if CHECK_WARNINGS == true
130+
previous_warning_string = previous_error_warning_string.match(/[0-9]* warning[s]?/)
131+
if previous_warning_string.nil?
132+
previous_warning_string = "0 warnings"
133+
else
134+
previous_warning_string = previous_warning_string[0]
135+
end
136+
previous_warning_count = previous_warning_string.match(/[0-9]*/)[0].to_i
137+
puts "previous warnings: " + previous_warning_count.to_s
138+
end
139+
end
140+
end
141+
142+
# compare previous error count with current error count
143+
if previous_results == true &&
144+
current_error_count > previous_error_count
145+
puts "FAIL: error count increased"
146+
exit 1
147+
end
148+
149+
# compare previous warning count with current warning count
150+
if CHECK_WARNINGS == true &&
151+
previous_results == true &&
152+
current_warning_count > previous_warning_count
153+
154+
puts "FAIL: warning count increased"
155+
exit 1
156+
end
157+
158+
# check if warning and error count stayed the same
159+
if previous_results == true &&
160+
current_error_count == previous_error_count &&
161+
current_warning_count == previous_warning_count
162+
163+
puts "SUCCESS: count stayed the same"
164+
exit 2
165+
end
166+
167+
# either error count or warning count DECREASED
168+
169+
# write new results to file (will overwrite existing, or create new)
170+
File.write(previous_lint_report, "DO NOT TOUCH; GENERATED BY DRONE\n" + error_warning_string)
171+
172+
# update git user name and email for this script
173+
system ("git config --local user.name 'github-actions'")
174+
system ("git config --local user.email '[email protected]'")
175+
176+
# add previous Lint result file to git
177+
system ('git add ' + PREVIOUS_LINT_RESULTS_FILE)
178+
179+
# commit changes
180+
system('git commit -sm "Analysis: update lint results to reflect reduced error/warning count"')
181+
182+
# push to origin
183+
system ('git push')
184+
185+
puts "SUCCESS: count was reduced"
186+
exit 0 # success

scripts/analysis/spotbugs-up.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
## Script originally from https://github.com/tir38/android-lint-entropy-reducer at 07.05.2017
2+
# heavily modified since then
3+
4+
Encoding.default_external = Encoding::UTF_8
5+
Encoding.default_internal = Encoding::UTF_8
6+
7+
puts "=================== starting Android Spotbugs Entropy Reducer ===================="
8+
9+
# get args
10+
base_branch = ARGV[0]
11+
12+
require 'fileutils'
13+
require 'pathname'
14+
require 'open3'
15+
16+
# run Spotbugs
17+
puts "running Spotbugs..."
18+
system './gradlew spotbugsGplayDebug 1>/dev/null 2>&1'
19+
20+
# find number of warnings
21+
current_warning_count = `./scripts/analysis/spotbugsSummary.py --total`.to_i
22+
puts "found warnings: " + current_warning_count.to_s
23+
24+
# get warning counts from target branch
25+
previous_xml = "/tmp/#{base_branch}.xml"
26+
previous_results = File.file?(previous_xml)
27+
28+
if previous_results == true
29+
previous_warning_count = `./scripts/analysis/spotbugsSummary.py --total --file #{previous_xml}`.to_i
30+
puts "previous warnings: " + previous_warning_count.to_s
31+
end
32+
33+
# compare previous warning count with current warning count
34+
if previous_results == true && current_warning_count > previous_warning_count
35+
puts "FAIL: warning count increased"
36+
exit 1
37+
end
38+
39+
# check if warning and error count stayed the same
40+
if previous_results == true && current_warning_count == previous_warning_count
41+
puts "SUCCESS: count stayed the same"
42+
exit 0
43+
end
44+
45+
# warning count DECREASED
46+
if previous_results == true && current_warning_count < previous_warning_count
47+
puts "SUCCESS: count decreased from " + previous_warning_count.to_s + " to " + current_warning_count.to_s
48+
end

0 commit comments

Comments
 (0)