blob: c6ff0c6204fdaeb6702aa4bc91b492d27833ca3d [file] [log] [blame]
david_williamsbd17e9e2008-01-20 05:05:16 +00001#!/usr/bin/env bash
2#
3# Script to promote the latest build in the specified committers area
4#
david_williamsbd17e9e2008-01-20 05:05:16 +00005
david_williamse69f1a02011-06-03 06:46:19 +00006function usage()
7{
david_williamsd4afb9c2011-02-15 06:38:09 +00008 printf "\n\tUsage: %s [-v] [-d] [-s] [-c] [-z] [-a] [-p] projectname " $(basename $0) >&2
david_williamsdd8549c2011-02-15 04:45:11 +00009 printf "\n\t\t%s\t%s" "-p <projectname>," "where projectname is a cc project, such as wtp-R3.2.3-M, wtp-R3.3.0-I, etc. from which to get latest build." >&2
david_williams01e8a412011-02-15 04:37:15 +000010 printf "\n\t\t%s\t%s" "-v" "verbose" >&2
11 printf "\n\t\t%s\t%s" "-d" "delete old builds" >&2
12 printf "\n\t\t%s\t%s" "-s" "send notification mail" >&2
13 printf "\n\t\t%s\t%s" "-c" "copy the build from committers to downloads" >&2
david_williams124777a2011-02-15 05:19:51 +000014 printf "\n\t\t%s\t%s" "-z" "process artifacts (create pack200 gz jars, etc.) Remember, is long running" >&2
15 printf "\n\t\t%s\t%s" "-a" "add properties" >&2
david_williams40769fd2011-02-15 04:42:28 +000016 printf "\n\t\t%s\t%s\n" "-h" "this help message" >&2
david_williams03bdf892008-02-02 03:00:11 +000017}
18
david_williams234ff412011-09-08 19:23:48 +000019# This "print arsgs" funtion is mostly a debugging aide, to help spot mistakes in invocation or command processing.
20# It could be later be changed to only print when in verbose mode, if seems like too much.
21function printargs()
22{
23
24echo "dump of script arguments"
25if [ $verboseFlag ]
26 then
27 echo " verbose output requested"
28 else
29 echo " verbose output NOT requested"
30fi
31
32if [ $deleteOld ]
33 then
34 echo " delete old requested"
35 else
36 echo " delete old NOT requested"
37fi
38
39if [ $doCopy ]
40 then
41 echo " copy requested"
42 else
43 echo " copy NOT requested"
44fi
45
46if [ $sendmail ]
47 then
48 echo " sendmail requested"
49 else
50 echo " sendmail NOT requested"
51fi
52
53if [ $processArtifacts ]
54 then
55 echo " processArtifacts requested"
56 else
57 echo " processArtifacts NOT requested"
58fi
59
60if [ $addProperties ]
61 then
62 echo " addProperties requested"
63 else
64 echo " addProperties NOT requested"
65fi
66
67}
68
david_williamse69f1a02011-06-03 06:46:19 +000069# see https://bugs.eclipse.org/bugs/show_bug.cgi?id=348028
david_williams3a6e7fa2011-06-04 16:36:36 +000070# for why mx might have to be so large as 1G
david_williamse69f1a02011-06-03 06:46:19 +000071# and this must be set early, since other's might read in commonVariations.shsource
david_williams3a6e7fa2011-06-04 16:36:36 +000072#export IBM_JAVA_OPTIONS=${IBM_JAVA_OPTIONS:-"-Dcom.ibm.tools.attach.enable=no -Xmx1G -Declipse.p2.mirrors=false"}
73export IBM_JAVA_OPTIONS=${IBM_JAVA_OPTIONS:-"-Dcom.ibm.tools.attach.enable=no -Declipse.p2.mirrors=false"}
david_williamse69f1a02011-06-03 06:46:19 +000074
75
david_williams33445492008-02-23 02:30:34 +000076source rsync-retry.sh
77
david_williams8bfa02a2008-01-22 05:34:52 +000078verboseFlag=
79deleteOld=
80doCopy=
81projectname=
david_williamseaa47b42011-02-15 04:11:49 +000082processArtifacts=
david_williams124777a2011-02-15 05:19:51 +000083addProperties=
84while getopts 'hvdcszap:' OPTION
david_williams8bfa02a2008-01-22 05:34:52 +000085do
86 case $OPTION in
david_williamsf1521c12008-05-30 20:20:25 +000087 h) usage
88 exit 1
89 ;;
david_williams8bfa02a2008-01-22 05:34:52 +000090 v) verboseFlag=1
91 ;;
92 d) deleteOld=1
93 ;;
94 c) doCopy=1
95 ;;
david_williams4e4949d2008-12-13 18:17:17 +000096 s) sendmail=1
97 ;;
david_williamseaa47b42011-02-15 04:11:49 +000098 z) processArtifacts=1
david_williams124777a2011-02-15 05:19:51 +000099 ;;
100 a) addProperties=1
david_williamseaa47b42011-02-15 04:11:49 +0000101 ;;
david_williamsd2601312011-03-18 04:42:16 +0000102 # we strip off ".ser", if present, just to make it easier to use with tab completion, etc., from
103 # releng.control directory, were the project files are named, for example, "wtp-R3.3.0-I.ser"
104 p) projectname=${OPTARG%\.ser}
david_williams8bfa02a2008-01-22 05:34:52 +0000105 ;;
david_williams03bdf892008-02-02 03:00:11 +0000106 ?) usage
david_williams8bfa02a2008-01-22 05:34:52 +0000107 exit 2
108 ;;
109 esac
110done
111
112shift $(($OPTIND - 1))
113
114
david_williams234ff412011-09-08 19:23:48 +0000115printargs
116
david_williams8bfa02a2008-01-22 05:34:52 +0000117
david_williams03bdf892008-02-02 03:00:11 +0000118# check we have at least the project name
david_williams8bfa02a2008-01-22 05:34:52 +0000119if [ -z $projectname ]
120then
121 printf "\n\t%s\n" "Error: project name is required." >&2
david_williams03bdf892008-02-02 03:00:11 +0000122 usage
david_williams8bfa02a2008-01-22 05:34:52 +0000123 exit 1
124fi
david_williamsbd17e9e2008-01-20 05:05:16 +0000125
david_williamsa3b65602010-08-01 17:50:32 +0000126if [[ "$projectname" =~ (.*)-(.*)-(.*) ]]
david_williamsbd17e9e2008-01-20 05:05:16 +0000127then
128 distribution=${BASH_REMATCH[1]}
129 buildBranch=${BASH_REMATCH[2]}
130 buildType=${BASH_REMATCH[3]}
131 printf "\n\t%s\n\n" "Promoting latest build from ${1} ..."
david_williams8bfa02a2008-01-22 05:34:52 +0000132 if [ $verboseFlag ]
133 then
134 echo "distribution: $distribution"
135 echo "buildBranch: $buildBranch"
136 echo "buildType: $buildType"
137 fi
david_williamsbd17e9e2008-01-20 05:05:16 +0000138else
david_williams03bdf892008-02-02 03:00:11 +0000139 printf "\n\t%s\n" "Error: projectname doesn't match <distribution>-<buildbranch>-<buildtype> pattern." >&2
140 usage
david_williamsbd17e9e2008-01-20 05:05:16 +0000141 exit 3
142fi
143
144# remember to leave no slashes on filename in source command,
145# (the commonVariations.shsource file, that is)
146# so that users path is used to find it (first)
147if [ -z $BUILD_INITIALIZED ]
148then
david_williams8bfa02a2008-01-22 05:34:52 +0000149 source commonVariations.shsource
david_williams8bfa02a2008-01-22 05:34:52 +0000150 source ${BUILD_HOME}/releng.control/commonComputedVariables.shsource
david_williamsbd17e9e2008-01-20 05:05:16 +0000151fi
152
153artifactsDir=${PROJECT_ARTIFACTS}
154promoteProjectDir=${artifactsDir}'/'${projectname}
david_williams8bfa02a2008-01-22 05:34:52 +0000155if [ $verboseFlag ]
156then
157 echo "Project directory to promote: ${promoteProjectDir} "
158fi
159
david_williamsbd17e9e2008-01-20 05:05:16 +0000160if [ ! \( -d ${promoteProjectDir} \) ]
161then
david_williams124777a2011-02-15 05:19:51 +0000162 printf "\n\t%s\n" "ERROR: directory ${promoteProjectDir} does not exist." >&2
david_williams03bdf892008-02-02 03:00:11 +0000163 usage
david_williamsbd17e9e2008-01-20 05:05:16 +0000164 exit 4
165fi
166
167i=0
168for FN in ${promoteProjectDir}/*
169do
170 dirName=$(basename ${FN})
david_williams8bfa02a2008-01-22 05:34:52 +0000171 if [ $verboseFlag ]
172 then
173 echo -n "${i}: "
174 echo ${dirName}
175 fi
176 # todo: could check that the name follows the expected date pattern
david_williamsbd17e9e2008-01-20 05:05:16 +0000177 dirList[${i}]=${dirName}
178 i=$(($i + 1))
179done
180
181nDir=${#dirList[*]}
182
david_williams8bfa02a2008-01-22 05:34:52 +0000183if [ $verboseFlag ]
184then
185 echo "Number of directories: ${nDir}"
186fi
david_williamsbd17e9e2008-01-20 05:05:16 +0000187
188# echo "Least recent: ${dirList[0]}"
189# echo "Most recent: ${dirList[$(($nDir - 1))]}"
190
191mostRecent=${dirList[$(($nDir - 1))]}
192
193mostRecentDir=${promoteProjectDir}/${mostRecent}
194
195
196i=0
197for FN in ${mostRecentDir}/*
198do
199 dropDirName=$(basename ${FN})
david_williams8bfa02a2008-01-22 05:34:52 +0000200 if [ $verboseFlag ]
201 then
202 echo -n "${i}: "
203 echo ${dropDirName}
204 fi
205 # todo: could check that the name follows the expected drop directory pattern
david_williamsbd17e9e2008-01-20 05:05:16 +0000206 dropDirList[${i}]=${dropDirName}
207 i=$(($i + 1))
208done
209
david_williams4cbceb72008-01-22 03:41:40 +0000210ndropDir=${#dropDirList[*]}
david_williamsbd17e9e2008-01-20 05:05:16 +0000211
212# there should be exactly one drop directory
david_williams4cbceb72008-01-22 03:41:40 +0000213if [ $ndropDir != 1 ]
david_williamsbd17e9e2008-01-20 05:05:16 +0000214then
david_williams8bfa02a2008-01-22 05:34:52 +0000215 printf "\n\t%s\n" "Error: there was not exactly one drop direc:tory. There was $ndropDir found instead." >&2
david_williams03bdf892008-02-02 03:00:11 +0000216 usage
david_williamsbd17e9e2008-01-20 05:05:16 +0000217 exit 5
david_williamsbd17e9e2008-01-20 05:05:16 +0000218fi
219
220# knowing there is exactly one, the value of dropDirName is still valid
221
david_williams8bfa02a2008-01-22 05:34:52 +0000222echo "Drop directory: ${dropDirName}"
david_williamsbd17e9e2008-01-20 05:05:16 +0000223
224FROMDIR=${mostRecentDir}/${dropDirName}
225
david_williams67098762011-09-18 00:56:42 +0000226# make sure RC has a value, in case no paths are taken that set it
227RC=0
228
david_williams6d540ce2011-02-15 05:30:47 +0000229if [[ $processArtifacts ]]
david_williamseaa47b42011-02-15 04:11:49 +0000230then
david_williamsa2b87ed2011-02-15 04:01:30 +0000231#run pack200 (and, recompute checksums) before literally promoting
232
david_williams35e02182011-06-03 05:44:00 +0000233
david_williamsa2b87ed2011-02-15 04:01:30 +0000234 repoDirLocation=$FROMDIR/repository
235 if [[ -d "${repoDirLocation}" ]]
236 then
david_williamseaa47b42011-02-15 04:11:49 +0000237 echo "INFO: processing artifacts in code repo: $repoDirLocation";
david_williamsa2b87ed2011-02-15 04:01:30 +0000238 ${RELENG_CONTROL}/runAntRunner.sh process-artifacts.xml -DrepoDirLocation="${repoDirLocation}"
david_williams046115d2011-09-08 18:53:11 +0000239 RC=$?
david_williamsa2b87ed2011-02-15 04:01:30 +0000240 else
david_williams046115d2011-09-08 18:53:11 +0000241 echo "ERROR: expected code repo directory does not exist: $repoDirLocation";
242 RC=2001
david_williamsa2b87ed2011-02-15 04:01:30 +0000243 fi
244
david_williams046115d2011-09-08 18:53:11 +0000245 if [ $RC -eq 0 ]
246 then
247 repoDirLocation=$FROMDIR/repositoryunittests
248 if [[ -d "${repoDirLocation}" ]]
249 then
250 echo "INFO: calling processing artifacts in test repo: $repoDirLocation";
251 ${RELENG_CONTROL}/runAntRunner.sh process-artifacts.xml -DrepoDirLocation="${repoDirLocation}"
252 RC=$?
253 else
254 echo "ERROR: expected test repo directory does not exist: $repoDirLocation";
255 RC=2002
256 fi
257 fi
david_williamseaa47b42011-02-15 04:11:49 +0000258fi
david_williamsa2b87ed2011-02-15 04:01:30 +0000259
david_williams046115d2011-09-08 18:53:11 +0000260if [ $RC != 0 ]
261 then
262 echo "ERROR: pack processing did not operate as expected. Exiting the promote script early."
263 exit $RC
264 fi
265
david_williamsb903b422011-02-15 06:12:50 +0000266# Remember, add properties should be called after process artifacts.
david_williams124777a2011-02-15 05:19:51 +0000267# TODO: we currently do not add properties to tests repo ... maybe should? for mirror URL, at least.
david_williamsb903b422011-02-15 06:12:50 +0000268# TODO: a fourth and fifth argument can be specified to addRepoProperties.sh to provide better stats marking.
269# A version indicator that becomes part of URI, such as /helios, /indigo, etc, and
270# a suffix, to signify releases, such as
271# such as _helios_SR2, _indigo_SR0 ... but, these will take some customization, and remember to update them fairly often, to be accurate.
272# And, we do not particularly use anyway.
273# Also, the addProperties app has some ability to add name property (but not in our releng repo yet).
david_williams09f97372011-02-15 05:44:15 +0000274if [[ $addProperties ]]
275then
276 repoDirLocation=$FROMDIR/repository
277 if [[ -d "${repoDirLocation}" ]]
278 then
279 ${RELENG_CONTROL}/addRepoProperties.sh "${repoDirLocation}" "${buildBranch}" "${dropDirName}"
280 else
281 echo "ERROR: addProperties requested, but repo location does not exist: ${repoDirLocation}";
282 fi
283fi
david_williams124777a2011-02-15 05:19:51 +0000284
david_williams34f3f912008-07-08 01:36:22 +0000285if [ "patches" == $distribution ]
286then
287 TODIR=${DOWNLOAD_ROOT}/webtools/patches/drops/${buildBranch}/
288else
289 TODIR=${DOWNLOAD_ROOT}/webtools/downloads/drops/${buildBranch}/
290fi
david_williamsf6963892008-01-20 05:38:13 +0000291
292printf "\t%s\n" "declaring build ${dropDirName} on buildstream ${buildBranch}"
293printf "\t\t%s\n" "into ${TODIR}"
294printf "\t\t%s\n\n" "using the build from ${FROMDIR}"
david_williamsbd17e9e2008-01-20 05:05:16 +0000295
david_williams8bfa02a2008-01-22 05:34:52 +0000296if [ $doCopy ]
david_williams26840072008-01-22 03:32:43 +0000297then
david_williams33445492008-02-23 02:30:34 +0000298 rsync-retry ${FROMDIR} ${TODIR} $verboseFlag
299 exitCode=$?
300 if [ $exitCode -ne 0 ]
301 then
302 exit $exitCode
303 fi
david_williams26840072008-01-22 03:32:43 +0000304
david_williams8bfa02a2008-01-22 05:34:52 +0000305 fromString="webtools/committers"
david_williams9db6fa42008-08-25 17:03:10 +0000306 if [ "patches" == $distribution ]
307 then
308 toString="webtools/patches"
309 else
310 toString="webtools/downloads"
david_williams55ecb6d2008-08-26 03:52:18 +0000311 fi
david_williams8bfa02a2008-01-22 05:34:52 +0000312 replaceCommand="s!${fromString}!${toString}!g"
david_williamsbd17e9e2008-01-20 05:05:16 +0000313
david_williams0be0d972008-02-16 05:38:57 +0000314 # remember TODIR already has a slash
david_williams67b15622011-07-03 00:45:12 +0000315 perl -w -pi -e ${replaceCommand} ${TODIR}${dropDirName}/*.php
david_williamsbd17e9e2008-01-20 05:05:16 +0000316
david_williams20067502011-01-22 07:00:56 +0000317 # now do the composite reference site update
318
319 case $buildType in
david_williamsc479bd22011-05-22 17:05:38 +0000320 R )
321 referenceCompositeDir=${BUILD_HOME}/integration;;
322 S )
323 referenceCompositeDir=${BUILD_HOME}/integration;;
david_williams20067502011-01-22 07:00:56 +0000324 I )
david_williamsdaf6fdf2011-01-22 07:41:28 +0000325 referenceCompositeDir=${BUILD_HOME}/integration;;
david_williams20067502011-01-22 07:00:56 +0000326 M )
david_williamsdaf6fdf2011-01-22 07:41:28 +0000327 referenceCompositeDir=${BUILD_HOME}/maintenance;;
david_williams20067502011-01-22 07:00:56 +0000328 * )
david_williamsc479bd22011-05-22 17:05:38 +0000329 printf "warning: 'buildType' ($buildType) was not an expected value."
330 printf " composite reference not updated." ;;
david_williams20067502011-01-22 07:00:56 +0000331 esac
david_williamsdaf6fdf2011-01-22 07:41:28 +0000332 if [ ! -z referenceCompositeDir ]
david_williams20067502011-01-22 07:00:56 +0000333 then
334 dropDirectory=${TODIR}${dropDirName}
david_williamsd69c3c42011-01-22 07:51:48 +0000335 ./runAntRunner.sh "${PWD}/updateReferenceComposite.xml" "-DreferenceCompositeDir=$referenceCompositeDir" "-DdropDirectory=$dropDirectory"
david_williams20067502011-01-22 07:00:56 +0000336 fi
david_williams8bfa02a2008-01-22 05:34:52 +0000337else
david_williams03bdf892008-02-02 03:00:11 +0000338 printf "\n\t%s\n\n" "Nothing copied: specify -c to actually do the copy"
david_williams26840072008-01-22 03:32:43 +0000339fi
david_williamsbd17e9e2008-01-20 05:05:16 +0000340
david_williams4e4949d2008-12-13 18:17:17 +0000341if [ $sendmail ]
342then
343 ./sendPromoteMail.sh "$projectname" "$TODIR" "$dropDirName"
344 echo "mail sent"
345else
346 echo "no mail sent. Specify -s if desired"
347fi
348
david_williams03bdf892008-02-02 03:00:11 +0000349
350if [ $deleteOld ]
351then
352
353 maxToDelete=$(($nDir - 1))
354 if [ $verboseFlag ]
355 then
356 echo "maxToDelete: $maxToDelete"
357 fi
358 for (( i=0; i < $maxToDelete; i++))
359 do
360 dirbasename=${dirList[$i]}
361 dropDirName=${promoteProjectDir}/${dirbasename}
362 if [ $verboseFlag ]
363 then
364 echo -n "${i}: "
365 echo ${dropDirName}
366 fi
367 rm -fr ${dropDirName}
368 done
369
370fi
david_williams234ff412011-09-08 19:23:48 +0000371
372printargs