analysis-wrapper.sh 5.6 KB

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