analysis-wrapper.sh 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. # check library, only if base branch is master
  43. baseBranch=$(scripts/analysis/getBranchBase.sh "${PR_NUMBER}" | tr -d "\"")
  44. if [ $baseBranch = "master" -a $(grep "androidLibraryVersion = \"master-SNAPSHOT\"" build.gradle -c) -ne 1 ]; then
  45. checkLibraryMessage="<h1>Android-library is not set to master branch in build.gradle</h1>"
  46. checkLibrary=1
  47. elif [ $baseBranch != "master" -a $baseBranch = $stableBranch -a $(grep "androidLibraryVersion.*SNAPSHOT" build.gradle -c) -ne 0 ]; then
  48. checkLibraryMessage="<h1>Android-library is set to a SNAPSHOT in build.gradle</h1>"
  49. checkLibrary=1
  50. else
  51. checkLibrary=0
  52. fi
  53. # lint and spotbugs file must exist
  54. if [ ! -s app/build/reports/lint/lint.html ] ; then
  55. echo "lint.html file is missing!"
  56. exit 1
  57. fi
  58. if [ ! -s app/build/reports/spotbugs/spotbugs.html ] ; then
  59. echo "spotbugs.html file is missing!"
  60. exit 1
  61. fi
  62. # add comment with results
  63. lintResultNew=$(grep "Lint Report.* [0-9]* warning" app/build/reports/lint/lint.html | cut -f2 -d':' |cut -f1 -d'<')
  64. lintErrorNew=$(echo $lintResultNew | grep "[0-9]* error" -o | cut -f1 -d" ")
  65. if ( [ -z $lintErrorNew ] ); then
  66. lintErrorNew=0
  67. fi
  68. lintWarningNew=$(echo $lintResultNew | grep "[0-9]* warning" -o | cut -f1 -d" ")
  69. if ( [ -z $lintWarningNew ] ); then
  70. lintWarningNew=0
  71. fi
  72. lintResultOld=$(curl 2>/dev/null "https://raw.githubusercontent.com/nextcloud/$repository/$stableBranch/scripts/analysis/lint-results.txt")
  73. lintErrorOld=$(echo $lintResultOld | grep "[0-9]* error" -o | cut -f1 -d" ")
  74. if ( [ -z $lintErrorOld ] ); then
  75. lintErrorOld=0
  76. fi
  77. lintWarningOld=$(echo $lintResultOld | grep "[0-9]* warning" -o | cut -f1 -d" ")
  78. if ( [ -z $lintWarningOld ] ); then
  79. lintWarningOld=0
  80. fi
  81. if [ $stableBranch = "master" ] ; then
  82. codacyValue=$(curl 2>/dev/null https://app.codacy.com/dashboards/breakdown\?projectId\=44248 | grep "total issues" | cut -d">" -f3 | cut -d"<" -f1)
  83. codacyResult="<h1>Codacy</h1>$codacyValue"
  84. else
  85. codacyResult=""
  86. fi
  87. 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>"
  88. 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")"
  89. if ( [ $lintValue -eq 1 ] ) ; then
  90. lintMessage="<h1>Lint increased!</h1>"
  91. fi
  92. if ( [ $spotbugsValue -eq 1 ] ) ; then
  93. spotbugsMessage="<h1>SpotBugs increased!</h1>"
  94. fi
  95. # check gplay limitation: all changelog files must only have 500 chars
  96. gplayLimitation=$(scripts/checkGplayLimitation.sh)
  97. if [ ! -z "$gplayLimitation" ]; then
  98. gplayLimitation="<h1>Following files are beyond 500 char limit:</h1><br><br>"$gplayLimitation
  99. fi
  100. # check for NotNull
  101. if [[ $(grep org.jetbrains.annotations app/src/main/* -irl | wc -l) -gt 0 ]] ; then
  102. notNull="org.jetbrains.annotations.NotNull is used. Please use androidx.annotation.NonNull instead.<br><br>"
  103. fi
  104. bodyContent="$codacyResult $lintResult $spotbugsResult $checkLibraryMessage $lintMessage $spotbugsMessage $gplayLimitation $notNull"
  105. echo "$bodyContent" >> "$GITHUB_STEP_SUMMARY"
  106. payload="{ \"body\" : \"$bodyContent\" }"
  107. curl_gh -X POST "https://api.github.com/repos/nextcloud/$repository/issues/${PR_NUMBER}/comments" -d "$payload"
  108. if [ ! -z "$gplayLimitation" ]; then
  109. exit 1
  110. fi
  111. if [ $checkLibrary -eq 1 ]; then
  112. exit 1
  113. fi
  114. if [ ! $lintValue -eq 2 ]; then
  115. exit $lintValue
  116. fi
  117. if [ -n "$notNull" ]; then
  118. exit 1
  119. fi
  120. if [ $spotbugsValue -eq 2 ]; then
  121. exit 0
  122. else
  123. exit $spotbugsValue
  124. fi
  125. fi