analysis-wrapper.sh 6.3 KB

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