uploadReport.sh 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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
  41. BRANCH_TYPE=$BRANCH-$TYPE
  42. set -e
  43. if [ $TYPE = "IT" ]; then
  44. FOLDER=build/reports/androidTests/connected/flavors/GPLAY
  45. elif [ $TYPE = "Unit" ]; then
  46. FOLDER=build/reports/tests/testGplayDebugUnitTest
  47. else
  48. FOLDER=build/reports/shot/verification
  49. fi
  50. if [ -e $FOLDER ]; then
  51. upload $FOLDER
  52. else
  53. deleteOldComments
  54. echo "$BRANCH_TYPE test failed, but no output was generated. Maybe a preliminary stage failed."
  55. curl -u $GITHUB_USER:$GITHUB_PASSWORD \
  56. -X POST https://api.github.com/repos/nextcloud/android/issues/$PR/comments \
  57. -d "{ \"body\" : \"$BRANCH_TYPE test failed, but no output was generated. Maybe a preliminary stage failed. \" }"
  58. if [ -e build/reports/androidTests/connected/flavors/gplayDebugAndroidTest ] ; then
  59. TYPE="IT"
  60. BRANCH_TYPE=$BRANCH-$TYPE
  61. upload "build/reports/androidTests/connected/flavors/gplayDebugAndroidTest"
  62. fi
  63. if [ -e build/reports/tests/testGplayDebugUnitTest ] ; then
  64. TYPE="Unit"
  65. BRANCH_TYPE=$BRANCH-$TYPE
  66. upload "build/reports/tests/testGplayDebugUnitTest"
  67. fi
  68. if [ -e build/reports/shot/verification ] ; then
  69. TYPE="Screenshot"
  70. BRANCH_TYPE=$BRANCH-$TYPE
  71. upload "build/reports/shot/verification"
  72. fi
  73. exit 1 # always fail
  74. fi