Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1b42b4b9a9a24d33852f2121dcf08d10f1094d5b (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
#!/bin/bash -x

#--------------------------------------------------------------------------------
# Copyright (c) 2012 CEA LIST.
#
#    
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
# which accompanies this distribution, and is available at
# https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
#    Nicolas Bros (Mia-Software)
#--------------------------------------------------------------------------------

set -o errexit
set -o nounset

DATE=$(date +%Y%m%d-%H%M)

function prune() {
	NARGS=3
	if [ $# -ne $NARGS ]; then echo "$NARGS arguments expected"; exit 1; fi
	_kind=$1 # prefix: N for nightlies, I for integration, ...
	_filesPath=$2
	_nBuildsToKeep=$3

	ls -1 $_filesPath | grep "${_kind}20*" || return 0
	allFiles=$(ls -trd $_filesPath/${_kind}20*)
	nFiles=$(ls -1d $_filesPath/${_kind}20* | wc -l)
	nToDelete=$((nFiles-_nBuildsToKeep))

	if [ $nToDelete -gt 0 ]; then
		for file in $allFiles; do
			rm -rf $file
			nToDelete=$((nToDelete-1))
			if [ $nToDelete -le 0 ]; then break; fi
		done
	fi
}

function getZip() {
	_zipName=$1
	_nfsBaseDir=$2
	_hudsonBaseURL=$3

	[[ "$_zipName" =~ ^.*?\.zip$ ]] || { echo "incorrect parameter: zipName"; exit 1; }

	# try with NFS access first, and if that fails, use the Hudson REST API
	# see http://wiki.hudson-ci.org/display/HUDSON/Remote+access+API
	# Note: for HIPP builds, NFS access isn't supported
	cp "$_nfsBaseDir/${_zipName}" . || wget --no-check-certificate "$_hudsonBaseURL/${_zipName}"
	if [ ! -f "$_zipName" ]; then echo "ERROR: $_zipName (from Hudson) not found"; exit -2; fi
	echo "[$DATE] Testing zip integrity"
	unzip -t "$_zipName"
}


function setAccessRights() {
	chmod -R 775 "$1"
	chgrp -hR modeling.mdt.papyrus "$1"
}

function waitUntilJobIsFinished() {
	_jobName="$1" # name of the Hudson Job
	_timeout="$2" # timeout in seconds
	interval=10
	
	((t = ${_timeout}))

    while ((t > 0)); do
    	# returns "true" or "false", depending on whether the build is currently running
    	# ignore error code, because Hudson returns garbage once in a while, and we prefer to timeout than to fail immediately in this case
        building=$(curl -s -S https://hudson.eclipse.org/hudson/job/${_jobName}/lastBuild/api/xml | xpath "//building/text()" || true)
        if [ "$building" == "false" ]; then return 0; fi
        sleep $interval
        ((t -= interval))
    done
	
	return 1
}

function promote() {
	NARGS=10
	if [ $# -ne $NARGS ]; then echo "promote expects exactly $NARGS arguments"; exit 1; fi
	_zipName=$1
	_version=$2
	_nfsBaseDir=$3
	_hudsonBaseURL=$4
	_dropsDir=$5
	_archiveDir=$6
	_archiveIndex=$7
	_updateSite=$8
	_updateZipPrefix=$9
	_branchToTag=${10}
	
	dirBefore=$(pwd)
	
	[[ "$_zipName" =~ ^.*?\.zip$ ]] || { echo "incorrect parameter: zipName"; exit 1; }
	[[ "$_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "incorrect parameter: version"; exit 1; }
	[[ "$_dropsDir" =~ ^/home/data/httpd/download\.eclipse\.org/.*$ ]] || { echo "incorrect parameter: dropsDir"; exit 1; }
	[[ "$_archiveDir" =~ ^/home/data/httpd/archive\.eclipse\.org/.*$ ]] || { echo "incorrect parameter: archiveDir"; exit 1; }
	[[ "$_archiveIndex" =~ ^/home/data/httpd/archive\.eclipse\.org/.*?/index\.html$ ]] || { echo "incorrect parameter: archiveIndex"; exit 1; }
	[[ "$_updateSite" =~ ^/home/data/httpd/download\.eclipse\.org/.*$ ]] || { echo "incorrect parameter: updateSite"; exit 1; }
	[ -n "$_updateZipPrefix" ] || { echo "empty parameter: updateZipPrefix"; exit 1; }
	[[ "$_branchToTag" =~ ^trunk|branches/[0-9]+_[0-9]+|NA$ ]] || { echo "incorrect parameter: branchToTag"; exit 1; }
	for (( i = 0 ; i < ${#SVN_DIRECTORIES_TO_TAG[*]} ; i++ )); do
		[[ "${SVN_DIRECTORIES_TO_TAG[$i]}" =~ ^file:///svnroot/.*$ ]] || { echo "incorrect variable: SVN_DIRECTORIES_TO_TAG"; exit 1; }
	done
		
	echo "[$DATE] creating working dir"
	workingDir=$(mktemp -d)
	cd "$workingDir"
	
	echo "[$DATE] getting last successful build"
	getZip "$_zipName" "$_nfsBaseDir" "$_hudsonBaseURL"
	
	buildsDir="$_dropsDir/$_version"
	echo "[$DATE] publishing build (version='$_version') to the builds directory '$buildsDir'..."
	unzip -o "$_zipName" -d "$buildsDir"
	
	echo "[$DATE] publishing build (version='$_version') to the update site '$_updateSite'..."
	[ -d "$_updateSite" ] && { echo "Error: update site directory already exists"; exit 1; }
	# extract the zip in which there is the update site zip to a tmp dir
	tmpDrop=$(mktemp -d)
	unzip "$_zipName" -d "$tmpDrop"
	dirNameInZip=$(ls -1 "$tmpDrop")
	[ $(echo "$dirNameInZip" | wc -l) == 1 ] || { echo "one directory expected in zip"; exit 1; }
	updateSiteZipName=$(basename $(ls -1 "$tmpDrop/$dirNameInZip/${_updateZipPrefix}"*.zip))
	unzip -o "$tmpDrop/$dirNameInZip/${updateSiteZipName}" -d "$_updateSite"
	
	# commented out because we don't need statistics for nightlies
	#echo "[$DATE] enabling download statistics"
	#$ADD_DOWNLOAD_STATS "$_updateSite"
	
	echo "[$DATE] setting access rights"
	#buildFolder="$buildsDir"/${_zipName/%\.zip/}
	foldersInZip=$(unzip -t "$_zipName" | egrep "testing: *[^/]*/ +OK" | sed 's%^ *testing: *\([^/]*\)/ *OK$%\1%')
	[ $(echo "$foldersInZip" | wc -l) == 1 ] || { echo "one directory expected in zip"; exit 1; }
	buildFolder="$buildsDir/$foldersInZip"
	setAccessRights "$buildFolder"
	setAccessRights "$_updateSite"
	
	# copy milestone and release builds to the archive, and tag the build
	if [[ "$_zipName" =~ ^[MSR].*$ && "${_branchToTag}" != "NA" ]]; then
		echo "copying the build to the archive"
		unzip "$_zipName" -d "${_archiveDir}/${_version}"
		cp "${_archiveIndex}" "${_archiveIndex}.bak"
		# Papyrus-Update-0.9.0M4.zip -> 0.9.0M4
		buildAlias=$(echo $updateSiteZipName | sed 's/^.*-\(.*\)\.zip/\1/g')
		# <li><a href="drops/0.9.0/S201112130437/Papyrus-Update-0.9.0M4.zip">0.9.0M4</a>
		echo "adding reference to ${buildAlias} in the archive's index.html"
		sed 's%<!--$$$_INSERT_HERE_$$$-->%<li><a href="drops/'${_version}'/'${dirNameInZip}'/'${updateSiteZipName}'">'${buildAlias}'<\/a>\n<!--$$$_INSERT_HERE_$$$-->%' "${_archiveIndex}.bak" > "${_archiveIndex}"

		echo "tagging the build"
		# "S201112140456.zip" and "0.9.0M4" => S0_9_0M4
		tagName=$(echo "$buildAlias")
		revisionToTag=$(cat "$tmpDrop/$dirNameInZip/revision.txt")
		
		for (( i = 0 ; i < ${#SVN_DIRECTORIES_TO_TAG[*]} ; i++ )); do
			fromSvnDir="${SVN_DIRECTORIES_TO_TAG[$i]}/${_branchToTag}"
			toSvnDir="${SVN_DIRECTORIES_TO_TAG[$i]}/tags/$tagName"
			echo "tagging: copying revision '$revisionToTag' from ${_branchToTag} of '$fromSvnDir' to '$toSvnDir'"
			svn copy -r "$revisionToTag" "$fromSvnDir" "$toSvnDir" -m "tagging $tagName with revision $revisionToTag from ${_branchToTag}"
		done
	fi

	cd ${dirBefore}
	echo "[$DATE] deleting working dir"
	rm -rf "$workingDir"
	rm -rf "$tmpDrop"
}

Back to the top