uploadReport.sh 3.1 KB

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