Sfoglia il codice sorgente

Merge pull request #3466 from nextcloud/failonFindbugs

Fail on findbugs
Andy Scherzinger 6 anni fa
parent
commit
dd9da32bc4

+ 13 - 3
scripts/analysis/analysis-wrapper.sh

@@ -14,13 +14,14 @@ repository="android"
 ruby scripts/analysis/lint-up.rb $1 $2 $3
 lintValue=$?
 
+ruby scripts/analysis/findbugs-up.rb $1 $2 $3
+findbugsValue=$?
+
 # exit codes:
 # 0: count was reduced
 # 1: count was increased
 # 2: count stayed the same
 
-./gradlew findbugs
-
 echo "Branch: $3"
 
 if [ $3 = $stableBranch ]; then
@@ -100,7 +101,16 @@ else
     findbugsResultNew=$(sed -n "/<h1>Summary<\/h1>/,/<h1>Warnings<\/h1>/p" build/reports/findbugs/findbugs.html |head -n-1 | sed s'/<\/a>//'g | sed s'/<a.*>//'g | sed s"#Summary#<a href=\"https://www.kaminsky.me/nc-dev/$repository-findbugs/$6.html\">FindBugs</a> (new)#" | tr "\"" "\'" | tr -d "\n")
     findbugsResultOld=$(curl 2>/dev/null https://www.kaminsky.me/nc-dev/$repository-findbugs/findbugs-summary-$stableBranch.html | tr "\"" "\'" | tr -d "\r\n" | sed s"#FindBugs#<a href=\"https://www.kaminsky.me/nc-dev/$repository-findbugs/$stableBranch.html\">FindBugs</a>#" | tr "\"" "\'" | tr -d "\n")
 
-    curl -u $1:$2 -X POST https://api.github.com/repos/nextcloud/android/issues/$7/comments -d "{ \"body\" : \"$lintResult $findbugsResultNew $findbugsResultOld $checkLibraryMessage \" }"
+
+    if ( [ $lintValue -eq 1 ] ) ; then
+        lintMessage="<h1>Lint increased!</h1>"
+    fi
+
+    if ( [ $findbugsValue -eq 1 ] ) ; then
+        findbugsMessage="<h1>Findbugs increased!</h1>"
+    fi
+
+    curl -u $1:$2 -X POST https://api.github.com/repos/nextcloud/android/issues/$7/comments -d "{ \"body\" : \"$lintResult $findbugsResultNew $findbugsResultOld $checkLibraryMessage $lintMessage $findbugsMessage \" }"
 
     if [ $checkLibrary -eq 1 ]; then
         exit 1

+ 1 - 0
scripts/analysis/findbugs-results.txt

@@ -0,0 +1 @@
+544

+ 130 - 0
scripts/analysis/findbugs-up.rb

@@ -0,0 +1,130 @@
+## Script from https://github.com/tir38/android-lint-entropy-reducer at 07.05.2017
+# adapts to drone, use git username / token as parameter
+
+Encoding.default_external = Encoding::UTF_8
+Encoding.default_internal = Encoding::UTF_8
+
+puts "=================== starting Android FindBugs Entropy Reducer ===================="
+
+# get args
+git_user, git_token, git_branch = ARGV
+
+# ========================  SETUP ============================
+
+# User name for git commits made by this script.
+TRAVIS_GIT_USERNAME = String.new("Drone CI server")
+
+# File name and relative path of generated FindBugs report. Must match build.gradle file:
+#   lintOptions {
+#       htmlOutput file("[FILE_NAME].html")
+#   }
+FINDBUGS_REPORT_FILE = String.new("build/reports/findbugs/findbugs.html")
+
+# File name and relative path of previous results of this script.
+PREVIOUS_FINDBUGS_RESULTS_FILE=String.new("scripts/analysis/findbugs-results.txt")
+
+# Flag to evaluate warnings. true = check warnings; false = ignore warnings
+CHECK_WARNINGS = true
+
+# File name and relative path to custom FindBugs rules; Can be null or "".
+CUSTOM_FINDBUGS_FILE = String.new("")
+
+# ================ SETUP DONE; DON'T TOUCH ANYTHING BELOW  ================
+
+require 'fileutils'
+require 'pathname'
+require 'open3'
+
+# since we need the xml-simple gem, and we want this script self-contained, let's grab it just when we need it
+begin
+    gem "xml-simple"
+    rescue LoadError
+    system("gem install xml-simple")
+    Gem.clear_paths
+end
+
+require 'xmlsimple'
+
+# run FindBugs
+puts "running FindBugs..."
+system './gradlew findbugs'
+
+# find FindBugs report file
+findbugs_reports = Dir.glob(FINDBUGS_REPORT_FILE)
+if findbugs_reports.length == 0
+    puts "Findbugs HTML report not found."
+    exit 1
+end
+findbugs_report = String.new(findbugs_reports[0])
+
+# find number of warnings
+current_warning_count = `grep -A 3 "<b>Total</b>" build/reports/findbugs/findbugs.html | tail -n1 | cut -f2 -d">" | cut -f1 -d"<"`.to_i
+puts "found warnings: " + current_warning_count.to_s
+
+# get warning counts from last successful build
+
+previous_results = false
+
+previous_findbugs_reports = Dir.glob(PREVIOUS_FINDBUGS_RESULTS_FILE)
+if previous_findbugs_reports.nil? || previous_findbugs_reports.length == 0
+    previous_findbugs_report = File.new(PREVIOUS_FINDBUGS_RESULTS_FILE, "w") # create for writing to later
+else
+    previous_findbugs_report = String.new(previous_findbugs_reports[0])
+
+    previous_warning_count = File.open(previous_findbugs_report, &:readline).match(/[0-9]*/)[0].to_i
+
+    if previous_warning_count.nil?
+        previous_results = false
+    else
+        previous_results = true
+
+        puts "previous warnings: " + previous_warning_count.to_s
+    end
+end
+
+# compare previous warning count with current warning count
+if previous_results == true && current_warning_count > previous_warning_count
+    puts "FAIL: warning count increased"
+    exit 1
+end
+
+# check if warning and error count stayed the same
+if  previous_results == true && current_warning_count == previous_warning_count
+    puts "SUCCESS: count stayed the same"
+    exit 2
+end
+
+# warning count DECREASED
+puts "SUCCESS: count decreased from " + previous_warning_count.to_s + " to " + current_warning_count.to_s
+
+# write new results to file (will overwrite existing, or create new)
+File.write(previous_findbugs_report, current_warning_count)
+
+# push changes to github (if this script is run locally, we don't want to overwrite git username and email, so save temporarily)
+previous_git_username, _ = Open3.capture2('git config user.name')
+previous_git_username = previous_git_username.strip
+
+previous_git_email, _ = Open3.capture3('git config user.email')
+previous_git_email = previous_git_email.strip
+
+# update git user name and email for this script
+system ("git config --local user.name '"  + git_user + "'")
+system ("git config --local user.email '.'") # set email blank
+system ("git remote rm origin")
+system ("git remote add origin https://" + git_user + ":" + git_token + "@github.com/nextcloud/android")
+
+# add previous FindBugs result file to git
+system ('git add ' + PREVIOUS_FINDBUGS_RESULTS_FILE)
+
+# commit changes; Add "skip ci" so that we don't accidentally trigger another Drone build
+system ('git commit -m "Drone: update FindBugs results to reflect reduced error/warning count [skip ci]" ')
+
+# push to origin
+system ('git push origin HEAD:' + git_branch)
+
+# restore previous git user name and email
+system("git config --local user.name '#{previous_git_username}'")
+system("git config --local user.email '#{previous_git_email}'")
+
+puts "SUCCESS: count was reduced"
+exit 0 # success