1 | #!/bin/bash
|
---|
2 |
|
---|
3 | addressToMailTo="eden_test_results@sahanafoundation.org"
|
---|
4 | SERVER_IP="82.71.213.53"
|
---|
5 |
|
---|
6 | # Path of the result directories.
|
---|
7 | path_to_automated_html_results="/var/spool/RESULTS/SELENIUM/"
|
---|
8 | path_to_smoke_html_results="/var/spool/RESULTS/SMOKE/"
|
---|
9 | path_to_roles_html_results="/var/spool/RESULTS/ROLES/"
|
---|
10 |
|
---|
11 | function append_selenium_results
|
---|
12 | {
|
---|
13 | # Get the template name from arguments
|
---|
14 | template=$1
|
---|
15 |
|
---|
16 | ################# ADD SELENIUM TESTS RESULTS #################
|
---|
17 |
|
---|
18 | # Grab the latest file from the template test results directory
|
---|
19 | results_path=$path_to_automated_html_results$template
|
---|
20 | automated_latest_result=$results_path/`ls -rt $results_path | tail -1 `
|
---|
21 | echo '' > /tmp/selenium.html
|
---|
22 | cat "$automated_latest_result" > /tmp/selenium.html
|
---|
23 |
|
---|
24 | # Grab the line containing the Status Details of the test (First instance of the line containing "Status")
|
---|
25 | statusLine=`cat /tmp/selenium.html | grep "Status" | head -1 | sed "s/<strong>Status:<\/strong>//"`
|
---|
26 |
|
---|
27 | URL_OF_SELENIUM_TESTS="http://$SERVER_IP/RESULTS/SELENIUM/"$template"/"$(python -c "import urllib; print urllib.quote('''`ls -rt $results_path | tail -1`''')")
|
---|
28 |
|
---|
29 | # Add inline CSS on the basis of the fact that the Status lines contain "Failure" and "Error" keywords or not
|
---|
30 | if [[ $statusLine == *Failure* || $statusLine == *Error* ]]
|
---|
31 | then
|
---|
32 | style="'background-color:red'"
|
---|
33 | #messageBody=$messageBody"<td style='background-color:red'>\n<strong><u>Selenium Tests</u></strong>::\n"$templateLine"\n"$statusLine"\n<i>Detailed Results</i> :: <a href='$URL_OF_SELENIUM_TESTS'>Click Here</a></td>\n"
|
---|
34 | else
|
---|
35 | style='background-color:greenyellow'
|
---|
36 | #messageBody=$messageBody"<td style='background-color:greenyellow'>\n<strong><u>Selenium Tests</u></strong>::\n"$templateLine"\n"$statusLine"\n<i>Detailed Results</i> :: <a href='$URL_OF_SELENIUM_TESTS'>Click Here</a></td>\n"
|
---|
37 | fi
|
---|
38 |
|
---|
39 | # Start a row for this test in the table
|
---|
40 | messageBody=$messageBody"<tr>"
|
---|
41 | messageBody=$messageBody"<td style="$style">"$template"</td>"
|
---|
42 | messageBody=$messageBody"<td style="$style">Selenium</td>"
|
---|
43 | messageBody=$messageBody"<td style="$style">"$statusLine"</td>"
|
---|
44 | messageBody=$messageBody"<td style="$style"><a href='$URL_OF_SELENIUM_TESTS'>Detailed Results</a></td>"
|
---|
45 | messageBody=$messageBody"</tr>"
|
---|
46 | }
|
---|
47 |
|
---|
48 | function append_smoke_results
|
---|
49 | {
|
---|
50 | template=$1
|
---|
51 |
|
---|
52 | ################# ADD SMOKE TESTS RESULTS #################
|
---|
53 |
|
---|
54 | # Grab the latest file from the default test results directory
|
---|
55 | results_path=$path_to_smoke_html_results$template
|
---|
56 | smoke_latest_result=$results_path/`ls -rt $results_path | tail -1 `
|
---|
57 | echo '' > /tmp/smoke.html
|
---|
58 | cat "$smoke_latest_result" > /tmp/smoke.html
|
---|
59 |
|
---|
60 | # Grab the line containing the Status Details of the test (First instance of the line containing "Status")
|
---|
61 | statusLine=`cat /tmp/smoke.html | grep "Status" | head -1 | sed "s/<strong>Status:<\/strong>//" `
|
---|
62 |
|
---|
63 | URL_OF_SMOKE_TESTS="http://$SERVER_IP/RESULTS/SMOKE/"$template"/"$(python -c "import urllib; print urllib.quote('''`ls -rt $results_path | tail -1`''')")
|
---|
64 |
|
---|
65 | # Add inline CSS on the basis of the fact that the Status lines contain "Faillur" and "Error" keywords or not
|
---|
66 | if [[ $statusLine == *Failure* || $statusLine == *Error* ]]
|
---|
67 | then
|
---|
68 | style="'background-color:red'"
|
---|
69 | else
|
---|
70 | style='background-color:greenyellow'
|
---|
71 | fi
|
---|
72 |
|
---|
73 | # Start a row for this test in the table
|
---|
74 | messageBody=$messageBody"<tr>"
|
---|
75 | messageBody=$messageBody"<td style="$style">"$template"</td>"
|
---|
76 | messageBody=$messageBody"<td style="$style">Smoke</td>"
|
---|
77 | messageBody=$messageBody"<td style="$style">"$statusLine"</td>"
|
---|
78 | messageBody=$messageBody"<td style="$style"><a href='$URL_OF_SMOKE_TESTS'>Detailed Results</a></td>"
|
---|
79 | messageBody=$messageBody"</tr>"
|
---|
80 | }
|
---|
81 |
|
---|
82 | function append_roles_results
|
---|
83 | {
|
---|
84 | template=$1
|
---|
85 | ################# ADD ROLES TESTS RESULTS #################
|
---|
86 |
|
---|
87 | # Grab the latest file from the default test results directory
|
---|
88 | results_path=$path_to_roles_html_results$template
|
---|
89 | roles_latest_result=$results_path/`ls -rt $results_path | tail -1 `
|
---|
90 | echo '' > /tmp/roles.html
|
---|
91 | cat "$roles_latest_result" > /tmp/roles.html
|
---|
92 |
|
---|
93 | # Grab the line containing the Status Details of the test (First instance of the line containing "Status")
|
---|
94 | statusLine=`cat /tmp/roles.html | grep "Status" | head -1 | sed "s/<strong>Status:<\/strong>//" `
|
---|
95 |
|
---|
96 | URL_OF_ROLES_TESTS="http://$SERVER_IP/RESULTS/ROLES/"$template"/"$(python -c "import urllib; print urllib.quote('''`ls -rt $results_path | tail -1`''')")
|
---|
97 |
|
---|
98 | # Add inline CSS on the basis of the fact that the Status lines contain "Faillur" and "Error" keywords or not
|
---|
99 | if [[ $statusLine == *Failure* || $statusLine == *Error* ]]
|
---|
100 | then
|
---|
101 | style="'background-color:red'"
|
---|
102 | else
|
---|
103 | style='background-color:greenyellow'
|
---|
104 | fi
|
---|
105 |
|
---|
106 | # Start a row for this test in the table
|
---|
107 | messageBody=$messageBody"<tr>"
|
---|
108 | messageBody=$messageBody"<td style="$style">"$template"</td>"
|
---|
109 | messageBody=$messageBody"<td style="$style">Roles</td>"
|
---|
110 | messageBody=$messageBody"<td style="$style">"$statusLine"</td>"
|
---|
111 | messageBody=$messageBody"<td style="$style"><a href='$URL_OF_ROLES_TESTS'>Detailed Results</a></td>"
|
---|
112 | messageBody=$messageBody"</tr>"
|
---|
113 | }
|
---|
114 |
|
---|
115 | messageBody="<h3>Sahana Eden Continuous Integration Server Test Results : </h3>\n"
|
---|
116 |
|
---|
117 | #### Obtain and attach the Head of the Eden Repository during the test ####
|
---|
118 | cd /home/web2py/applications/eden
|
---|
119 | LINK_TO_LATEST_COMMIT=`git log --format="%H ### %an ### %ad ### %s" --date=iso | head -1 | python -c "line = raw_input().split('###'); \
|
---|
120 | print '<b>Commit Hash</b>: <a href=\'https://github.com/flavour/eden/commit/'+line[0]+'\'>'+line[0]+'</a><br/> \
|
---|
121 | <b>Commit Message</b>: <a href=\'https://github.com/flavour/eden/commit/'+line[0]+'\'>'+line[3]+'</a><br/>\
|
---|
122 | <b>Commit Author </b>: '+line[1]+'<br/>\
|
---|
123 | <b>Commit Time</b> : '+line[2]+'<br/><br/>'"`
|
---|
124 | # Start the table for the results.
|
---|
125 | messageBody=$messageBody"<table width = '"100%"'>"
|
---|
126 | messageBody=$messageBody"<tr><td><b>Template</b></td><td><b>Test Type</b></td><td><b>Status</b></td><td></td></tr>"
|
---|
127 |
|
---|
128 | # Add test results
|
---|
129 | append_selenium_results IFRC
|
---|
130 | append_smoke_results IFRC
|
---|
131 | append_roles_results IFRC
|
---|
132 | append_selenium_results default
|
---|
133 | append_smoke_results default
|
---|
134 | append_selenium_results SandyRelief
|
---|
135 | append_smoke_results SandyRelief
|
---|
136 | append_selenium_results DRMP
|
---|
137 | append_smoke_results DRMP
|
---|
138 | append_selenium_results CRMT
|
---|
139 | append_smoke_results CRMT
|
---|
140 | append_smoke_results DRRPP
|
---|
141 | append_roles_results DRRPP
|
---|
142 |
|
---|
143 |
|
---|
144 | # End the table tag.
|
---|
145 | messageBody=$messageBody"</table>"
|
---|
146 |
|
---|
147 | # Add the head of the repository information
|
---|
148 | messageBody=$messageBody"<u><h4>Head Of the Repository during Testing at :</h4></u>\n$LINK_TO_LATEST_COMMIT \n\n"
|
---|
149 |
|
---|
150 | ##
|
---|
151 | # Prepare muttrc for this mail
|
---|
152 | echo 'set from="Sahana Eden CI Server <notifications@ci.eden.sahanafoundation.org>' > /tmp/muttrc
|
---|
153 | ##
|
---|
154 |
|
---|
155 | # Send the test results to the mailing list
|
---|
156 | echo -e $messageBody | mutt -e "set content_type=text/html" -s "Sahana Eden CI Server Test Results (`date -u "+%Y-%m-%d %H:%M UTC"`) " -F /tmp/muttrc -- sahana-eden-ci-server@googlegroups.com
|
---|
157 | #echo -e $messageBody | mutt -e "set content_type=text/html" -s "Sahana Eden CI Server Test Results (`date -u "+%Y-%m-%d %H:%M UTC"`) " -F /tmp/muttrc -- somay.jain@gmail.com
|
---|
158 |
|
---|
159 | if [ "$?" = '0' ]; then
|
---|
160 | echo "Mail Sent"
|
---|
161 | else
|
---|
162 | echo "Unable to Send file...."
|
---|
163 | fi
|
---|