cswTestScript.sh 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # Copyright (C) 2020, 2019, 2018 Girish M
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 3 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, write to the Free Software
  15. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  16. # MA 02110-1301, USA.
  17. #
  18. echo "Running script that runs all the tests that are part of csw and uploads them to my confluence page..."
  19. today=`date '+%d%b%I%p'`
  20. filename=TestResults$today.txt
  21. failedTests=TestFailed$today.txt
  22. uploadRes=UploadRes$today.txt
  23. userToken="$(cat ../tokenDir/confToken)"
  24. slackToken="$(cat ../tokenDir/slackToken)"
  25. #navigate to csw-prod directory
  26. echo "Going into csw home directory..."
  27. cd ../IdeaProjects/csw/ #this can be replaced with your directory path of csw checked folder
  28. touch $filename
  29. touch $failedTests
  30. touch $uploadRes
  31. #update the Git repo
  32. git pull
  33. #set environment variable
  34. export SBT_OPTS=--add-modules=java.xml.bind,java.activation
  35. #start sbt and run all tests
  36. echo "Starting sbt to run all tests..."
  37. sbt -Dsbt.log.noformat=true test > $filename
  38. #upload it to Confluence
  39. echo "Uploading $filename to confluence..."
  40. confluenceURL=https://tmt-project.atlassian.net/wiki/rest/api/content/208764929/child/attachment
  41. #replace with your mail ID and obtain the API token from https://id.atlassian.com/manage/api-tokens
  42. curl --request PUT \
  43. --user 'gireesh.itcc@iiap.res.in:'$userToken \
  44. --header 'Accept: application/json' \
  45. --header 'Content-Type: multipart/form-data' \
  46. --header 'X-Atlassian-Token: nocheck' \
  47. --form 'file=@'$filename \
  48. --url 'https://tmt-project.atlassian.net/wiki/rest/api/content/208764929/child/attachment' > $uploadRes
  49. #to parse the test file and locate [error] lines and report
  50. echo "Parsing the test file to locate [error] lines..."
  51. if [$(grep "\[success\]" $filename)]; then
  52. slackMsg=" Tests executed successfully"
  53. else
  54. slackMsg="$(grep "\[error\]" $filename)"
  55. fi
  56. echo slackMsg > $failedTests
  57. testRes="$(grep "Total time:" $filename)"
  58. #Add the final result and test run time as a comment to the attachement
  59. attachmentId=$(jq --raw-output '.results[0].id' $uploadRes)
  60. echo "\nUploaded test file attachment id: $attachmentId"
  61. curl -D- \
  62. -u gireesh.itcc@iiap.res.in:$userToken \
  63. -X POST \
  64. -H "X-Atlassian-Token: nocheck" \
  65. -F "file=@"$filename \
  66. -F "minorEdit=true" \
  67. -F "comment=$testRes" \
  68. https://tmt-project.atlassian.net/wiki/rest/api/content/208764929/child/attachment/$attachmentId/data >> $uploadRes
  69. #Use the Slack API token to update the Testing V&V channel about the failed tests
  70. slackAtt="%5B%7B%22CSW Test Results%22%3A%20%22Tests that have failed:%22%2C%20%22text%22%3A%20%22$slackMsg%22%7D%5Di"
  71. slackChnl="csw-testing_validate"
  72. detLogLink="Detailed log: https://tmt-project.atlassian.net/wiki/x/AYBxD"
  73. curl -X POST "https://slack.com/api/chat.postMessage" -d "token=$slackToken&channel=$slackChnl&text=$detLogLink&attachments=$slackAtt&pretty=1"
  74. echo "\nCompleted!"
  75. #TODO: make it periodic. The script should run at 10.00 AM everyday. Well my system should be on to do this or it has to be made to switch one automatically and then run it.
  76. #Ideally, on logging into this system it could be made to run, thereby avoiding me to do a simple task of opening the command line and running myself. Well, is it worth the effort?
  77. #Finally, move the files to confluence test directory
  78. echo "\nMoving $filename $failedTests $uploadRes to TestResConfl directory..."
  79. mv $filename $failedTests $uploadRes ../../TestResConfl #replace with your directory where the files need to be stored