analysis-wrapper.sh 6.4 KB

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