uploadReport.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/usr/bin/env bash
  2. curl_gh() {
  3. curl \
  4. --header "authorization: Bearer $GITHUB_TOKEN" \
  5. "$@"
  6. }
  7. deleteOldComments() {
  8. # delete all old comments, matching this type
  9. echo "Deleting old comments for $BRANCH_TYPE"
  10. oldComments=$(curl_gh > /dev/null 2>&1 -X GET https://api.github.com/repos/nextcloud/android/issues/$PR/comments | jq --arg TYPE $BRANCH_TYPE '.[] | (.id |tostring) + "|" + (.user.login | test("nextcloud-android-bot") | tostring) + "|" + (.body | test([$TYPE]) | tostring)'| grep "true|true" | tr -d "\"" | cut -f1 -d"|")
  11. count=$(echo $oldComments | grep true | wc -l)
  12. echo "Found $count old comments"
  13. echo $oldComments | while read comment ; do
  14. echo "Deleting comment: $comment"
  15. curl_gh > /dev/null 2>&1 -X DELETE https://api.github.com/repos/nextcloud/android/issues/comments/$comment
  16. done
  17. }
  18. upload() {
  19. deleteOldComments
  20. cd $1
  21. find . -type d -exec curl > /dev/null 2>&1 -u $USER:$PASS -X MKCOL $URL/$REMOTE_FOLDER/$(echo {} | sed s#\./##) \;
  22. find . -type f -exec curl > /dev/null 2>&1 -u $USER:$PASS -X PUT $URL/$REMOTE_FOLDER/$(echo {} | sed s#\./##) --upload-file {} \;
  23. echo "Uploaded failing tests to https://www.kaminsky.me/nc-dev/android-integrationTests/$REMOTE_FOLDER"
  24. curl_gh -X POST https://api.github.com/repos/nextcloud/android/issues/$PR/comments \
  25. -d "{ \"body\" : \"$BRANCH_TYPE test failed: https://www.kaminsky.me/nc-dev/android-integrationTests/$REMOTE_FOLDER \" }"
  26. exit 1
  27. }
  28. #1: LOG_USERNAME
  29. #2: LOG_PASSWORD
  30. #3: DRONE_BUILD_NUMBER
  31. #4: BRANCH (stable or master)
  32. #5: TYPE (IT or Unit)
  33. #6: DRONE_PULL_REQUEST
  34. #7: GITHUB_TOKEN
  35. URL=https://nextcloud.kaminsky.me/remote.php/webdav/android-integrationTests
  36. ID=$3
  37. USER=$1
  38. PASS=$2
  39. BRANCH=$4
  40. TYPE=$5
  41. PR=$6
  42. GITHUB_TOKEN="$7"
  43. REMOTE_FOLDER=$ID-$TYPE-$BRANCH-$(date +%H-%M)
  44. BRANCH_TYPE=$BRANCH-$TYPE
  45. set -e
  46. if [ -z $USER ] || [ -z $PASS ]; then
  47. echo "USER or PASS is empty!"
  48. exit 1
  49. fi
  50. if [ $TYPE = "IT" ]; then
  51. FOLDER=build/reports/androidTests/connected/flavors/gplay
  52. elif [ $TYPE = "Unit" ]; then
  53. FOLDER=build/reports/tests/testGplayDebugUnitTest
  54. else
  55. FOLDER=build/reports/shot/gplay/debug/verification
  56. fi
  57. if [ -e $FOLDER ]; then
  58. upload $FOLDER
  59. else
  60. deleteOldComments
  61. echo "$BRANCH_TYPE test failed, but no output was generated. Maybe a preliminary stage failed."
  62. curl_gh > /dev/null 2>&1 \
  63. -X POST https://api.github.com/repos/nextcloud/android/issues/$PR/comments \
  64. -d "{ \"body\" : \"$BRANCH_TYPE test failed, but no output was generated. Maybe a preliminary stage failed. \" }"
  65. if [ -e build/reports/androidTests/connected/flavors/gplay ] ; then
  66. TYPE="IT"
  67. BRANCH_TYPE=$BRANCH-$TYPE
  68. upload "build/reports/androidTests/connected/flavors/gplay"
  69. fi
  70. if [ -e build/reports/tests/testGplayDebugUnitTest ] ; then
  71. TYPE="Unit"
  72. BRANCH_TYPE=$BRANCH-$TYPE
  73. upload "build/reports/tests/testGplayDebugUnitTest"
  74. fi
  75. if [ -e build/reports/shot/gplay/debug/verification ] ; then
  76. TYPE="Screenshot"
  77. BRANCH_TYPE=$BRANCH-$TYPE
  78. upload "build/reports/shot/gplay/debug/verification"
  79. fi
  80. exit 1 # always fail
  81. fi