Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 38eaad772ae45c5189e513fda88a11071313a5f1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
#!/usr/bin/env bash

export PROMOTION_SCRIPT_PATH=${PROMOTION_SCRIPT_PATH:-$( dirname $0 )}
echo "PROMOTION_SCRIPT_PATH: ${PROMOTION_SCRIPT_PATH}"
source ${PROMOTION_SCRIPT_PATH}/syncUpdateUtils.shsource

# Utility to convert raw millisecond string of digits to "hours, minutes" type
# of display string.
# TODO: should allow a few types of "desired format" to be specified, such as
# in addition to current "hours and minutes" perhaps "minutes and seconds", etc.

function show_hours_minutes ()
{
  TESTING=${TESTING:-"false"}
  num=$1

  # if no decimal points in input number, we assume it is already in the msec form
  # we want, and this initial conversion to have correct number of zeros
  # are not needed. Otherwise they 'increase' the number (See bug 485084).
  if [[ "$num" =~ .*\..* ]]
  then
    # if more than one decimal point, 'convert...' writes an error to standard error,
    # and returns "InvalidInput"
    num=$(convertToZeroPaddedMillisecs $num)
  fi
  if [[ $TESTING == "true" ]]
  then
    printf "\tInput: %s \t" "$num"
  fi
  # we are sometimes given seconds.milliseconds so we convert to milliseconds
  # by removing the period. Equivalent to seconds times 1000. Just to have common
  # staring point, as integer, since bash can not do 'float' arithmetic.
  num="${num//.}"
  # sanity test input is all digits
  all_digits="^([0-9]+)$"
  if [[ ${num} =~ ${all_digits} ]]
  then
    msecs=0
    sec=0
    min=0
    hour=0
    day=0
    # assign to radix 10 just to remove leading zeros
    # in some computations, leading zeros will cause number to be
    # interpreted as hex.
    ((num=10#$num))
    if ((num>1000))
    then
      ((msecs=num%1000))
      ((num=num/1000))
      if ((num>59))
      then
        ((sec=num%60))
        ((num=num/60))
        if((num>59))
        then
          ((min=num%60))
          ((num=num/60))
          if((num>23))
          then
            ((hour=num%24))
            ((day=num/24))
          else
            ((hour=num))
          fi
        else
          ((min=num))
        fi
      else
        ((sec=num))
      fi
    else
      msecs=$num
    fi
    if [[ "${TESTING}" == "true" ]]
    then
      echo "TESTING: days: $day hours: $hour mins: $min secs: $sec msecs $msecs"
    else
      echo "$hour h  $min m"
    fi
  else
    if [[ -z "${num}" ]]
    then
      echo -e "\n\tInvalid argument: it must be all digits, but was null or empty"
    else
      echo -e "\n\tInvalid argument: it must be all digits, but was >${num}<"
    fi
  fi
}

# compute main (left part) of download site
function dlpath()
{
  eclipseStream=$1
  if [[ -z "${eclipseStream}" ]]
  then
    printf "\n\n\t%s\n\n" "ERROR: Must provide eclipseStream as first argument, for this function $(basename $0)"
    return 1;
  fi


  buildId=$2
  if [[ -z "${buildId}" ]]
  then
    printf "\n\n\t%s\n\n" "ERROR: Must provide buildId as second argument, for this function $(basename $0)"
    return 1;
  fi

  eclipseStreamMajor=${eclipseStream:0:1}
  buildType=${buildId:0:1}

  pathToDL=eclipse/downloads/drops
  if (( $eclipseStreamMajor > 3 ))
  then
    pathToDL=$pathToDL$eclipseStreamMajor
  fi

  echo $pathToDL
}


# update index on build machine with test results
function updatePages()
{
  eclipseStream=$1
  buildId=$2
  EBUILDER_HASH=$3
  if [[ -z "${EBUILDER_HASH}" ]]
  then
    printf "\n\n\t%s\n\n" "ERROR: Must provide builder (or aggregator) hash as third argument, for this function $(basename $0)"
    return 1;
  fi

  JOB_NAME=$4
  if [[ -z "${JOB_NAME}" ]]
  then
    printf "\n\n\t%s\n\n" "ERROR: Must provide JOB_NAME as fourth argument, for this function $(basename $0)"
    return 1;
  fi
  JOB_NUMBER=$5
  if [[ -z "${JOB_NUMBER}" ]]
  then
    # technically, may not be needed, just effects some directory names, but will require, for now.
    printf "\n\n\t%s\n\n" "ERROR: JOB_NUMBER as fifth argument was not provided, for this function $(basename $0). Exiting."
    exit 1
  fi
  eclipseStreamMajor=${eclipseStream:0:1}
  buildType=${buildId:0:1}

  echo "-- properties in updateDropLocation.sh function updatePages --"
  echo "eclipseStreamMajor: $eclipseStreamMajor"
  echo "buildType: $buildType"
  echo "eclipseStream: $eclipseStream"
  echo "buildId: $buildId"
  echo "EBUILDER_HASH: $EBUILDER_HASH"
  echo "JOB_NAME: $JOB_NAME"
  echo "JOB_NUMBER: $JOB_NUMBER"

  # compute directory on build machine
  dropFromBuildDir=$( dropFromBuildDir "$eclipseStream" "$buildId" )
  echo "dropFromBuildDir: $dropFromBuildDir"


  eclipsebuilder=eclipse.platform.releng.aggregator
  ebuilderDropDir="${dropFromBuildDir}/${eclipsebuilder}/production/testScripts"
  echo "DEBUG: ebuilderDropDir: ${ebuilderDropDir}"

  ${ebuilderDropDir}/updateTestResultsPages.sh  $eclipseStream $buildId $JOB_NAME $JOB_NUMBER
  rccode=$?
  if [[ $rccode != 0 ]]
  then
    printf "\n\n\t%s\n\n" "ERROR occurred while updating test pages."
    return $rccode
  fi

}

function sendTestResultsMail ()
{

  SITE_HOST=${SITE_HOST:-download.eclipse.org}

  echo "     Starting sendTestResultsMail"
  eclipseStream=$1
  if [[ -z "${eclipseStream}" ]]
  then
    printf "\n\n\t%s\n\n" "ERROR: Must provide eclipseStream as first argument, for this function $(basename $0)"
    return 1;
  fi
  echo "     eclipseStream: ${eclipseStream}"

  buildId=$2
  if [[ -z "${buildId}" ]]
  then
    printf "\n\n\t%s\n\n" "ERROR: Must provide buildId as second argument, for this function $(basename $0)"
    return 1;
  fi
  echo "     buildId: ${buildId}"

  JOB_NAME=$3
  if [[ -z "${JOB_NAME}" ]]
  then
    printf "\n\n\t%s\n\n" "ERROR: Must provide JOB_NAME as third argument, for this function $(basename $0)"
    return 1;
  fi
  echo "     JOB_NAME: ${JOB_NAME}"

  JOB_NUMBER=$4
  if [[ -z "${JOB_NUMBER}" ]]
  then
    printf "\n\n\t%s\n\n" "ERROR: Must provide JOB_NUMBER as fourth argument, for this function $(basename $0)"
    return 1;
  fi
  echo "     JOB_NUMBER: ${JOB_NUMBER}"

  buildType=${buildId:0:1}
  echo "     buildType: ${buildType}"


  fsDocRoot="/home/data/httpd/download.eclipse.org"

  mainPath=$( dlToPath "$eclipseStream" "$buildId")
  echo "     mainPath: $mainPath"
  if [[ "$mainPath" == 1 ]]
  then
    printf "\n\n\t%s\n\n" "ERROR: mainPath could not be computed."
    return 1
  fi

  downloadURL="http://${SITE_HOST}/${mainPath}/${buildId}/"
  fsDownloadSitePath="${fsDocRoot}/${mainPath}/${buildId}"

  export BUILD_HOME=${BUILD_HOME:-/shared/eclipse/builds}
  buildRoot=${BUILD_HOME}/${eclipseStreamMajor}${buildType}
  testsSummary="eclipse/downloads/drops4/${buildId}/testresults/${JOB_NAME}-${JOB_NUMBER}.xml"
  eclipseSiteTestFile="${buildRoot}/siteDir/${testsSummary}"
  echo -e "\n\tDEBUG: eclipseSiteTestFile: ${eclipseSiteTestFile}"
  if [[ ! -e "${eclipseSiteTestFile}" ]]
  then
    echo -e "\nProgramming error. The test summary file was not found where expected:"
    echo -e "\t${eclipseSiteTestFile}"
    return 1
  else
    # Had trouble reading this file in a while loop. Perhaps because it is one line,
    # with no EOL character?
    read -r line <  "${eclipseSiteTestFile}"
    echo -e "\n\tDEBUG: Text read from test summary file: ${line}"
    pattern="^.*<duration>(.*)</duration><failCount>(.*)</failCount><passCount>(.*)</passCount>.*$"
    if [[ "${line}" =~ ${pattern} ]]
    then
      testsDuration=${BASH_REMATCH[1]}
      testsFailed=${BASH_REMATCH[2]}
      testsPassed=${BASH_REMATCH[3]}
    else
      echo -e "\n\tProgramming error. We should always match!?"
      echo -e "\n\tDEBUG: line: ${line}"
    fi
    
    platform=$(echo ${JOB_NAME}|cut -b 12-16)
    case "$platform" in
        "win32")
            HUDSON_URL="${HUDSON_PROTOCOL}://${HUDSON_HOST}:${HUDSON_PORT}/shared/view/Eclipse and Equinox"
            ;;
        "mac64")
            HUDSON_URL="${HUDSON_PROTOCOL}://${HUDSON_HOST}:${HUDSON_PORT}/shared/view/Eclipse and Equinox"
            ;;
        *)
            HUDSON_URL="${HUDSON_PROTOCOL}://${HUDSON_HOST}:${HUDSON_PORT}/${HUDSON_ROOT_URI}/view/Automated tests"
            ;;
    esac

    # Now read "elapsed time" duration from Hudson. (The time above is the sum of all unit tests times,
    # so does not include "overhead" and is deceptive.) The "-O -" means send output to standard out (instead of file).
    # Discovered that "xpath plugin 1.03" was needed. Initially had 1.0.2 on local test system.
    elapsedTimeDuration=$( wget -O - "${HUDSON_URL}/job/${JOB_NAME}/${JOB_NUMBER}/api/xml?xpath=/*/duration/text%28%29")

    # Subject is similar to "build finished" subject in syncDropLocation.sh.
    # 4.3.0 I-Build: I20120411-2034: 7 failures from ep46I-unit-mac64
    if [[ "${testsFailed}" -eq 1 ]]
    then
      failures="failure"
    else
      failures="failures"
    fi
    if [[ "${buildType}" == "M" ]]
    then
        SUBJECT="${eclipseStream}a ${buildType}-Build: ${buildId}: ${testsFailed} ${failures} from ${JOB_NAME}"
    else
        SUBJECT="${eclipseStream} ${buildType}-Build: ${buildId}: ${testsFailed} ${failures} from ${JOB_NAME}"
    fi

    setToAndFromAddresses

    # Artificially mark each message for a particular build with unique message-id-like value.
    # Even though technically incorrect for the initial message it seems to work in
    # most situations.
    InReplyTo="<${buildId}@build.eclipse.org/build/eclipse/>"
    Reference="${InReplyTo}"

    # repeat subject in message
    message1="<p>${SUBJECT}</p>\n"
    link=$(linkURL ${downloadURL}testResults.php)
    message1="${message1}<p>&nbsp;&nbsp;&nbsp;Build logs and test results: <br />\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${link}</p>\n"


    message1="${message1}<p>&nbsp;&nbsp;&nbsp;Tests Passed: ${testsPassed} &nbsp;&nbsp;&nbsp; Total Number of Tests: $(( testsFailed + testsPassed )) &nbsp;&nbsp;&nbsp; Total Tests Time: $(show_hours_minutes ${testsDuration}) &nbsp;&nbsp;&nbsp; Total Elapsed Time: $(show_hours_minutes ${elapsedTimeDuration} )</p>\n"

    link=$(linkURL "${HUDSON_URL}/")
    message1="${message1}<br /><p>&nbsp;&nbsp;&nbsp;In general, the tests can be viewed on Hudson at <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${link}</p>\n"

    link=$(linkURL "${HUDSON_URL}/job/${JOB_NAME}/${JOB_NUMBER}/")
    message1="${message1}<br /><p>&nbsp;&nbsp;&nbsp;For this specific test the specific Hudson job results can be viewed at<br />\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${link}</p>\n"

    sendEclipseMail "${TO}" "${FROM}" "${SUBJECT}" "${message1}"

    echo "INFO: test results mail sent for ${eclipseStream} ${buildType}-build ${buildId}"

    return 0
  fi
}

# We do the 'main' function, only if TESTING is not 'true'.
# This allows us to test individual functions easily, such as the
# show_hours_minutes function.

if [[ "${TESTING}" != "true" ]]
then

  # this is the single script to call that "does it all" update DL page
  # with test results, and updates index.php summaries.
  # it requires four arguments
  #    eclipseStream (e.g. 4.2 or 3.8)
  #    buildId       (e.g. N20120415-2015)
  #    EBUILDER_HASH (SHA1 HASH or branch of eclipse builder to used

  if [[ "${#}" -lt "4" ]]
  then
    # usage:
    scriptname=$(basename $0)
    printf "\n\t%s\n" "PROGRAM ERROR: This script, $scriptname requires four arguments, in order: "
    printf "\t\t%s\t%s\n" "eclipseStream" "(e.g. 4.2.2 or 3.8.2) "
    printf "\t\t%s\t%s\n" "buildId" "(e.g. N20120415-2015) "
    printf "\t\t%s\t%s\n" "EBUILDER_HASH" "(SHA1 HASH for eclipse builder used) "
    printf "\t\t%s\t%s\n" "JOB_NAME" "job name from Hudson"
    printf "\t%s\n" "for example,"
    printf "\t%s\n\n" "./$scriptname 4.5.1 N20120415-2015 master ep4I-unit-lin64"
    exit 1
  fi

  echo "Starting $0"

  eclipseStream=$1
  if [[ -z "${eclipseStream}" ]]
  then
    printf "\n\n\t%s\n\n" "ERROR: Must provide eclipseStream as first argument, for this function $(basename $0)"
    exit 1
  fi
  echo "eclipseStream: $eclipseStream"

  buildId=$2
  if [[ -z "${buildId}" ]]
  then
    printf "\n\n\t%s\n\n" "ERROR: Must provide buildId as second argument, for this function $(basename $0)"
    exit 1
  fi
  echo "buildId: $buildId"

  EBUILDER_HASH=$3
  if [[ -z "${EBUILDER_HASH}" ]]
  then
    printf "\n\n\t%s\n\n" "ERROR: Must provide builder (or aggregator) hash as third argument, for this function $(basename $0)"
    exit 1;
  fi
  echo "EBUILDER_HASH: $EBUILDER_HASH"

  JOB_NAME=$4
  if [[ -z "${JOB_NAME}" ]]
  then
    printf "\n\n\t%s\n\n" "ERROR: Must provide job (JOB_NAME) as fourth argument, for this function $(basename $0)"
    exit 1;
  fi
  echo "JOB_NAME: $JOB_NAME"

  JOB_NUMBER=$5
  if [[ -z "${JOB_NUMBER}" ]]
  then
    printf "\n\n\t%s\n\n" "ERROR: Must provide job number (JOB_NUMBER) as fifth argument, for this function $(basename $0)"
    exit 1;
  fi
  echo "JOB_NUMBER: $JOB_NUMBER"

  eclipseStreamMajor=${eclipseStream:0:1}
  buildType=${buildId:0:1}
  echo "buildType: $buildType"

  # = = = = = = = = =
  # compute directory on build machine
  dropFromBuildDir=$( dropFromBuildDir "$eclipseStream" "$buildId" )
  echo "dropFromBuildDir: $dropFromBuildDir"

  if [[ "${dropFromBuildDir}" == "1" ]]
  then
    echo "dropDir did not complete normally, returned '1'."
    exit 1
  fi

  if [[ ! -d "${dropFromBuildDir}" ]]
  then
    echo "ERROR: expected toDir (drop directory) did not exist"
    echo "       drop directory: ${dropFromBuildDir}"
    exit 1
  fi
  export PROMOTION_SCRIPT_PATH=${PROMOTION_SCRIPT_PATH:-$( dirname $0 )}
  ${PROMOTION_SCRIPT_PATH}/getEBuilder.sh "${EBUILDER_HASH}" "${dropFromBuildDir}"

  updatePages $eclipseStream $buildId "${EBUILDER_HASH}" $JOB_NAME $JOB_NUMBER
  rccode=$?
  if [ $rccode -ne 0 ]
  then
    echo "ERROR occurred during promotion to download server: rccode: $rccode."
    exit $rccode
  fi

  syncDropLocation "$eclipseStream" "$buildId" "${EBUILDER_HASH}"
  rccode=$?
  if [ $rccode -ne 0 ]
  then
    echo "ERROR occurred during promotion to download server: rccode: $rccode."
    exit $rccode
  fi



  # do not send for performance tests, for now
  if [[ ! "${JOB_NAME}" =~ .*-perf-.* ]]
  then
    sendTestResultsMail "$eclipseStream" "$buildId" "${JOB_NAME}" "${JOB_NUMBER}"
  fi

  exit 0

fi

Back to the top