analysis-wrapper.sh 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #!/usr/bin/env bash
  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. repository="talk"
  10. if [[ $3 = \stable-* ]] ; then
  11. stableBranch=$3
  12. else
  13. stableBranch="master"
  14. fi
  15. ruby scripts/analysis/lint-up.rb $1 $2 $3
  16. lintValue=$?
  17. ruby scripts/analysis/findbugs-up.rb $1 $2 $3
  18. findbugsValue=$?
  19. # exit codes:
  20. # 0: count was reduced
  21. # 1: count was increased
  22. # 2: count stayed the same
  23. echo "Branch: $3"
  24. if [ $3 = $stableBranch ]; then
  25. echo "New findbugs result for $stableBranch at: https://www.kaminsky.me/nc-dev/$repository-findbugs/$stableBranch.html"
  26. curl -k -u $4:$5 -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/$repository-findbugs/$stableBranch.html --upload-file app/build/reports/spotbugs/spotbugs.html
  27. summary=$(sed -n "/<h1>Summary<\/h1>/,/<h1>Warnings<\/h1>/p" app/build/reports/spotbugs/spotbugs.html | head -n-1 | sed s'/<\/a>//'g | sed s'/<a.*>//'g | sed s"/Summary/SpotBugs ($stableBranch)/" | tr "\"" "\'" | tr -d "\r\n")
  28. curl -k -u $4:$5 -X PUT -d "$summary" https://nextcloud.kaminsky.me/remote.php/webdav/$repository-findbugs/findbugs-summary-$stableBranch.html
  29. if [ $lintValue -ne 1 ]; then
  30. echo "New lint result for $stableBranch at: https://www.kaminsky.me/nc-dev/$repository-lint/$stableBranch.html"
  31. curl -k -u $4:$5 -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/$repository-lint/$stableBranch.html --upload-file app/build/reports/lint/lint.html
  32. exit 0
  33. fi
  34. else
  35. if [ -e $6 ]; then
  36. 6=$stableBranch"-"$(date +%F)
  37. fi
  38. echo "New lint results at https://www.kaminsky.me/nc-dev/$repository-lint/$6.html"
  39. curl -k -u $4:$5 -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/$repository-lint/$6.html --upload-file app/build/reports/lint/lint.html
  40. echo "New findbugs results at https://www.kaminsky.me/nc-dev/$repository-findbugs/$6.html"
  41. curl -k -u $4:$5 -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/$repository-findbugs/$6.html --upload-file app/build/reports/spotbugs/spotbugs.html
  42. # delete all old comments
  43. oldComments=$(curl -k 2>/dev/null -u $1:$2 -X GET https://api.github.com/repos/nextcloud/talk-android/issues/$7/comments | jq '.[] | (.id |tostring) + "|" + (.user.login | test("nextcloud-android-bot") | tostring) ' | grep true | tr -d "\"" | cut -f1 -d"|")
  44. echo $oldComments | while read comment ; do
  45. curl -k 2>/dev/null -u $1:$2 -X DELETE https://api.github.com/repos/nextcloud/talk-android/issues/comments/$comment
  46. done
  47. # lint and findbugs file must exist
  48. if [ ! -s app/build/reports/lint/lint.html ] ; then
  49. echo "lint.html file is missing!"
  50. exit 1
  51. fi
  52. if [ ! -s app/build/reports/spotbugs/spotbugs.html ] ; then
  53. echo "spotbugs.html file is missing!"
  54. exit 1
  55. fi
  56. # add comment with results
  57. lintResultNew=$(grep "Lint Report.* [0-9]* warning" app/build/reports/lint/lint.html | cut -f2 -d':' |cut -f1 -d'<')
  58. lintErrorNew=$(echo $lintResultNew | grep "[0-9]* error" -o | cut -f1 -d" ")
  59. if ( [ -z $lintErrorNew ] ); then
  60. lintErrorNew=0
  61. fi
  62. lintWarningNew=$(echo $lintResultNew | grep "[0-9]* warning" -o | cut -f1 -d" ")
  63. if ( [ -z $lintWarningNew ] ); then
  64. lintWarningNew=0
  65. fi
  66. lintResultOld=$(curl -k 2>/dev/null https://raw.githubusercontent.com/nextcloud/talk-android/$stableBranch/scripts/analysis/lint-results.txt)
  67. lintErrorOld=$(echo $lintResultOld | grep "[0-9]* error" -o | cut -f1 -d" ")
  68. if ( [ -z $lintErrorOld ] ); then
  69. lintErrorOld=0
  70. fi
  71. lintWarningOld=$(echo $lintResultOld | grep "[0-9]* warning" -o | cut -f1 -d" ")
  72. if ( [ -z $lintWarningOld ] ); then
  73. lintWarningOld=0
  74. fi
  75. 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>"
  76. findbugsResultNew=$(sed -n "/<h1>Summary<\/h1>/,/<h1>Warnings<\/h1>/p" app/build/reports/spotbugs/spotbugs.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\">SpotBugs</a> (new)#" | tr "\"" "\'" | tr -d "\n")
  77. findbugsResultOld=$(curl -k 2>/dev/null https://www.kaminsky.me/nc-dev/$repository-findbugs/findbugs-summary-$stableBranch.html | tr "\"" "\'" | tr -d "\r\n" | sed s"#SpotBugs#<a href=\"https://www.kaminsky.me/nc-dev/$repository-findbugs/$stableBranch.html\">SpotBugs</a>#" | tr "\"" "\'" | tr -d "\n")
  78. if ( [ $lintValue -eq 1 ] ) ; then
  79. lintMessage="<h1>Lint increased!</h1>"
  80. fi
  81. if ( [ $findbugsValue -eq 1 ] ) ; then
  82. findbugsMessage="<h1>SpotBugs increased!</h1>"
  83. fi
  84. # check for NotNull
  85. if [[ $(grep org.jetbrains.annotations src/main/* -ir -c) -gt 0 ]] ; then
  86. notNull="org.jetbrains.annotations.NotNull is used. Please use androidx.annotation.NonNull instead.<br><br>"
  87. fi
  88. curl -k -u $1:$2 -X POST https://api.github.com/repos/nextcloud/talk-android/issues/$7/comments -d "{ \"body\" : \"$lintResult $findbugsResultNew $findbugsResultOld $lintMessage $findbugsMessage $notNull\" }"
  89. if [ ! $lintValue -eq 2 ]; then
  90. exit $lintValue
  91. fi
  92. if [[ -n $notNull ]]; then
  93. exit 1
  94. fi
  95. if [ $findbugsValue -eq 2 ]; then
  96. exit 0
  97. else
  98. exit $findbugsValue
  99. fi
  100. fi