|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +function help_and_exit() { |
| 4 | + echo "Usage: $0 [-go] [-verbose]" |
| 5 | + echo |
| 6 | + echo "Moves minified CSS and JS to distribution directories and" |
| 7 | + echo "creates a branch in SVN." |
| 8 | + echo |
| 9 | + echo " -go: Run commands instead of just echoing them." |
| 10 | + echo " -verbose: More verbose logging." |
| 11 | + exit "$1" |
| 12 | +} |
| 13 | + |
| 14 | +# 1 for verbose logging |
| 15 | +export VERBOSE="0" |
| 16 | +# 1 if commands that have side-effects should actually be run instead of logged |
| 17 | +export EFFECT="0" |
| 18 | + |
| 19 | +function panic() { |
| 20 | + echo "$*" |
| 21 | + exit -1 |
| 22 | +} |
| 23 | + |
| 24 | +function command() { |
| 25 | + if (( $VERBOSE )) || ! (( $EFFECT )); then |
| 26 | + echo '$' "$*" |
| 27 | + fi |
| 28 | + if (( $EFFECT )); then |
| 29 | + "$@" || panic "command failed: $@" |
| 30 | + fi |
| 31 | +} |
| 32 | + |
| 33 | +function mime_for_file() { |
| 34 | + local path="$1" |
| 35 | + case "${path##*.}" in |
| 36 | + js) echo -n "text/javascript;charset=UTF-8";; |
| 37 | + css) echo -n "text/css;charset=UTF-8";; |
| 38 | + html) echo -n "text/html;charset=UTF-8";; |
| 39 | + *) panic "unrecognized extension for $path";; |
| 40 | + esac |
| 41 | +} |
| 42 | + |
| 43 | +for var in "$@"; do |
| 44 | + case "$var" in |
| 45 | + -verbose) |
| 46 | + VERBOSE="1" |
| 47 | + ;; |
| 48 | + -go) |
| 49 | + EFFECT="1" |
| 50 | + ;; |
| 51 | + -h) |
| 52 | + help_and_exit 0 |
| 53 | + ;; |
| 54 | + *) |
| 55 | + echo "Unrecognized variable $var" |
| 56 | + help_and_exit -1 |
| 57 | + ;; |
| 58 | + esac |
| 59 | +done |
| 60 | + |
| 61 | +# Find svn root |
| 62 | +export VERSION_BASE="$( |
| 63 | + pushd "$(dirname "$0")/.." > /dev/null; pwd; popd > /dev/null)" |
| 64 | + |
| 65 | +if [ -z "$VERSION_BASE" ] || ! [ -d "$VERSION_BASE" ]; then |
| 66 | + panic "unknown VERSION_BASE" |
| 67 | +fi |
| 68 | +if ! [ -d "$VERSION_BASE/trunk" ]; then |
| 69 | + panic "missing trunk in $VERSION_BASE" |
| 70 | +fi |
| 71 | +if ! [ -d "$VERSION_BASE/loader" ]; then |
| 72 | + panic "missing loader in $VERSION_BASE" |
| 73 | +fi |
| 74 | +if ! [ -d "$VERSION_BASE/branches" ]; then |
| 75 | + panic "missing branches in $VERSION_BASE" |
| 76 | +fi |
| 77 | + |
| 78 | +if (( $VERBOSE )); then |
| 79 | + echo "VERSION_BASE=$VERSION_BASE" |
| 80 | +fi |
| 81 | + |
| 82 | +# Choose a release label |
| 83 | +export RELEASE_LABEL="$(date -u +release-%e-%b-%Y)" |
| 84 | + |
| 85 | +if (( $VERBOSE )); then |
| 86 | + echo "RELEASE_LABEL=$RELEASE_LABEL" |
| 87 | +fi |
| 88 | + |
| 89 | +if [ -e "$VERSION_BASE/branches/$RELEASE_LABEL" ]; then |
| 90 | + panic "duplicate release $VERSION_BASE/branches/$RELEASE_LABEL" |
| 91 | +fi |
| 92 | + |
| 93 | + |
| 94 | +# Make the distribution |
| 95 | +function build() { |
| 96 | + pushd "$VERSION_BASE/trunk" > /dev/null |
| 97 | + make distrib |
| 98 | + local status=$? |
| 99 | + popd > /dev/null |
| 100 | + (($status)) |
| 101 | +} |
| 102 | +if build; then |
| 103 | + panic "Make failed" |
| 104 | +fi |
| 105 | + |
| 106 | +if [-n "$(svn stat "$VERSION_BASE/trunk")"; then |
| 107 | + svn stat "$VERSION_BASE/trunk" |
| 108 | + panic "Uncommitted changes" |
| 109 | +fi |
| 110 | + |
| 111 | +function sync() { |
| 112 | + local action="$1" |
| 113 | + local src_dir="$2" |
| 114 | + local dest_dir="$3" |
| 115 | + shift 3 |
| 116 | + local exts=$@ |
| 117 | + local ext |
| 118 | + local src_file |
| 119 | + local dest_file |
| 120 | + for ext in $exts; do |
| 121 | + for src_file in "$src_dir"/*."$ext"; do |
| 122 | + dest_file="$dest_dir"/"$(basename "$src_file")" |
| 123 | + if ! [ -e "$dest_file" ] || diff -q "$src_file" "$dest_file"; then |
| 124 | + "$action" "$src_file" "$dest_file" |
| 125 | + fi |
| 126 | + done |
| 127 | + for dest_file in "$dest_dir"/*."$ext"; do |
| 128 | + src_file="$src_dir"/"$(basename "$dest_file")" |
| 129 | + if ! [ -e "$src_file" ]; then |
| 130 | + "$action" "$src_file" "$dest_file" |
| 131 | + fi |
| 132 | + done |
| 133 | + done |
| 134 | +} |
| 135 | + |
| 136 | +function svn_sync() { |
| 137 | + local src_file="$1" |
| 138 | + local dest_file="$2" |
| 139 | + if ! [ -e "$src_file" ]; then |
| 140 | + command svn delete "$dest_file" |
| 141 | + else |
| 142 | + command cp "$src_file" "$dest_file" |
| 143 | + if ! [ -e "$dest_file" ]; then |
| 144 | + command svn add "$dest_file" |
| 145 | + command svn propset svn:mime-type "$(mime_for_file "$src_file")" \ |
| 146 | + "$dest_file" |
| 147 | + fi |
| 148 | + fi |
| 149 | +} |
| 150 | + |
| 151 | +# Deploy the current compiled source to /loader |
| 152 | +sync svn_sync "$VERSION_BASE/trunk/src" "$VERSION_BASE/loader" js css |
| 153 | +sync svn_sync "$VERSION_BASE/trunk/styles" "$VERSION_BASE/loader/skins" css |
| 154 | + |
| 155 | +# Cut branch |
| 156 | +command svn copy "$VERSION_BASE/trunk" "$VERSION_BASE/branches/$RELEASE_LABEL" |
| 157 | + |
| 158 | +# Dump final instructions for caller. |
| 159 | +echo |
| 160 | +if (( $EFFECT )); then |
| 161 | + echo "Finally run" |
| 162 | + echo " $ svn commit -m 'Release $VERSION_BASE'" |
| 163 | + echo "to commit the new release then upload" |
| 164 | + echo " $VERSION_BASE/trunk/distrib/prettify-small.*" |
| 165 | + echo "to" |
| 166 | + echo " http://code.google.com/p/google-code-prettify/downloads/list" |
| 167 | +else |
| 168 | + echo "Rerun with -go flag to actually execute these commands." |
| 169 | +fi |
| 170 | + |
| 171 | +exit 0 |
0 commit comments