analysis-wrapper.sh 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #!/usr/bin/env bash
  2. BRANCH=$1
  3. LOG_USERNAME=$2
  4. LOG_PASSWORD=$3
  5. BUILD_NUMBER=$4
  6. PR_NUMBER=$5
  7. stableBranch="master"
  8. repository="android"
  9. ruby scripts/analysis/lint-up.rb
  10. lintValue=$?
  11. curl "https://www.kaminsky.me/nc-dev/$repository-findbugs/$stableBranch.xml" -o "/tmp/$stableBranch.xml"
  12. ruby scripts/analysis/spotbugs-up.rb "$stableBranch"
  13. spotbugsValue=$?
  14. # exit codes:
  15. # 0: count was reduced
  16. # 1: count was increased
  17. # 2: count stayed the same
  18. source scripts/lib.sh
  19. echo "Branch: $BRANCH"
  20. if [ "$BRANCH" = $stableBranch ]; then
  21. echo "New spotbugs result for $stableBranch at: https://www.kaminsky.me/nc-dev/$repository-findbugs/$stableBranch.html"
  22. curl -u "${LOG_USERNAME}:${LOG_PASSWORD}" -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/$repository-findbugs/$stableBranch.html --upload-file app/build/reports/spotbugs/spotbugs.html
  23. curl 2>/dev/null -u "${LOG_USERNAME}:${LOG_PASSWORD}" -X PUT "https://nextcloud.kaminsky.me/remote.php/webdav/$repository-findbugs/$stableBranch.xml" --upload-file app/build/reports/spotbugs/gplayDebug.xml
  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 "${LOG_USERNAME}:${LOG_PASSWORD}" -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/$repository-lint/$stableBranch.html --upload-file app/build/reports/lint/lint.html
  27. exit 0
  28. fi
  29. else
  30. if [ -e "${BUILD_NUMBER}" ]; then
  31. 6=$stableBranch"-"$(date +%F)
  32. fi
  33. echo "New lint results at https://www.kaminsky.me/nc-dev/$repository-lint/${BUILD_NUMBER}.html"
  34. curl 2>/dev/null -u "${LOG_USERNAME}:${LOG_PASSWORD}" -X PUT "https://nextcloud.kaminsky.me/remote.php/webdav/$repository-lint/${BUILD_NUMBER}.html" --upload-file app/build/reports/lint/lint.html
  35. echo "New spotbugs results at https://www.kaminsky.me/nc-dev/$repository-findbugs/${BUILD_NUMBER}.html"
  36. curl 2>/dev/null -u "${LOG_USERNAME}:${LOG_PASSWORD}" -X PUT "https://nextcloud.kaminsky.me/remote.php/webdav/$repository-findbugs/${BUILD_NUMBER}.html" --upload-file app/build/reports/spotbugs/spotbugs.html
  37. # delete all old comments, starting with Codacy
  38. oldComments=$(curl_gh -X GET "https://api.github.com/repos/nextcloud/$repository/issues/${PR_NUMBER}/comments" | jq '.[] | select((.user.login | contains("github-actions")) and (.body | test("<h1>Codacy.*"))) | .id')
  39. echo "$oldComments" | while read -r comment ; do
  40. curl_gh -X DELETE "https://api.github.com/repos/nextcloud/$repository/issues/comments/$comment"
  41. done
  42. # lint and spotbugs file must exist
  43. if [ ! -s app/build/reports/lint/lint.html ] ; then
  44. echo "lint.html file is missing!"
  45. exit 1
  46. fi
  47. if [ ! -s app/build/reports/spotbugs/spotbugs.html ] ; then
  48. echo "spotbugs.html file is missing!"
  49. exit 1
  50. fi
  51. # add comment with results
  52. lintResultNew=$(grep "Lint Report.* [0-9]* warning" app/build/reports/lint/lint.html | cut -f2 -d':' |cut -f1 -d'<')
  53. lintErrorNew=$(echo $lintResultNew | grep "[0-9]* error" -o | cut -f1 -d" ")
  54. if ( [ -z $lintErrorNew ] ); then
  55. lintErrorNew=0
  56. fi
  57. lintWarningNew=$(echo $lintResultNew | grep "[0-9]* warning" -o | cut -f1 -d" ")
  58. if ( [ -z $lintWarningNew ] ); then
  59. lintWarningNew=0
  60. fi
  61. lintResultOld=$(curl 2>/dev/null "https://raw.githubusercontent.com/nextcloud/$repository/$stableBranch/scripts/analysis/lint-results.txt")
  62. lintErrorOld=$(echo $lintResultOld | grep "[0-9]* error" -o | cut -f1 -d" ")
  63. if ( [ -z $lintErrorOld ] ); then
  64. lintErrorOld=0
  65. fi
  66. lintWarningOld=$(echo $lintResultOld | grep "[0-9]* warning" -o | cut -f1 -d" ")
  67. if ( [ -z $lintWarningOld ] ); then
  68. lintWarningOld=0
  69. fi
  70. if [ $stableBranch = "master" ] ; then
  71. codacyValue=$(curl 2>/dev/null https://app.codacy.com/dashboards/breakdown\?projectId\=44248 | grep "total issues" | cut -d">" -f3 | cut -d"<" -f1)
  72. codacyResult="<h1>Codacy</h1>$codacyValue"
  73. else
  74. codacyResult=""
  75. fi
  76. 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/${BUILD_NUMBER}.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>"
  77. spotbugsResult="<h1>SpotBugs</h1>$(scripts/analysis/spotbugsComparison.py "/tmp/$stableBranch.xml" app/build/reports/spotbugs/gplayDebug.xml --link-new "https://www.kaminsky.me/nc-dev/$repository-findbugs/${BUILD_NUMBER}.html" --link-base "https://www.kaminsky.me/nc-dev/$repository-findbugs/$stableBranch.html")"
  78. if ( [ $lintValue -eq 1 ] ) ; then
  79. lintMessage="<h1>Lint increased!</h1>"
  80. fi
  81. if ( [ $spotbugsValue -eq 1 ] ) ; then
  82. spotbugsMessage="<h1>SpotBugs increased!</h1>"
  83. fi
  84. # check gplay limitation: all changelog files must only have 500 chars
  85. gplayLimitation=$(scripts/checkGplayLimitation.sh)
  86. if [ ! -z "$gplayLimitation" ]; then
  87. gplayLimitation="<h1>Following files are beyond 500 char limit:</h1><br><br>"$gplayLimitation
  88. fi
  89. # check for NotNull
  90. if [[ $(grep org.jetbrains.annotations app/src/main/* -irl | wc -l) -gt 0 ]] ; then
  91. notNull="org.jetbrains.annotations.* is used. Please use androidx.annotation.* instead.<br><br>"
  92. fi
  93. bodyContent="$codacyResult $lintResult $spotbugsResult $lintMessage $spotbugsMessage $gplayLimitation $notNull"
  94. echo "$bodyContent" >> "$GITHUB_STEP_SUMMARY"
  95. payload="{ \"body\" : \"$bodyContent\" }"
  96. curl_gh -X POST "https://api.github.com/repos/nextcloud/$repository/issues/${PR_NUMBER}/comments" -d "$payload"
  97. if [ ! -z "$gplayLimitation" ]; then
  98. exit 1
  99. fi
  100. if [ $checkLibrary -eq 1 ]; then
  101. exit 1
  102. fi
  103. if [ ! $lintValue -eq 2 ]; then
  104. exit $lintValue
  105. fi
  106. if [ -n "$notNull" ]; then
  107. exit 1
  108. fi
  109. if [ $spotbugsValue -eq 2 ]; then
  110. exit 0
  111. else
  112. exit $spotbugsValue
  113. fi
  114. fi