Debian Codegraph @

util/buildscripts/build_release.sh

raw symbols SCIP
1 #!/usr/bin/env bash
2
3 set -e
4
5 usage() {
6 echo "Usage: $0 [-c] [-t] [-b branch] version"
7 echo
8 echo "-b Branch to archive. Defaults to 'master'."
9 echo "-t Include themes repo in release."
10 echo "-c Build CDN release as well."
11 exit 1
12 }
13
14 while getopts ctb:u: OPTION; do
15 case $OPTION in
16 c)
17 CDN=1
18 shift 1
19 OPTIND=1
20 ;;
21 b)
22 BRANCH=$OPTARG
23 shift 2
24 OPTIND=1
25 ;;
26 t)
27 THEMES=1
28 shift 1
29 OPTIND=1
30 ;;
31 \?)
32 echo "Invalid option -$OPTARG"
33 exit 1
34 ;;
35 :)
36 echo "Missing argument for -$OPTARG"
37 exit 1
38 ;;
39 esac
40 done
41
42 # Version should be something like 0.9.0-beta or 0.9.0. See http://semver.org.
43 VERSION=$1
44
45 OLDIFS=$IFS
46 IFS="."
47 PRE_VERSION=($VERSION)
48 IFS=$OLDIFS
49
50 if [[ ${PRE_VERSION[2]} == *-* ]]; then
51 PRE_VERSION="${PRE_VERSION[0]}.${PRE_VERSION[1]}.$((PRE_VERSION[2]))-pre"
52 elif [[ ${PRE_VERSION[2]} -eq 0 ]]; then
53 PRE_VERSION="${PRE_VERSION[0]}.$((PRE_VERSION[1] + 1)).0-pre"
54 else
55 PRE_VERSION="${PRE_VERSION[0]}.${PRE_VERSION[1]}.$((PRE_VERSION[2] + 1))-pre"
56 fi
57
58 BRANCH=${BRANCH=master}
59
60 # Name used for directory and tar/zip file of prebuilt version
61 BUILD_NAME=dojo-release-$VERSION
62
63 # Name used for directory and tar/zip file of source version
64 SOURCE_NAME=$BUILD_NAME-src
65
66 # Name used for tar/zip file of demos
67 DEMOS_NAME=$BUILD_NAME-demos
68
69 # Name used for tarball of temporary archive for downloads.dojotoolkit.org
70 OUTPUT_NAME=release-$VERSION
71
72 # Name used for directory and zip file of CDN version
73 CDN_NAME=$VERSION
74
75 # Name used for directory and zip archive for archive.dojotoolkit.org
76 CDN_OUTPUT_NAME=$VERSION-cdn
77
78 # Build scripts directory (own directory)
79 UTIL_DIR=$(cd $(dirname $0) && pwd)
80
81 # Directory where all build operations will be rooted
82 ROOT_DIR=$UTIL_DIR/build
83
84 ###########
85 # NOTE: OUTPUT_DIR, SOURCE_DIR, and CDN_OUTPUT_DIR *must* be children of ROOT_DIR for certain operations to work
86 # properly. They must also use $*_NAME variables as the last directory part too.
87 ###########
88
89 # Directory into which final output for downloads.dojotoolkit.org is placed
90 OUTPUT_DIR=$ROOT_DIR/$OUTPUT_NAME
91
92 # Directory into which Dojo source is checked out
93 SOURCE_DIR=$ROOT_DIR/$SOURCE_NAME
94
95 # Directory where source Dojo build scripts exist
96 SOURCE_BUILD_DIR=$SOURCE_DIR/util/buildscripts
97
98 # Directory into which the source Dojo writes built data
99 SOURCE_RELEASE_DIR=$SOURCE_DIR/release
100
101 # Directory into which the source CDN writes built data for CDN
102 CDN_OUTPUT_DIR=$ROOT_DIR/$CDN_OUTPUT_NAME
103
104 # Repositories that are a part of the Dojo Toolkit
105
106 if [ $THEMES ]; then
107 ALL_REPOS="demos dijit dojo dojox dijit-themes util"
108 # Dojo 1.10-
109 else
110 ALL_REPOS="demos dijit dojo dojox util"
111 fi
112
113 zip="zip -dd -ds 1m -rq"
114
115 if [ $(echo $(zip -dd test 2>&1) |grep -c "one action") -eq 1 ]; then
116 # Zip 2.3 does not support progress output
117 zip="zip -rq"
118 fi
119
120 tar="tar --checkpoint=1000 --checkpoint-action=dot"
121 ant=~/.ant/bin/ant
122
123 if [ "$VERSION" == "" ]; then
124 usage
125 exit 1
126 fi
127
128 if [ -d $SOURCE_DIR -o -d $OUTPUT_DIR ]; then
129 echo "Existing build directories detected at $ROOT_DIR"
130 echo "Aborted."
131 exit 1
132 fi
133
134 echo "This is an internal Dojo release script. You probably meant to run build.sh!"
135 echo "If you want to create Dojo version $VERSION from branch $BRANCH, press 'y'."
136 echo "The source version will be updated to $PRE_VERSION after the build."
137 echo "(You will have an opportunity to abort pushing upstream later on if something"
138 echo "goes wrong.)"
139 read -s -n 1
140
141 if [ "$REPLY" != "y" ]; then
142 echo "Aborted."
143 exit 0
144 fi
145
146 if [ ! -d $ROOT_DIR ]; then
147 mkdir $ROOT_DIR
148 fi
149
150 mkdir $SOURCE_DIR
151 mkdir $OUTPUT_DIR
152
153 VERSION_EXISTS=0
154
155 for REPO in $ALL_REPOS; do
156 # Clone pristine copies of the repository for the desired branch instead of trying to copy a local repo
157 # which might be outdated, on a different branch, or containing other unpushed/uncommitted code
158 git clone --recursive --single-branch --branch=$BRANCH [email protected]:dojo/$REPO.git $SOURCE_DIR/$REPO
159
160 cd $SOURCE_DIR/$REPO
161
162 set +e
163 git checkout $VERSION > /dev/null 2>&1
164 if [ $? -eq 0 ]; then
165 set -e
166 echo "Tag $VERSION already exists for $REPO; using existing tag"
167 VERSION_EXISTS=1
168 continue
169 fi
170 set -e
171
172 REVISION=$(git log -n 1 --format='%h')
173 VERSION_FILES=
174
175 if [ -f "package.json" ]; then
176 VERSION_FILES=package.json
177 fi
178
179 if [ -f "bower.json" ]; then
180 VERSION_FILES="$VERSION_FILES bower.json"
181 fi
182
183 if [ $REPO == "dojo" ]; then
184 # Dojo 1.7+
185 if [ -f "_base/kernel.js" ]; then
186 VERSION_FILES="$VERSION_FILES _base/kernel.js"
187 # Dojo 1.6-
188 elif [ -f "_base/_loader/bootstrap.js" ]; then
189 VERSION_FILES="$VERSION_FILES _base/_loader/bootstrap.js"
190 fi
191 fi
192
193 if [ $REPO == "util" ]; then
194 for FILENAME in doh/package.json doh/_rhinoRunner.js doh/mobileRunner.html doh/runner.html doh/_nodeRunner.js; do
195 if [ -f $FILENAME ]; then
196 VERSION_FILES="$VERSION_FILES $FILENAME"
197 fi
198 done
199
200 if [ -f "build/version.js" ]; then
201 VERSION_FILES="$VERSION_FILES build/version.js"
202 fi
203 fi
204
205 if [ -n "$VERSION_FILES" ]; then
206 for FILENAME in $VERSION_FILES; do
207 java -jar $UTIL_DIR/../shrinksafe/js.jar $UTIL_DIR/changeVersion.js $VERSION $REVISION $FILENAME
208 done
209
210 # These will be pushed later, once it is confirmed the build was successful, in order to avoid polluting
211 # the origin repository with failed build commits and tags
212 git commit -m "Updating metadata for $VERSION" $VERSION_FILES
213 fi
214
215 git tag -a -m "Release $VERSION" $VERSION
216
217 if [ -n "$VERSION_FILES" ]; then
218 for FILENAME in $VERSION_FILES; do
219 java -jar $UTIL_DIR/../shrinksafe/js.jar $UTIL_DIR/changeVersion.js $PRE_VERSION "" $FILENAME
220 done
221
222 git commit -m "Updating source version to $PRE_VERSION" $VERSION_FILES
223 fi
224
225 git checkout $VERSION
226 done
227
228 cd $ROOT_DIR
229
230 # Archive all source except for demos, which are provided separately so people do not have to download them
231 # with the source
232 echo -n "Archiving source..."
233 $zip $OUTPUT_DIR/$SOURCE_NAME.zip $SOURCE_NAME/ -x "*/.git" -x "*/.git/*" -x "$SOURCE_NAME/demos/*"
234 $tar --exclude="$SOURCE_NAME/demos" --exclude-vcs -zcf $OUTPUT_DIR/$SOURCE_NAME.tar.gz $SOURCE_NAME/
235 echo "Done"
236
237 # Temporarily rename $SOURCE_NAME ($SOURCE_DIR) to $BUILD_NAME to archive demos backwards-compatibly
238 mv $SOURCE_NAME $BUILD_NAME
239 echo -n "Archiving demos..."
240 $zip $OUTPUT_DIR/$DEMOS_NAME.zip $BUILD_NAME/demos/ -x "*/.git" -x "*/.git/*"
241 $tar --exclude-vcs -zcf $OUTPUT_DIR/$DEMOS_NAME.tar.gz $BUILD_NAME/demos/
242 mv $BUILD_NAME $SOURCE_NAME
243 echo "Done"
244
245 # Create the built release archive using the checked out release code
246 cd $SOURCE_BUILD_DIR
247 echo "Building release..."
248 ./build.sh action=release profile=standard version=$VERSION releaseName=$BUILD_NAME cssOptimize=comments.keepLines optimize=shrinksafe.keepLines insertAbsMids=1 mini=true
249 cd $SOURCE_RELEASE_DIR
250 echo -n "Archiving release..."
251 $zip $OUTPUT_DIR/$BUILD_NAME.zip $BUILD_NAME/
252 $tar -zcf $OUTPUT_DIR/$BUILD_NAME.tar.gz $BUILD_NAME/
253 echo "Done"
254
255 # For backwards-compatibility, Dojo Base is also copied for direct download
256 cp $BUILD_NAME/dojo/dojo.js* $OUTPUT_DIR
257
258 # Second build with tests that is kept unarchived and placed directly on downloads.dojotoolkit.org
259 rm -rf $SOURCE_RELEASE_DIR
260 cd $SOURCE_BUILD_DIR
261 echo "Building downloads release..."
262 ./build.sh action=release profile=standard version=$VERSION releaseName=$BUILD_NAME cssOptimize=comments.keepLines optimize=shrinksafe.keepLines insertAbsMids=1 copyTests=true mini=false
263 mv $SOURCE_RELEASE_DIR/$BUILD_NAME $OUTPUT_DIR
264 rmdir $SOURCE_RELEASE_DIR
265 echo "Done"
266
267 if [ $CDN ]; then
268 mkdir $CDN_OUTPUT_DIR
269
270 # Only this super-specific Ant version works!
271 if [ ! -d ~/.ant ]; then
272 mkdir ~/.ant
273 cd ~/.ant
274 echo "Installing ant 1.7.1 to ~/.ant..."
275 curl http://archive.apache.org/dist/ant/binaries/apache-ant-1.7.1-bin.tar.gz |tar --strip-components=1 -zx
276 echo "Done"
277 fi
278
279 echo "Building CDN release..."
280
281 # Build all locales
282 cd $SOURCE_BUILD_DIR/cldr
283 sed -i -e '/<property name="locales"/d' build.xml
284
285 $ant clean
286
287 # On first run of Ant, build.xml does some bad stuff that requires running ant twice
288 set +e
289 set -o pipefail
290 TMPFILE=$(mktemp)
291 $ant 2>&1 | tee $TMPFILE
292 EXITCODE=$?
293 set -e
294 set +o pipefail
295 if [ $EXITCODE -gt 0 ]; then
296 if [ $(grep -c "please re-run" $TMPFILE) -gt 0 ]; then
297 $ant
298 else
299 rm $TMPFILE
300 exit 1
301 fi
302 fi
303 rm $TMPFILE
304 unset TMPFILE EXITCODE
305
306 cd $SOURCE_BUILD_DIR
307
308 # Dojo 1.7+
309 if [ -f "profiles/cdn.profile.js" ]; then
310 ./build.sh action=release profile=standard profile=cdn version=$VERSION releaseName=$CDN_NAME cssOptimize=comments.keepLines optimize=closure layerOptimize=closure stripConsole=normal copyTests=false mini=true
311 # Dojo 1.6
312 else
313 java -classpath ../shrinksafe/js.jar:../shrinksafe/shrinksafe.jar org.mozilla.javascript.tools.shell.Main build.js profile=standard version=$VERSION releaseName=$CDN_NAME cssOptimize=comments.keepLines optimize=shrinksafe layerOptimize=shrinksafe stripConsole=normal copyTests=false mini=true action=release loader=xdomain xdDojoPath="//ajax.googleapis.com/ajax/libs/dojo/$VERSION" xdDojoScopeName=window[\(typeof\(djConfig\)\!\=\"undefined\"\&\&djConfig.scopeMap\&\&djConfig.scopeMap[0][1]\)\|\|\"dojo\"]
314 fi
315
316 mv $SOURCE_RELEASE_DIR/$CDN_NAME $CDN_OUTPUT_DIR
317 rmdir $SOURCE_RELEASE_DIR
318 echo "Done"
319
320 echo -n "Generating CDN checksums..."
321 cd $CDN_OUTPUT_DIR
322 $zip $CDN_NAME.zip $CDN_NAME/
323 sha1sum $CDN_NAME.zip > sha1.txt
324 cd $CDN_OUTPUT_DIR/$CDN_NAME
325 find . -type f -exec sha1sum {} >> ../sha1.txt +
326 echo "Done"
327
328 cd $ROOT_DIR
329 echo -n "Creating CDN archive..."
330 $tar -cf $CDN_OUTPUT_NAME.tar $CDN_OUTPUT_NAME/
331 echo "Done"
332
333 cd $ROOT_DIR
334 fi
335
336 cd $OUTPUT_DIR
337
338 # Checksums, because who doesn't love checksums?!
339 md5=$(which md5 md5sum 2>/dev/null || true)
340 if [ -x $md5 ]; then
341 echo -n "Generating release checksums..."
342 for FILENAME in *.zip *.gz *.js; do
343 $md5 $FILENAME > $FILENAME.md5
344 echo -n "."
345 done
346 echo "Done"
347 else
348 echo "MD5 utility missing; cannot generate checksums"
349 fi
350
351 # Archive file for download.dojotoolkit.org
352 cd $ROOT_DIR
353 echo -n "Creating downloads archive..."
354 $tar -cf $OUTPUT_NAME.tar $OUTPUT_NAME/
355 echo "Done"
356
357 echo "Build complete."
358
359 # Confirmaton
360 if [ $VERSION_EXISTS -eq 1 ]; then
361 echo "Please confirm build success, then press 'y' key to clean up archives"
362 echo "and upload, or any other key to bail."
363 else
364 echo "Please confirm build success, then press 'y' key to clean up archives, push"
365 echo "tags, and upload, or any other key to bail."
366 fi
367 read -p "> "
368
369 if [ "$REPLY" != "y" ]; then
370 echo "Aborted."
371 exit 0
372 fi
373
374 # Flush archives
375 echo -n "Cleaning up archives..."
376 rm -rf $OUTPUT_DIR
377 if [ $CDN ]; then
378 rm -rf $CDN_OUTPUT_DIR
379 fi
380 echo "Done"
381
382 if [ $VERSION_EXISTS -eq 1 ]; then
383 echo "Skipping tag push, since tags already exist"
384 else
385 for REPO in $ALL_REPOS; do
386 cd $SOURCE_DIR/$REPO
387 echo "Pushing to repo $REPO"
388 git push origin $BRANCH
389 git push origin --tags
390 done
391 fi
392
393 echo "Release is now built and tagged. There rest from here is paperwork."
394
395 cd $ROOT_DIR
396
397 echo "Copying archive to downloads.dojotoolkit.org..."
398 cp $OUTPUT_NAME.tar /srv/www/vhosts.d/download.dojotoolkit.org
399 cd /srv/www/vhosts.d/download.dojotoolkit.org && tar -xf $OUTPUT_NAME.tar && rm $OUTPUT_NAME.tar
400
401 cd $ROOT_DIR
402
403 if [ $CDN ]; then
404 echo "Copying cdn to archive.dojotoolkit.org..."
405 cp $CDN_OUTPUT_NAME.tar /srv/www/vhosts.d/archive.dojotoolkit.org/cdn
406 cd /srv/www/vhosts.d/archive.dojotoolkit.org/cdn && tar -xf $CDN_OUTPUT_NAME.tar && rm $CDN_OUTPUT_NAME.tar
407 fi
408
409 cd $ROOT_DIR
410
411 echo "Upload complete. download.dojotoolkit.org should be automatically udpated. archive.dojotoolkit.org/cdn"
412 echo "This site should be automagically updated: download.dojotoolkit.org"
413 echo "CDNs can be found here: archive.dojotoolkit.org/cdn"
414 echo "To deploy to dojotoolkit.org, make sure appropriate changes are done and merged to master, then redeploy."