2019-03-20 11:03:58 +03:00
|
|
|
#!/usr/bin/env bash
|
2018-06-21 10:06:33 +03:00
|
|
|
|
2022-05-31 11:07:03 +03:00
|
|
|
BRANCH=$1
|
|
|
|
LOG_USERNAME=$2
|
|
|
|
LOG_PASSWORD=$3
|
|
|
|
BUILD_NUMBER=$4
|
|
|
|
PR_NUMBER=$5
|
|
|
|
|
2018-06-21 10:06:33 +03:00
|
|
|
|
2018-11-01 12:59:08 +03:00
|
|
|
stableBranch="master"
|
|
|
|
repository="android"
|
|
|
|
|
2022-05-31 11:07:03 +03:00
|
|
|
ruby scripts/analysis/lint-up.rb
|
2018-06-21 10:06:33 +03:00
|
|
|
lintValue=$?
|
|
|
|
|
2022-05-06 10:32:15 +03:00
|
|
|
curl "https://www.kaminsky.me/nc-dev/$repository-findbugs/$stableBranch.xml" -o "/tmp/$stableBranch.xml"
|
|
|
|
ruby scripts/analysis/spotbugs-up.rb "$stableBranch"
|
2022-04-25 16:19:28 +03:00
|
|
|
spotbugsValue=$?
|
2019-01-16 18:20:10 +03:00
|
|
|
|
2018-06-21 10:06:33 +03:00
|
|
|
# exit codes:
|
|
|
|
# 0: count was reduced
|
|
|
|
# 1: count was increased
|
|
|
|
# 2: count stayed the same
|
|
|
|
|
2022-05-31 11:07:03 +03:00
|
|
|
source scripts/lib.sh
|
|
|
|
|
|
|
|
echo "Branch: $BRANCH"
|
2018-06-21 10:06:33 +03:00
|
|
|
|
2022-05-31 11:07:03 +03:00
|
|
|
if [ "$BRANCH" = $stableBranch ]; then
|
2022-04-25 16:19:28 +03:00
|
|
|
echo "New spotbugs result for $stableBranch at: https://www.kaminsky.me/nc-dev/$repository-findbugs/$stableBranch.html"
|
2022-05-31 11:07:03 +03:00
|
|
|
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
|
|
|
|
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
|
2018-11-01 12:59:08 +03:00
|
|
|
|
2018-06-21 10:06:33 +03:00
|
|
|
if [ $lintValue -ne 1 ]; then
|
2018-11-01 12:59:08 +03:00
|
|
|
echo "New lint result for $stableBranch at: https://www.kaminsky.me/nc-dev/$repository-lint/$stableBranch.html"
|
2022-05-31 11:07:03 +03:00
|
|
|
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
|
2018-06-21 10:06:33 +03:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
else
|
2022-05-31 11:07:03 +03:00
|
|
|
if [ -e "${BUILD_NUMBER}" ]; then
|
2018-11-01 12:59:08 +03:00
|
|
|
6=$stableBranch"-"$(date +%F)
|
2018-06-21 10:06:33 +03:00
|
|
|
fi
|
2022-05-31 11:07:03 +03:00
|
|
|
echo "New lint results at https://www.kaminsky.me/nc-dev/$repository-lint/${BUILD_NUMBER}.html"
|
|
|
|
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
|
2018-11-01 12:59:08 +03:00
|
|
|
|
2022-05-31 11:07:03 +03:00
|
|
|
echo "New spotbugs results at https://www.kaminsky.me/nc-dev/$repository-findbugs/${BUILD_NUMBER}.html"
|
|
|
|
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
|
2018-11-01 12:59:08 +03:00
|
|
|
|
2019-05-15 09:59:06 +03:00
|
|
|
# delete all old comments, starting with Codacy
|
2022-05-31 11:07:03 +03:00
|
|
|
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')
|
2018-11-01 12:59:08 +03:00
|
|
|
|
2022-05-31 11:07:03 +03:00
|
|
|
echo "$oldComments" | while read -r comment ; do
|
|
|
|
curl_gh -X DELETE "https://api.github.com/repos/nextcloud/$repository/issues/comments/$comment"
|
2018-06-21 15:11:55 +03:00
|
|
|
done
|
2018-11-01 12:59:08 +03:00
|
|
|
|
2018-08-30 13:24:50 +03:00
|
|
|
# check library, only if base branch is master
|
2022-05-31 11:07:03 +03:00
|
|
|
baseBranch=$(scripts/analysis/getBranchBase.sh "${PR_NUMBER}" | tr -d "\"")
|
2019-05-07 18:00:22 +03:00
|
|
|
if [ $baseBranch = "master" -a $(grep "androidLibraryVersion = \"master-SNAPSHOT\"" build.gradle -c) -ne 1 ]; then
|
2018-08-27 17:15:23 +03:00
|
|
|
checkLibraryMessage="<h1>Android-library is not set to master branch in build.gradle</h1>"
|
|
|
|
checkLibrary=1
|
2019-05-07 18:00:22 +03:00
|
|
|
elif [ $baseBranch != "master" -a $baseBranch = $stableBranch -a $(grep "androidLibraryVersion.*SNAPSHOT" build.gradle -c) -ne 0 ]; then
|
2019-04-18 14:57:24 +03:00
|
|
|
checkLibraryMessage="<h1>Android-library is set to a SNAPSHOT in build.gradle</h1>"
|
|
|
|
checkLibrary=1
|
2018-11-01 12:59:08 +03:00
|
|
|
else
|
2018-08-27 17:15:23 +03:00
|
|
|
checkLibrary=0
|
|
|
|
fi
|
2018-11-01 12:59:08 +03:00
|
|
|
|
2022-04-25 16:19:28 +03:00
|
|
|
# lint and spotbugs file must exist
|
2022-02-04 12:53:52 +03:00
|
|
|
if [ ! -s app/build/reports/lint/lint.html ] ; then
|
2018-09-25 12:55:53 +03:00
|
|
|
echo "lint.html file is missing!"
|
|
|
|
exit 1
|
|
|
|
fi
|
2018-11-01 12:59:08 +03:00
|
|
|
|
2022-02-04 12:53:52 +03:00
|
|
|
if [ ! -s app/build/reports/spotbugs/spotbugs.html ] ; then
|
2019-04-01 10:47:30 +03:00
|
|
|
echo "spotbugs.html file is missing!"
|
2018-09-25 12:55:53 +03:00
|
|
|
exit 1
|
2018-11-01 12:59:08 +03:00
|
|
|
fi
|
|
|
|
|
2018-06-21 10:06:33 +03:00
|
|
|
# add comment with results
|
2022-02-04 12:53:52 +03:00
|
|
|
lintResultNew=$(grep "Lint Report.* [0-9]* warning" app/build/reports/lint/lint.html | cut -f2 -d':' |cut -f1 -d'<')
|
2018-12-07 16:12:40 +03:00
|
|
|
|
2018-11-01 12:59:08 +03:00
|
|
|
lintErrorNew=$(echo $lintResultNew | grep "[0-9]* error" -o | cut -f1 -d" ")
|
2018-12-07 16:12:40 +03:00
|
|
|
if ( [ -z $lintErrorNew ] ); then
|
|
|
|
lintErrorNew=0
|
|
|
|
fi
|
|
|
|
|
2018-11-01 12:59:08 +03:00
|
|
|
lintWarningNew=$(echo $lintResultNew | grep "[0-9]* warning" -o | cut -f1 -d" ")
|
2018-12-07 16:12:40 +03:00
|
|
|
if ( [ -z $lintWarningNew ] ); then
|
|
|
|
lintWarningNew=0
|
|
|
|
fi
|
2018-12-06 13:24:16 +03:00
|
|
|
|
2022-05-31 11:07:03 +03:00
|
|
|
lintResultOld=$(curl 2>/dev/null "https://raw.githubusercontent.com/nextcloud/$repository/$stableBranch/scripts/analysis/lint-results.txt")
|
2018-12-06 13:24:16 +03:00
|
|
|
lintErrorOld=$(echo $lintResultOld | grep "[0-9]* error" -o | cut -f1 -d" ")
|
2018-12-07 16:12:40 +03:00
|
|
|
if ( [ -z $lintErrorOld ] ); then
|
|
|
|
lintErrorOld=0
|
|
|
|
fi
|
|
|
|
|
2018-12-06 13:24:16 +03:00
|
|
|
lintWarningOld=$(echo $lintResultOld | grep "[0-9]* warning" -o | cut -f1 -d" ")
|
2018-12-07 16:12:40 +03:00
|
|
|
if ( [ -z $lintWarningOld ] ); then
|
|
|
|
lintWarningOld=0
|
|
|
|
fi
|
2018-12-06 13:24:16 +03:00
|
|
|
|
2019-04-15 10:33:53 +03:00
|
|
|
if [ $stableBranch = "master" ] ; then
|
|
|
|
codacyValue=$(curl 2>/dev/null https://app.codacy.com/dashboards/breakdown\?projectId\=44248 | grep "total issues" | cut -d">" -f3 | cut -d"<" -f1)
|
|
|
|
codacyResult="<h1>Codacy</h1>$codacyValue"
|
|
|
|
else
|
|
|
|
codacyResult=""
|
|
|
|
fi
|
|
|
|
|
2022-05-31 11:07:03 +03:00
|
|
|
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>"
|
2018-12-06 13:24:16 +03:00
|
|
|
|
2022-05-31 11:07:03 +03:00
|
|
|
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")"
|
2019-01-16 18:20:10 +03:00
|
|
|
|
|
|
|
if ( [ $lintValue -eq 1 ] ) ; then
|
|
|
|
lintMessage="<h1>Lint increased!</h1>"
|
|
|
|
fi
|
|
|
|
|
2022-04-25 16:19:28 +03:00
|
|
|
if ( [ $spotbugsValue -eq 1 ] ) ; then
|
|
|
|
spotbugsMessage="<h1>SpotBugs increased!</h1>"
|
2019-01-16 18:20:10 +03:00
|
|
|
fi
|
|
|
|
|
2019-03-20 11:03:58 +03:00
|
|
|
# check gplay limitation: all changelog files must only have 500 chars
|
|
|
|
gplayLimitation=$(scripts/checkGplayLimitation.sh)
|
|
|
|
|
|
|
|
if [ ! -z "$gplayLimitation" ]; then
|
|
|
|
gplayLimitation="<h1>Following files are beyond 500 char limit:</h1><br><br>"$gplayLimitation
|
|
|
|
fi
|
|
|
|
|
2020-10-27 13:44:48 +03:00
|
|
|
# check for NotNull
|
2022-02-04 12:53:52 +03:00
|
|
|
if [[ $(grep org.jetbrains.annotations app/src/main/* -irl | wc -l) -gt 0 ]] ; then
|
2020-10-27 13:44:48 +03:00
|
|
|
notNull="org.jetbrains.annotations.NotNull is used. Please use androidx.annotation.NonNull instead.<br><br>"
|
|
|
|
fi
|
|
|
|
|
2022-06-06 12:35:00 +03:00
|
|
|
bodyContent="$codacyResult $lintResult $spotbugsResult $checkLibraryMessage $lintMessage $spotbugsMessage $gplayLimitation $notNull"
|
|
|
|
echo "$bodyContent" >> "$GITHUB_STEP_SUMMARY"
|
|
|
|
payload="{ \"body\" : \"$bodyContent\" }"
|
2022-05-31 11:07:03 +03:00
|
|
|
curl_gh -X POST "https://api.github.com/repos/nextcloud/$repository/issues/${PR_NUMBER}/comments" -d "$payload"
|
2019-03-20 11:03:58 +03:00
|
|
|
|
|
|
|
if [ ! -z "$gplayLimitation" ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
2018-11-01 12:59:08 +03:00
|
|
|
|
2018-08-27 17:15:23 +03:00
|
|
|
if [ $checkLibrary -eq 1 ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
2018-11-01 12:59:08 +03:00
|
|
|
|
2019-01-29 12:03:37 +03:00
|
|
|
if [ ! $lintValue -eq 2 ]; then
|
|
|
|
exit $lintValue
|
|
|
|
fi
|
|
|
|
|
2021-05-27 11:14:53 +03:00
|
|
|
if [ -n "$notNull" ]; then
|
2020-10-27 13:44:48 +03:00
|
|
|
exit 1
|
2020-10-27 20:08:56 +03:00
|
|
|
fi
|
2020-10-27 13:44:48 +03:00
|
|
|
|
2022-04-25 16:19:28 +03:00
|
|
|
if [ $spotbugsValue -eq 2 ]; then
|
2018-06-21 10:06:33 +03:00
|
|
|
exit 0
|
|
|
|
else
|
2022-04-25 16:19:28 +03:00
|
|
|
exit $spotbugsValue
|
2018-11-01 12:59:08 +03:00
|
|
|
fi
|
2018-06-21 10:06:33 +03:00
|
|
|
fi
|