blob: bdba2f9a11cb937109e6cd3ffd870ac584ce95fe [file] [log] [blame]
david_williamsbd17e9e2008-01-20 05:05:16 +00001#!/usr/bin/env bash
nickboldt03a6f082019-02-12 15:17:11 -05002#*******************************************************************************
3# Copyright (c) 2008, 2019 IBM Corporation and others.
4# This program and the accompanying materials
5# are made available under the terms of the Eclipse Public License 2.0
6# which accompanies this distribution, and is available at
7# https://www.eclipse.org/legal/epl-2.0/
8#
9# SPDX-License-Identifier: EPL-2.0
10#
11# Contributors:
12# IBM Corporation - initial API and implementation
13#*******************************************************************************
david_williamsbd17e9e2008-01-20 05:05:16 +000014#
nickboldta179b752018-03-15 10:41:53 -040015# V2.1
david_williamsbd17e9e2008-01-20 05:05:16 +000016# Script to promote the latest build in the specified committers area
nickboldta179b752018-03-15 10:41:53 -040017# Change control
18# [425061] A static URL to latest integration build :: New function added to synchronize the I-latest directory with the repository and repositoryunittests from the build when required ==> [-r] option
19#
david_williamse69f1a02011-06-03 06:46:19 +000020function usage()
21{
nickboldta179b752018-03-15 10:41:53 -040022 printf "\n\tUsage: %s [-v] [-d] [-s] [-c] [-r] [-z] [-a] [-p] projectname " $(basename $0) >&2
david_williamsdd8549c2011-02-15 04:45:11 +000023 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 +000024 printf "\n\t\t%s\t%s" "-v" "verbose" >&2
25 printf "\n\t\t%s\t%s" "-d" "delete old builds" >&2
26 printf "\n\t\t%s\t%s" "-s" "send notification mail" >&2
27 printf "\n\t\t%s\t%s" "-c" "copy the build from committers to downloads" >&2
nickboldta179b752018-03-15 10:41:53 -040028 printf "\n\t\t%s\t%s" "-r" "refresh I-latest with current build" >&2
29 printf "\n\t\t%s\t%s" "-z" "process artifacts (create pack200 gz jars, etc.) Remember, is long running. NOTE: This is not required for builds >=3.6.1" >&2
david_williams124777a2011-02-15 05:19:51 +000030 printf "\n\t\t%s\t%s" "-a" "add properties" >&2
david_williams40769fd2011-02-15 04:42:28 +000031 printf "\n\t\t%s\t%s\n" "-h" "this help message" >&2
david_williams03bdf892008-02-02 03:00:11 +000032}
33
david_williams234ff412011-09-08 19:23:48 +000034# This "print arsgs" funtion is mostly a debugging aide, to help spot mistakes in invocation or command processing.
35# It could be later be changed to only print when in verbose mode, if seems like too much.
36function printargs()
37{
38
39echo "dump of script arguments"
40if [ $verboseFlag ]
41 then
42 echo " verbose output requested"
43 else
44 echo " verbose output NOT requested"
45fi
46
47if [ $deleteOld ]
48 then
49 echo " delete old requested"
50 else
51 echo " delete old NOT requested"
52fi
53
54if [ $doCopy ]
55 then
56 echo " copy requested"
57 else
58 echo " copy NOT requested"
59fi
60
61if [ $sendmail ]
62 then
63 echo " sendmail requested"
64 else
65 echo " sendmail NOT requested"
66fi
67
68if [ $processArtifacts ]
69 then
70 echo " processArtifacts requested"
71 else
72 echo " processArtifacts NOT requested"
73fi
74
75if [ $addProperties ]
76 then
77 echo " addProperties requested"
78 else
79 echo " addProperties NOT requested"
80fi
81
nickboldta179b752018-03-15 10:41:53 -040082if [ $syncLatest ]
83 then
84 echo " refresh I-latest repositories requested"
85 else
86 echo " refresh I-latest repositories NOT requested"
87fi
88
david_williams234ff412011-09-08 19:23:48 +000089}
90
david_williamse69f1a02011-06-03 06:46:19 +000091# see https://bugs.eclipse.org/bugs/show_bug.cgi?id=348028
david_williams3a6e7fa2011-06-04 16:36:36 +000092# for why mx might have to be so large as 1G
david_williamse69f1a02011-06-03 06:46:19 +000093# and this must be set early, since other's might read in commonVariations.shsource
david_williams3a6e7fa2011-06-04 16:36:36 +000094#export IBM_JAVA_OPTIONS=${IBM_JAVA_OPTIONS:-"-Dcom.ibm.tools.attach.enable=no -Xmx1G -Declipse.p2.mirrors=false"}
95export IBM_JAVA_OPTIONS=${IBM_JAVA_OPTIONS:-"-Dcom.ibm.tools.attach.enable=no -Declipse.p2.mirrors=false"}
david_williamse69f1a02011-06-03 06:46:19 +000096
97
david_williams33445492008-02-23 02:30:34 +000098source rsync-retry.sh
99
david_williams8bfa02a2008-01-22 05:34:52 +0000100verboseFlag=
101deleteOld=
102doCopy=
103projectname=
david_williamseaa47b42011-02-15 04:11:49 +0000104processArtifacts=
david_williams124777a2011-02-15 05:19:51 +0000105addProperties=
nickboldta179b752018-03-15 10:41:53 -0400106syncLatest=
107while getopts 'hvdcrszap:' OPTION
david_williams8bfa02a2008-01-22 05:34:52 +0000108do
109 case $OPTION in
david_williamsf1521c12008-05-30 20:20:25 +0000110 h) usage
111 exit 1
112 ;;
david_williams8bfa02a2008-01-22 05:34:52 +0000113 v) verboseFlag=1
114 ;;
115 d) deleteOld=1
116 ;;
117 c) doCopy=1
118 ;;
david_williams4e4949d2008-12-13 18:17:17 +0000119 s) sendmail=1
120 ;;
david_williamseaa47b42011-02-15 04:11:49 +0000121 z) processArtifacts=1
david_williams124777a2011-02-15 05:19:51 +0000122 ;;
123 a) addProperties=1
nickboldta179b752018-03-15 10:41:53 -0400124 ;;
125 r) syncLatest=1
david_williamseaa47b42011-02-15 04:11:49 +0000126 ;;
david_williamsd2601312011-03-18 04:42:16 +0000127 # we strip off ".ser", if present, just to make it easier to use with tab completion, etc., from
128 # releng.control directory, were the project files are named, for example, "wtp-R3.3.0-I.ser"
129 p) projectname=${OPTARG%\.ser}
david_williams8bfa02a2008-01-22 05:34:52 +0000130 ;;
david_williams03bdf892008-02-02 03:00:11 +0000131 ?) usage
david_williams8bfa02a2008-01-22 05:34:52 +0000132 exit 2
133 ;;
134 esac
135done
136
137shift $(($OPTIND - 1))
138
139
david_williams234ff412011-09-08 19:23:48 +0000140printargs
141
david_williams8bfa02a2008-01-22 05:34:52 +0000142
david_williams03bdf892008-02-02 03:00:11 +0000143# check we have at least the project name
david_williams8bfa02a2008-01-22 05:34:52 +0000144if [ -z $projectname ]
145then
146 printf "\n\t%s\n" "Error: project name is required." >&2
david_williams03bdf892008-02-02 03:00:11 +0000147 usage
david_williams8bfa02a2008-01-22 05:34:52 +0000148 exit 1
149fi
david_williamsbd17e9e2008-01-20 05:05:16 +0000150
david_williamsa3b65602010-08-01 17:50:32 +0000151if [[ "$projectname" =~ (.*)-(.*)-(.*) ]]
david_williamsbd17e9e2008-01-20 05:05:16 +0000152then
153 distribution=${BASH_REMATCH[1]}
154 buildBranch=${BASH_REMATCH[2]}
155 buildType=${BASH_REMATCH[3]}
156 printf "\n\t%s\n\n" "Promoting latest build from ${1} ..."
david_williams8bfa02a2008-01-22 05:34:52 +0000157 if [ $verboseFlag ]
158 then
159 echo "distribution: $distribution"
160 echo "buildBranch: $buildBranch"
161 echo "buildType: $buildType"
162 fi
david_williamsbd17e9e2008-01-20 05:05:16 +0000163else
david_williams03bdf892008-02-02 03:00:11 +0000164 printf "\n\t%s\n" "Error: projectname doesn't match <distribution>-<buildbranch>-<buildtype> pattern." >&2
165 usage
david_williamsbd17e9e2008-01-20 05:05:16 +0000166 exit 3
167fi
168
169# remember to leave no slashes on filename in source command,
170# (the commonVariations.shsource file, that is)
171# so that users path is used to find it (first)
172if [ -z $BUILD_INITIALIZED ]
173then
david_williams8bfa02a2008-01-22 05:34:52 +0000174 source commonVariations.shsource
david_williams8bfa02a2008-01-22 05:34:52 +0000175 source ${BUILD_HOME}/releng.control/commonComputedVariables.shsource
david_williamsbd17e9e2008-01-20 05:05:16 +0000176fi
177
178artifactsDir=${PROJECT_ARTIFACTS}
179promoteProjectDir=${artifactsDir}'/'${projectname}
david_williams8bfa02a2008-01-22 05:34:52 +0000180if [ $verboseFlag ]
181then
182 echo "Project directory to promote: ${promoteProjectDir} "
183fi
184
david_williamsbd17e9e2008-01-20 05:05:16 +0000185if [ ! \( -d ${promoteProjectDir} \) ]
186then
david_williams124777a2011-02-15 05:19:51 +0000187 printf "\n\t%s\n" "ERROR: directory ${promoteProjectDir} does not exist." >&2
david_williams03bdf892008-02-02 03:00:11 +0000188 usage
david_williamsbd17e9e2008-01-20 05:05:16 +0000189 exit 4
190fi
191
192i=0
193for FN in ${promoteProjectDir}/*
194do
195 dirName=$(basename ${FN})
david_williams8bfa02a2008-01-22 05:34:52 +0000196 if [ $verboseFlag ]
197 then
198 echo -n "${i}: "
199 echo ${dirName}
200 fi
201 # todo: could check that the name follows the expected date pattern
david_williamsbd17e9e2008-01-20 05:05:16 +0000202 dirList[${i}]=${dirName}
203 i=$(($i + 1))
204done
205
206nDir=${#dirList[*]}
207
david_williams8bfa02a2008-01-22 05:34:52 +0000208if [ $verboseFlag ]
209then
210 echo "Number of directories: ${nDir}"
211fi
david_williamsbd17e9e2008-01-20 05:05:16 +0000212
213# echo "Least recent: ${dirList[0]}"
214# echo "Most recent: ${dirList[$(($nDir - 1))]}"
215
216mostRecent=${dirList[$(($nDir - 1))]}
217
218mostRecentDir=${promoteProjectDir}/${mostRecent}
219
220
221i=0
222for FN in ${mostRecentDir}/*
223do
224 dropDirName=$(basename ${FN})
nickboldt17958d82020-01-30 16:05:17 -0500225 # Check that the name follows the expected drop directory pattern, S-3.17.0.M2-20200130040242
226 if [[ ${dropDirName} =~ ^.*[0-9]{14}$ ]]; then
227 dropDirList[${i}]=${dropDirName}
228 i=$(($i + 1))
229 if [ $verboseFlag ]; then
230 echo "${i}: ${dropDirName}"
231 fi
232 else
233 if [ $verboseFlag ]; then
234 echo "${i}: SKIP: ${dropDirName} (does not match expected directory pattern)"
235 fi
david_williams8bfa02a2008-01-22 05:34:52 +0000236 fi
david_williamsbd17e9e2008-01-20 05:05:16 +0000237done
238
david_williams4cbceb72008-01-22 03:41:40 +0000239ndropDir=${#dropDirList[*]}
david_williamsbd17e9e2008-01-20 05:05:16 +0000240
241# there should be exactly one drop directory
david_williams4cbceb72008-01-22 03:41:40 +0000242if [ $ndropDir != 1 ]
david_williamsbd17e9e2008-01-20 05:05:16 +0000243then
nickboldt17958d82020-01-30 16:05:17 -0500244 printf "\n\t%s\n" "Error: there was not exactly one drop directory. There was $ndropDir found instead." >&2
david_williams03bdf892008-02-02 03:00:11 +0000245 usage
david_williamsbd17e9e2008-01-20 05:05:16 +0000246 exit 5
david_williamsbd17e9e2008-01-20 05:05:16 +0000247fi
248
249# knowing there is exactly one, the value of dropDirName is still valid
250
david_williams8bfa02a2008-01-22 05:34:52 +0000251echo "Drop directory: ${dropDirName}"
david_williamsbd17e9e2008-01-20 05:05:16 +0000252
253FROMDIR=${mostRecentDir}/${dropDirName}
254
david_williams67098762011-09-18 00:56:42 +0000255# make sure RC has a value, in case no paths are taken that set it
256RC=0
257
david_williams6d540ce2011-02-15 05:30:47 +0000258if [[ $processArtifacts ]]
david_williamseaa47b42011-02-15 04:11:49 +0000259then
david_williamsa2b87ed2011-02-15 04:01:30 +0000260#run pack200 (and, recompute checksums) before literally promoting
261
david_williams35e02182011-06-03 05:44:00 +0000262
david_williamsa2b87ed2011-02-15 04:01:30 +0000263 repoDirLocation=$FROMDIR/repository
264 if [[ -d "${repoDirLocation}" ]]
265 then
david_williamseaa47b42011-02-15 04:11:49 +0000266 echo "INFO: processing artifacts in code repo: $repoDirLocation";
david_williamsa2b87ed2011-02-15 04:01:30 +0000267 ${RELENG_CONTROL}/runAntRunner.sh process-artifacts.xml -DrepoDirLocation="${repoDirLocation}"
david_williams046115d2011-09-08 18:53:11 +0000268 RC=$?
david_williamsa2b87ed2011-02-15 04:01:30 +0000269 else
david_williams046115d2011-09-08 18:53:11 +0000270 echo "ERROR: expected code repo directory does not exist: $repoDirLocation";
271 RC=2001
david_williamsa2b87ed2011-02-15 04:01:30 +0000272 fi
273
david_williams046115d2011-09-08 18:53:11 +0000274 if [ $RC -eq 0 ]
275 then
276 repoDirLocation=$FROMDIR/repositoryunittests
277 if [[ -d "${repoDirLocation}" ]]
278 then
279 echo "INFO: calling processing artifacts in test repo: $repoDirLocation";
280 ${RELENG_CONTROL}/runAntRunner.sh process-artifacts.xml -DrepoDirLocation="${repoDirLocation}"
281 RC=$?
282 else
283 echo "ERROR: expected test repo directory does not exist: $repoDirLocation";
284 RC=2002
285 fi
286 fi
david_williamseaa47b42011-02-15 04:11:49 +0000287fi
david_williamsa2b87ed2011-02-15 04:01:30 +0000288
david_williams046115d2011-09-08 18:53:11 +0000289if [ $RC != 0 ]
290 then
291 echo "ERROR: pack processing did not operate as expected. Exiting the promote script early."
292 exit $RC
293 fi
294
david_williamsb903b422011-02-15 06:12:50 +0000295# Remember, add properties should be called after process artifacts.
david_williams124777a2011-02-15 05:19:51 +0000296# TODO: we currently do not add properties to tests repo ... maybe should? for mirror URL, at least.
david_williamsb903b422011-02-15 06:12:50 +0000297# TODO: a fourth and fifth argument can be specified to addRepoProperties.sh to provide better stats marking.
298# A version indicator that becomes part of URI, such as /helios, /indigo, etc, and
299# a suffix, to signify releases, such as
300# such as _helios_SR2, _indigo_SR0 ... but, these will take some customization, and remember to update them fairly often, to be accurate.
301# And, we do not particularly use anyway.
302# 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 +0000303if [[ $addProperties ]]
304then
305 repoDirLocation=$FROMDIR/repository
306 if [[ -d "${repoDirLocation}" ]]
307 then
308 ${RELENG_CONTROL}/addRepoProperties.sh "${repoDirLocation}" "${buildBranch}" "${dropDirName}"
309 else
310 echo "ERROR: addProperties requested, but repo location does not exist: ${repoDirLocation}";
311 fi
312fi
david_williams124777a2011-02-15 05:19:51 +0000313
david_williams34f3f912008-07-08 01:36:22 +0000314if [ "patches" == $distribution ]
315then
316 TODIR=${DOWNLOAD_ROOT}/webtools/patches/drops/${buildBranch}/
317else
318 TODIR=${DOWNLOAD_ROOT}/webtools/downloads/drops/${buildBranch}/
319fi
david_williamsf6963892008-01-20 05:38:13 +0000320
321printf "\t%s\n" "declaring build ${dropDirName} on buildstream ${buildBranch}"
322printf "\t\t%s\n" "into ${TODIR}"
323printf "\t\t%s\n\n" "using the build from ${FROMDIR}"
david_williamsbd17e9e2008-01-20 05:05:16 +0000324
david_williams8bfa02a2008-01-22 05:34:52 +0000325if [ $doCopy ]
david_williams26840072008-01-22 03:32:43 +0000326then
david_williams33445492008-02-23 02:30:34 +0000327 rsync-retry ${FROMDIR} ${TODIR} $verboseFlag
328 exitCode=$?
329 if [ $exitCode -ne 0 ]
330 then
331 exit $exitCode
332 fi
david_williams26840072008-01-22 03:32:43 +0000333
david_williams8bfa02a2008-01-22 05:34:52 +0000334 fromString="webtools/committers"
david_williams9db6fa42008-08-25 17:03:10 +0000335 if [ "patches" == $distribution ]
336 then
337 toString="webtools/patches"
338 else
339 toString="webtools/downloads"
david_williams55ecb6d2008-08-26 03:52:18 +0000340 fi
david_williams8bfa02a2008-01-22 05:34:52 +0000341 replaceCommand="s!${fromString}!${toString}!g"
david_williamsbd17e9e2008-01-20 05:05:16 +0000342
david_williams0be0d972008-02-16 05:38:57 +0000343 # remember TODIR already has a slash
david_williams67b15622011-07-03 00:45:12 +0000344 perl -w -pi -e ${replaceCommand} ${TODIR}${dropDirName}/*.php
david_williamsbd17e9e2008-01-20 05:05:16 +0000345
david_williams20067502011-01-22 07:00:56 +0000346 # now do the composite reference site update
347
348 case $buildType in
david_williamsc479bd22011-05-22 17:05:38 +0000349 R )
350 referenceCompositeDir=${BUILD_HOME}/integration;;
351 S )
352 referenceCompositeDir=${BUILD_HOME}/integration;;
david_williams20067502011-01-22 07:00:56 +0000353 I )
david_williamsdaf6fdf2011-01-22 07:41:28 +0000354 referenceCompositeDir=${BUILD_HOME}/integration;;
david_williams20067502011-01-22 07:00:56 +0000355 M )
david_williamsdaf6fdf2011-01-22 07:41:28 +0000356 referenceCompositeDir=${BUILD_HOME}/maintenance;;
david_williams20067502011-01-22 07:00:56 +0000357 * )
david_williamsc479bd22011-05-22 17:05:38 +0000358 printf "warning: 'buildType' ($buildType) was not an expected value."
359 printf " composite reference not updated." ;;
david_williams20067502011-01-22 07:00:56 +0000360 esac
david_williamsdaf6fdf2011-01-22 07:41:28 +0000361 if [ ! -z referenceCompositeDir ]
david_williams20067502011-01-22 07:00:56 +0000362 then
363 dropDirectory=${TODIR}${dropDirName}
david_williamsd69c3c42011-01-22 07:51:48 +0000364 ./runAntRunner.sh "${PWD}/updateReferenceComposite.xml" "-DreferenceCompositeDir=$referenceCompositeDir" "-DdropDirectory=$dropDirectory"
nickboldta179b752018-03-15 10:41:53 -0400365 fi
david_williams8bfa02a2008-01-22 05:34:52 +0000366else
david_williams03bdf892008-02-02 03:00:11 +0000367 printf "\n\t%s\n\n" "Nothing copied: specify -c to actually do the copy"
nickboldta179b752018-03-15 10:41:53 -0400368fi
369
370if [ $syncLatest ]
371then
372 if [ "patches" != $distribution ]
373 then
374 iLatest=${TODIR}I-latest
375
376 mkdir -p iLatest/repository
377 mkdir -p iLatest/repositoryunittests
378
379 repoDir=${FROMDIR}/repository
380 repoTestDir=${FROMDIR}/repositoryunittests
381
382 echo "Refreshing I-latest from [ ${FROMDIR} ]"
383 rsync-retry $repoDir $iLatest $verboseFlag
384 rsync-retry $repoTestDir $iLatest $verboseFlag
385 else
386 echo "Refresh I-latest operation is not allowed for Patches"
387 fi
388else
389 echo "I-latest not updated. Specify -r if desired"
390fi
david_williamsbd17e9e2008-01-20 05:05:16 +0000391
david_williams4e4949d2008-12-13 18:17:17 +0000392if [ $sendmail ]
393then
394 ./sendPromoteMail.sh "$projectname" "$TODIR" "$dropDirName"
395 echo "mail sent"
396else
397 echo "no mail sent. Specify -s if desired"
398fi
399
david_williams03bdf892008-02-02 03:00:11 +0000400
401if [ $deleteOld ]
402then
403
404 maxToDelete=$(($nDir - 1))
405 if [ $verboseFlag ]
406 then
407 echo "maxToDelete: $maxToDelete"
408 fi
409 for (( i=0; i < $maxToDelete; i++))
410 do
411 dirbasename=${dirList[$i]}
412 dropDirName=${promoteProjectDir}/${dirbasename}
413 if [ $verboseFlag ]
414 then
415 echo -n "${i}: "
416 echo ${dropDirName}
417 fi
418 rm -fr ${dropDirName}
419 done
420
421fi
david_williams234ff412011-09-08 19:23:48 +0000422
423printargs