|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Script for updating code.angularjs.org repo from current local build. |
| 4 | + |
| 5 | +echo "#################################" |
| 6 | +echo "## Update code.angularjs.org ###" |
| 7 | +echo "#################################" |
| 8 | + |
| 9 | +ARG_DEFS=( |
| 10 | + "--action=(prepare|publish)" |
| 11 | + "--version-number=([0-9]+\.[0-9]+\.[0-9]+(-[a-z]+\.[0-9]+)?)" |
| 12 | +) |
| 13 | + |
| 14 | +function init { |
| 15 | + TMP_DIR=$(resolveDir ../../tmp) |
| 16 | + BUILD_DIR=$(resolveDir ../../dist/bundle) |
| 17 | + REPO_DIR=$TMP_DIR/code.angularjs.org |
| 18 | + # TODO: replace with version read from the bundle dir. |
| 19 | + NEW_VERSION=$VERSION_NUMBER |
| 20 | + if [[ "$NEW_VERSION" =~ sha ]]; then |
| 21 | + IS_SNAPSHOT_BUILD=true |
| 22 | + else |
| 23 | + IS_SNAPSHOT_BUILD= |
| 24 | + fi |
| 25 | +} |
| 26 | + |
| 27 | +function prepare { |
| 28 | + |
| 29 | + echo "-- Cloning code.angularjs.org" |
| 30 | + git clone git@github.com:angular/code.angularjs.org.git $REPO_DIR --depth=1 |
| 31 | + |
| 32 | + echo "-- Updating code.angularjs.org" |
| 33 | + |
| 34 | + if [[ $IS_SNAPSHOT_BUILD ]]; then |
| 35 | + # |
| 36 | + # update the snapshot folder |
| 37 | + # |
| 38 | + rm -rf $REPO_DIR/snapshot-angular2/ |
| 39 | + mkdir $REPO_DIR/snapshot-angular2 |
| 40 | + cp -r $BUILD_DIR/* $REPO_DIR/snapshot-angular2/ |
| 41 | + else |
| 42 | + # |
| 43 | + # copy the files from the build |
| 44 | + # |
| 45 | + mkdir $REPO_DIR/$NEW_VERSION |
| 46 | + cp -r $BUILD_DIR/* $REPO_DIR/$NEW_VERSION/ |
| 47 | + fi |
| 48 | + |
| 49 | + # |
| 50 | + # commit |
| 51 | + # |
| 52 | + echo "-- Committing code.angularjs.org" |
| 53 | + cd $REPO_DIR |
| 54 | + git add -A |
| 55 | + git commit -m "v$NEW_VERSION" |
| 56 | +} |
| 57 | + |
| 58 | + |
| 59 | +function _update_code() { |
| 60 | + cd $REPO_DIR |
| 61 | + |
| 62 | + echo "-- Pushing code.angularjs.org" |
| 63 | + git push origin master |
| 64 | + |
| 65 | + for backend in "$@" ; do |
| 66 | + echo "-- Refreshing code.angularjs.org: backend=$backend" |
| 67 | + curl http://$backend:8003/gitFetchSite.php |
| 68 | + done |
| 69 | +} |
| 70 | + |
| 71 | +function publish { |
| 72 | + # The TXT record for backends.angularjs.org is a CSV of the IP addresses for |
| 73 | + # the currently serving Compute Engine backends. |
| 74 | + # code.angularjs.org is served out of port 8003 on these backends. |
| 75 | + backends=("$(dig backends.angularjs.org +short TXT | python -c 'print raw_input()[1:-1].replace(",", "\n")')") |
| 76 | + _update_code ${backends[@]} |
| 77 | +} |
| 78 | + |
| 79 | +source $(dirname $0)/../utils.inc |
0 commit comments