Debian Codegraph @

util/buildscripts/build_release.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2
3 set -e
4
5 usagescip-shell shell dojo 1.17.3+dfsg1-1 usage().() {
6 echoscip-shell system . . echo. "Usage: $0 [-c] [-t] [-b branch] version"
7 echoscip-shell system . . echo.
8 echoscip-shell system . . echo. "-b Branch to archive. Defaults to 'master'."
9 echoscip-shell system . . echo. "-t Include themes repo in release."
10 echoscip-shell system . . 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 echoscip-shell system . . echo. "Invalid option -$OPTARG"
33 exit 1
34 ;;
35 :)
36 echoscip-shell system . . 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 $(dirnamescip-shell system . . dirname. $0) && pwdscip-shell system . . 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 [scip-shell system . . `[`. $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 [scip-shell system . . `[`. $(echoscip-shell system . . echo. $(zip -dd test 2>&1) |grepscip-shell system . . 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 [scip-shell system . . `[`. "$VERSION" == "" ]; then
124 usagescip-shell shell dojo 1.17.3+dfsg1-1 usage().
125 exit 1
126 fi
127
128 if [scip-shell system . . `[`. -d $SOURCE_DIR -o -d $OUTPUT_DIR ]; then
129 echoscip-shell system . . echo. "Existing build directories detected at $ROOT_DIR"
130 echoscip-shell system . . echo. "Aborted."
131 exit 1
132 fi
133
134 echoscip-shell system . . echo. "This is an internal Dojo release script. You probably meant to run build.sh!"
135 echoscip-shell system . . echo. "If you want to create Dojo version $VERSION from branch $BRANCH, press 'y'."
136 echoscip-shell system . . echo. "The source version will be updated to $PRE_VERSION after the build."
137 echoscip-shell system . . echo. "(You will have an opportunity to abort pushing upstream later on if something"
138 echoscip-shell system . . echo. "goes wrong.)"
139 read -s -n 1
140
141 if [scip-shell system . . `[`. "$REPLY" != "y" ]; then
142 echoscip-shell system . . echo. "Aborted."
143 exit 0
144 fi
145
146 if [scip-shell system . . `[`. ! -d $ROOT_DIR ]; then
147 mkdirscip-shell system . . mkdir. $ROOT_DIR
148 fi
149
150 mkdirscip-shell system . . mkdir. $SOURCE_DIR
151 mkdirscip-shell system . . 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 gitscip-shell system . . 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 gitscip-shell system . . git. checkout $VERSION > /dev/nullscip-shell filesystem . . `/dev/null`. 2>&1
164 if [scip-shell system . . `[`. $? -eq 0 ]; then
165 set -e
166 echoscip-shell system . . echo. "Tag $VERSION already exists for $REPO; using existing tag"
167 VERSION_EXISTS=1
168 continue
169 fi
170 set -e
171
172 REVISION=$(gitscip-shell system . . git. log -n 1 --format='%h')
173 VERSION_FILES=
174
175 if [scip-shell system . . `[`. -f "package.json" ]; then
176 VERSION_FILES=package.json
177 fi
178
179 if [scip-shell system . . `[`. -f "bower.json" ]; then
180 VERSION_FILES="$VERSION_FILES bower.json"
181 fi
182
183 if [scip-shell system . . `[`. $REPO == "dojo" ]; then
184 # Dojo 1.7+
185 if [scip-shell system . . `[`. -f "_base/kernel.js" ]; then
186 VERSION_FILES="$VERSION_FILES _base/kernel.js"
187 # Dojo 1.6-
188 elif [scip-shell system . . `[`. -f "_base/_loader/bootstrap.js" ]; then
189 VERSION_FILES="$VERSION_FILES _base/_loader/bootstrap.js"
190 fi
191 fi
192
193 if [scip-shell system . . `[`. $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 [scip-shell system . . `[`. -f $FILENAME ]; then
196 VERSION_FILES="$VERSION_FILES $FILENAME"
197 fi
198 done
199
200 if [scip-shell system . . `[`. -f "build/version.js" ]; then
201 VERSION_FILES="$VERSION_FILES build/version.js"
202 fi
203 fi
204
205 if [scip-shell system . . `[`. -n "$VERSION_FILES" ]; then
206 for FILENAME in $VERSION_FILES; do
207 javascip-shell system . . 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 gitscip-shell system . . git. commit -m "Updating metadata for $VERSION" $VERSION_FILES
213 fi
214
215 gitscip-shell system . . git. tag -a -m "Release $VERSION" $VERSION
216
217 if [scip-shell system . . `[`. -n "$VERSION_FILES" ]; then
218 for FILENAME in $VERSION_FILES; do
219 javascip-shell system . . java. -jar $UTIL_DIR/../shrinksafe/js.jar $UTIL_DIR/changeVersion.js $PRE_VERSION "" $FILENAME
220 done
221
222 gitscip-shell system . . git. commit -m "Updating source version to $PRE_VERSION" $VERSION_FILES
223 fi
224
225 gitscip-shell system . . 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 echoscip-shell system . . 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 echoscip-shell system . . echo. "Done"
236
237 # Temporarily rename $SOURCE_NAME ($SOURCE_DIR) to $BUILD_NAME to archive demos backwards-compatibly
238 mvscip-shell system . . mv. $SOURCE_NAME $BUILD_NAME
239 echoscip-shell system . . 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 mvscip-shell system . . mv. $BUILD_NAME $SOURCE_NAME
243 echoscip-shell system . . echo. "Done"
244
245 # Create the built release archive using the checked out release code
246 cd $SOURCE_BUILD_DIR
247 echoscip-shell system . . 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 echoscip-shell system . . 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 echoscip-shell system . . echo. "Done"
254
255 # For backwards-compatibility, Dojo Base is also copied for direct download
256 cpscip-shell system . . 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 rmscip-shell system . . rm. -rf $SOURCE_RELEASE_DIR
260 cd $SOURCE_BUILD_DIR
261 echoscip-shell system . . 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 mvscip-shell system . . mv. $SOURCE_RELEASE_DIR/$BUILD_NAME $OUTPUT_DIR
264 rmdirscip-shell system . . rmdir. $SOURCE_RELEASE_DIR
265 echoscip-shell system . . echo. "Done"
266
267 if [scip-shell system . . `[`. $CDN ]; then
268 mkdirscip-shell system . . mkdir. $CDN_OUTPUT_DIR
269
270 # Only this super-specific Ant version works!
271 if [scip-shell system . . `[`. ! -d ~/.ant ]; then
272 mkdirscip-shell system . . mkdir. ~/.ant
273 cd ~/.ant
274 echoscip-shell system . . echo. "Installing ant 1.7.1 to ~/.ant..."
275 curlscip-shell system . . curl. http://archive.apache.org/dist/ant/binaries/apache-ant-1.7.1-bin.tar.gz |tarscip-shell system . . tar. --strip-components=1 -zx
276 echoscip-shell system . . echo. "Done"
277 fi
278
279 echoscip-shell system . . echo. "Building CDN release..."
280
281 # Build all locales
282 cd $SOURCE_BUILD_DIR/cldr
283 sedscip-shell system . . sed. -i -e '/<property name="locales"/dscip-shell filesystem . . `/<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=$(mktempscip-shell system . . mktemp.)
291 $ant 2>&1 | teescip-shell system . . tee. $TMPFILE
292 EXITCODE=$?
293 set -e
294 set +o pipefail
295 if [scip-shell system . . `[`. $EXITCODE -gt 0 ]; then
296 if [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c "please re-run" $TMPFILE) -gt 0 ]; then
297 $ant
298 else
299 rmscip-shell system . . rm. $TMPFILE
300 exit 1
301 fi
302 fi
303 rmscip-shell system . . rm. $TMPFILE
304 unset TMPFILE EXITCODE
305
306 cd $SOURCE_BUILD_DIR
307
308 # Dojo 1.7+
309 if [scip-shell system . . `[`. -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 javascip-shell system . . 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 mvscip-shell system . . mv. $SOURCE_RELEASE_DIR/$CDN_NAME $CDN_OUTPUT_DIR
317 rmdirscip-shell system . . rmdir. $SOURCE_RELEASE_DIR
318 echoscip-shell system . . echo. "Done"
319
320 echoscip-shell system . . echo. -n "Generating CDN checksums..."
321 cd $CDN_OUTPUT_DIR
322 $zip $CDN_NAME.zip $CDN_NAME/
323 sha1sumscip-shell system . . sha1sum. $CDN_NAME.zip > sha1.txt
324 cd $CDN_OUTPUT_DIR/$CDN_NAME
325 findscip-shell system . . find. . -type f -exec sha1sum {} >> ../sha1.txt +
326 echoscip-shell system . . echo. "Done"
327
328 cd $ROOT_DIR
329 echoscip-shell system . . echo. -n "Creating CDN archive..."
330 $tar -cf $CDN_OUTPUT_NAME.tar $CDN_OUTPUT_NAME/
331 echoscip-shell system . . 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=$(whichscip-shell system . . which. md5 md5sum 2>/dev/nullscip-shell filesystem . . `/dev/null`. || truescip-shell system . . true.)
340 if [scip-shell system . . `[`. -x $md5 ]; then
341 echoscip-shell system . . echo. -n "Generating release checksums..."
342 for FILENAME in *.zip *.gz *.js; do
343 $md5 $FILENAME > $FILENAME.md5
344 echoscip-shell system . . echo. -n "."
345 done
346 echoscip-shell system . . echo. "Done"
347 else
348 echoscip-shell system . . echo. "MD5 utility missing; cannot generate checksums"
349 fi
350
351 # Archive file for download.dojotoolkit.org
352 cd $ROOT_DIR
353 echoscip-shell system . . echo. -n "Creating downloads archive..."
354 $tar -cf $OUTPUT_NAME.tar $OUTPUT_NAME/
355 echoscip-shell system . . echo. "Done"
356
357 echoscip-shell system . . echo. "Build complete."
358
359 # Confirmaton
360 if [scip-shell system . . `[`. $VERSION_EXISTS -eq 1 ]; then
361 echoscip-shell system . . echo. "Please confirm build success, then press 'y' key to clean up archives"
362 echoscip-shell system . . echo. "and upload, or any other key to bail."
363 else
364 echoscip-shell system . . echo. "Please confirm build success, then press 'y' key to clean up archives, push"
365 echoscip-shell system . . echo. "tags, and upload, or any other key to bail."
366 fi
367 read -p "> "
368
369 if [scip-shell system . . `[`. "$REPLY" != "y" ]; then
370 echoscip-shell system . . echo. "Aborted."
371 exit 0
372 fi
373
374 # Flush archives
375 echoscip-shell system . . echo. -n "Cleaning up archives..."
376 rmscip-shell system . . rm. -rf $OUTPUT_DIR
377 if [scip-shell system . . `[`. $CDN ]; then
378 rmscip-shell system . . rm. -rf $CDN_OUTPUT_DIR
379 fi
380 echoscip-shell system . . echo. "Done"
381
382 if [scip-shell system . . `[`. $VERSION_EXISTS -eq 1 ]; then
383 echoscip-shell system . . echo. "Skipping tag push, since tags already exist"
384 else
385 for REPO in $ALL_REPOS; do
386 cd $SOURCE_DIR/$REPO
387 echoscip-shell system . . echo. "Pushing to repo $REPO"
388 gitscip-shell system . . git. push origin $BRANCH
389 gitscip-shell system . . git. push origin --tags
390 done
391 fi
392
393 echoscip-shell system . . echo. "Release is now built and tagged. There rest from here is paperwork."
394
395 cd $ROOT_DIR
396
397 echoscip-shell system . . echo. "Copying archive to downloads.dojotoolkit.org..."
398 cpscip-shell system . . cp. $OUTPUT_NAME.tar /srv/www/vhosts.d/download.dojotoolkit.orgscip-shell filesystem . . `/srv/www/vhosts.d/download.dojotoolkit.org`.
399 cd /srv/www/vhosts.d/download.dojotoolkit.orgscip-shell filesystem . . `/srv/www/vhosts.d/download.dojotoolkit.org`. && tarscip-shell system . . tar. -xf $OUTPUT_NAME.tar && rmscip-shell system . . rm. $OUTPUT_NAME.tar
400
401 cd $ROOT_DIR
402
403 if [scip-shell system . . `[`. $CDN ]; then
404 echoscip-shell system . . echo. "Copying cdn to archive.dojotoolkit.org..."
405 cpscip-shell system . . cp. $CDN_OUTPUT_NAME.tar /srv/www/vhosts.d/archive.dojotoolkit.org/cdnscip-shell filesystem . . `/srv/www/vhosts.d/archive.dojotoolkit.org/cdn`.
406 cd /srv/www/vhosts.d/archive.dojotoolkit.org/cdnscip-shell filesystem . . `/srv/www/vhosts.d/archive.dojotoolkit.org/cdn`. && tarscip-shell system . . tar. -xf $CDN_OUTPUT_NAME.tar && rmscip-shell system . . rm. $CDN_OUTPUT_NAME.tar
407 fi
408
409 cd $ROOT_DIR
410
411 echoscip-shell system . . echo. "Upload complete. download.dojotoolkit.org should be automatically udpated. archive.dojotoolkit.org/cdn"
412 echoscip-shell system . . echo. "This site should be automagically updated: download.dojotoolkit.org"
413 echoscip-shell system . . echo. "CDNs can be found here: archive.dojotoolkit.org/cdn"
414 echoscip-shell system . . echo. "To deploy to dojotoolkit.org, make sure appropriate changes are done and merged to master, then redeploy."