analysis-wrapper.sh 4.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/bin/sh
  2. #1: GIT_USERNAME
  3. #2: GIT_TOKEN
  4. #3: BRANCH
  5. #4: LOG_USERNAME
  6. #5: LOG_PASSWORD
  7. #6: DRONE_BUILD_NUMBER
  8. #7: PULL_REQUEST_NUMBER
  9. stableBranch="master"
  10. repository="android"
  11. ruby scripts/analysis/lint-up.rb $1 $2 $3
  12. lintValue=$?
  13. # exit codes:
  14. # 0: count was reduced
  15. # 1: count was increased
  16. # 2: count stayed the same
  17. ./gradlew findbugs
  18. echo "Branch: $3"
  19. if [ $3 = $stableBranch ]; then
  20. echo "New findbugs result for $stableBranch at: https://www.kaminsky.me/nc-dev/$repository-findbugs/$stableBranch.html"
  21. curl -u $4:$5 -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/$repository-findbugs/$stableBranch.html --upload-file build/reports/findbugs/findbugs.html
  22. summary=$(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/FindBugs ($stableBranch)/" | tr "\"" "\'" | tr -d "\r\n")
  23. curl -u $4:$5 -X PUT -d "$summary" https://nextcloud.kaminsky.me/remote.php/webdav/$repository-findbugs/findbugs-summary-$stableBranch.html
  24. if [ $lintValue -ne 1 ]; then
  25. echo "New lint result for $stableBranch at: https://www.kaminsky.me/nc-dev/$repository-lint/$stableBranch.html"
  26. curl -u $4:$5 -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/$repository-lint/$stableBranch.html --upload-file build/reports/lint/lint.html
  27. exit 0
  28. fi
  29. else
  30. if [ -e $6 ]; then
  31. 6=$stableBranch"-"$(date +%F)
  32. fi
  33. echo "New lint results at https://www.kaminsky.me/nc-dev/$repository-lint/$6.html"
  34. curl 2>/dev/null -u $4:$5 -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/$repository-lint/$6.html --upload-file build/reports/lint/lint.html
  35. echo "New findbugs results at https://www.kaminsky.me/nc-dev/$repository-findbugs/$6.html"
  36. curl 2>/dev/null -u $4:$5 -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/$repository-findbugs/$6.html --upload-file build/reports/findbugs/findbugs.html
  37. # delete all old comments
  38. oldComments=$(curl 2>/dev/null -u $1:$2 -X GET https://api.github.com/repos/nextcloud/android/issues/$7/comments | jq '.[] | (.id |tostring) + "|" + (.user.login | test("nextcloud-android-bot") | tostring) ' | grep true | tr -d "\"" | cut -f1 -d"|")
  39. echo $oldComments | while read comment ; do
  40. curl 2>/dev/null -u $1:$2 -X DELETE https://api.github.com/repos/nextcloud/android/issues/comments/$comment
  41. done
  42. # check library, only if base branch is master
  43. baseBranch=$(scripts/analysis/getBranchBase.sh $1 $2 $7 | tr -d "\"")
  44. if [ $baseBranch = "master" -a $(grep "android-library:master" build.gradle -c) -ne 3 ]; then
  45. checkLibraryMessage="<h1>Android-library is not set to master branch in build.gradle</h1>"
  46. checkLibrary=1
  47. else
  48. checkLibrary=0
  49. fi
  50. # lint and findbugs file must exist
  51. if [ ! -s build/reports/lint/lint.html ] ; then
  52. echo "lint.html file is missing!"
  53. exit 1
  54. fi
  55. if [ ! -s build/reports/findbugs/findbugs.html ] ; then
  56. echo "findbugs.html file is missing!"
  57. exit 1
  58. fi
  59. # add comment with results
  60. lintResultNew=$(grep "Lint Report.* [0-9]* warnings" build/reports/lint/lint.html | cut -f2 -d':' |cut -f1 -d'<')
  61. lintErrorNew=$(echo $lintResultNew | grep "[0-9]* error" -o | cut -f1 -d" ")
  62. lintWarningNew=$(echo $lintResultNew | grep "[0-9]* warning" -o | cut -f1 -d" ")
  63. lintErrorOld=$(grep "[0-9]* error" scripts/analysis/lint-results.txt -o | cut -f1 -d" ")
  64. lintWarningOld=$(grep "[0-9]* warning" scripts/analysis/lint-results.txt -o | cut -f1 -d" ")
  65. lintResult="<h1>Lint</h1><table width='500' cellpadding='5' cellspacing='2'><tr class='tablerow0'><td>Type</td><td><a href='https://www.kaminsky.me/nc-dev/"$repository"-lint/"$stableBranch".html'>$stableBranch</a></td><td><a href='https://www.kaminsky.me/nc-dev/"$repository"-lint/"$6".html'>PR</a></td></tr><tr class='tablerow1'><td>Warnings</td><td>"$lintWarningOld"</td><td>"$lintWarningNew"</td></tr><tr class='tablerow0'><td>Errors</td><td>"$lintErrorOld"</td><td>"$lintErrorNew"</td></tr></table>"
  66. 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")
  67. 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")
  68. curl -u $1:$2 -X POST https://api.github.com/repos/nextcloud/android/issues/$7/comments -d "{ \"body\" : \"$lintResult $findbugsResultNew $findbugsResultOld $checkLibraryMessage \" }"
  69. if [ $checkLibrary -eq 1 ]; then
  70. exit 1
  71. fi
  72. if [ $lintValue -eq 2 ]; then
  73. exit 0
  74. else
  75. exit $lintValue
  76. fi
  77. fi