update-oojs-ui.sh: Replace target dir instead of adding file copies
authorTimo Tijhof <krinklemail@gmail.com>
Sat, 19 Apr 2014 02:05:04 +0000 (04:05 +0200)
committerKrinkle <krinklemail@gmail.com>
Sat, 19 Apr 2014 02:14:36 +0000 (02:14 +0000)
* A command like "cp dist/* $TARGET_DIR" does not remove files
  that were deleted in the release dist. Using rsync instead.

* Use bash -n or -z instead of "" and "x$VAR" == "x" tricks.

* The "git commit <dir>" doesn't properly take care of staging
  deletion of files removed by the update script, nor does it
  reliably (?) stage new files.
  Instead using a combination of "git add -u <dir>" (The -u
  stages deletion and modifcation of tracked files), and
  "git add <dir>" (stages modification and creation of files in
  that directory).

* Use "grunt test" instead of "grunt <default>" to make more
  explicit what is going on (no change in behaviour, default=test).
  And document why we don't use plain grunt-build without tests.

Change-Id: Id97a66df64d9e43e3c05388486b9f959108363c1

maintenance/resources/update-oojs-ui.sh [new file with mode: 0755]
resources/lib/oojs-ui/update-oojs-ui.sh [deleted file]

diff --git a/maintenance/resources/update-oojs-ui.sh b/maintenance/resources/update-oojs-ui.sh
new file mode 100755 (executable)
index 0000000..cc5988c
--- /dev/null
@@ -0,0 +1,97 @@
+#!/usr/bin/env bash
+
+# This script generates a commit that updates our distribution copy of OOjs UI
+
+if [ -z "$1" ]
+then
+       # Missing required parameter
+       echo >&2 "Usage: $0 path/to/repo/for/oojs-ui"
+       exit 1
+fi
+
+TARGET_REPO=$(cd $(dirname $0)/../..; pwd)
+TARGET_DIR=resources/lib/oojs-ui
+UI_REPO=$1
+
+function oojsuihash() {
+       grep "OOjs UI v" $TARGET_REPO/$TARGET_DIR/oojs-ui.js \
+               | head -n 1 \
+               | grep -Eo '\([a-z0-9]+\)' \
+               | sed 's/^(//' \
+               | sed 's/)$//'
+}
+
+function oojsuitag() {
+       grep "OOjs UI v" $TARGET_REPO/$TARGET_DIR/oojs-ui.js \
+               | head -n 1 \
+               | grep -Eo '\bv[0-9a-z.-]+\b'
+}
+
+function oojsuiversion() {
+       grep "OOjs UI v" $TARGET_REPO/$TARGET_DIR/oojs-ui.js \
+               | head -n 1 \
+               | grep -Eo '\bv[0-9a-z.-]+\b.*$'
+}
+
+# Prepare working tree
+cd $TARGET_REPO &&
+git reset $TARGET_DIR && git checkout $TARGET_DIR && git fetch origin &&
+git checkout -B upstream-oojsui origin/master || exit 1
+
+cd $UI_REPO || exit 1
+
+# Read the old version and check for changes
+OLDHASH=$(oojsuihash)
+if [ -z "$OLDHASH" ]
+then
+       OLDTAG=$(oojsuitag)
+fi
+if [ "$OLDHASH" == "" ]
+then
+       OLDHASH=$(git rev-parse $OLDTAG)
+       if [ $? != 0 ]
+       then
+               echo Could not find OOjs UI version
+               cd -
+               exit 1
+       fi
+fi
+if [ "$(git rev-parse $OLDHASH)" == "$(git rev-parse HEAD)" ]
+then
+       echo "No changes (already at $OLDHASH)"
+       cd -
+       exit 0
+fi
+
+# Build the distribution (using grunt-test instead of grunt-build, because we
+# want to run unit tests first, and because grunt-build is for a release build
+# and wouldn't put a git hash in the file headers)
+npm install && grunt test || exit 1
+
+# Get the list of changes
+NEWCHANGES=$(git log $OLDHASH.. --oneline --no-merges --reverse --color=never)
+NEWCHANGESDISPLAY=$(git log $OLDHASH.. --oneline --no-merges --reverse --color=always)
+
+# Copy files
+# - Exclude the default non-svg stylesheet
+rsync --recursive --delete --force --exclude 'oojs-ui.css' ./dist/ $TARGET_REPO/$TARGET_DIR || exit 1
+
+# Read the new version
+NEWVERSION=$(oojsuiversion)
+
+# Generate commit
+cd $TARGET_REPO
+COMMITMSG=$(cat <<END
+Update OOjs UI to $NEWVERSION
+
+New changes:
+$NEWCHANGES
+END
+)
+git add -u $TARGET_DIR && git add $TARGET_DIR && git commit -m "$COMMITMSG"
+cat >&2 <<END
+
+
+Created commit with changes:
+$NEWCHANGESDISPLAY
+END
diff --git a/resources/lib/oojs-ui/update-oojs-ui.sh b/resources/lib/oojs-ui/update-oojs-ui.sh
deleted file mode 100755 (executable)
index 3c6dca6..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-#!/usr/bin/env bash
-
-# FIXME this script is duplicated from update-oojs.sh - factor this out
-
-# This script generates a commit that updates the oojs-ui distribution
-# ./bin/update-oojs-ui.sh path/to/repo/for/oojs-ui
-
-function oojsuihash() {
-       grep "OOjs UI v" resources/lib/oojs-ui/oojs-ui.js \
-               | head -n 1 \
-               | grep -Eo '\([a-z0-9]+\)' \
-               | sed 's/^(//' \
-               | sed 's/)$//'
-}
-
-function oojsuitag() {
-       grep "OOjs UI v" resources/lib/oojs-ui/oojs-ui.js \
-               | head -n 1 \
-               | grep -Eo '\bv[0-9a-z.-]+\b'
-}
-
-function oojsuiversion() {
-       grep "OOjs UI v" resources/lib/oojs-ui/oojs-ui.js \
-               | head -n 1 \
-               | grep -Eo '\bv[0-9a-z.-]+\b.*$'
-}
-
-# cd to the MW root directory
-cd $(cd $(dirname $0)/../../..; pwd)
-
-if [ "x$1" == "x" ]
-then
-       echo >&2 "Usage: update-oojs-ui.sh path/to/repo/for/oojs-ui"
-       exit 1
-fi
-
-# Undo any changes in the oojs-ui directory
-git reset -- resources/lib/oojs-ui/
-git checkout -- resources/lib/oojs-ui/
-
-git fetch origin
-# Create a branch of MW if needed, and reset it to master
-git checkout -B update-oojsui origin/master
-
-# Get the old oojs-ui version
-OLDVERSION=$(oojsuihash)
-if [ "x$OLDVERSION" == "x" ]
-then
-       TAG=$(oojsuitag)
-fi
-
-# cd to the oojs-ui directory
-cd $1 || exit 1
-if [ "x$OLDVERSION" == "x" ]
-then
-       # Try the tag
-       OLDVERSION=$(git rev-parse $TAG)
-       if [ $? != 0 ]
-       then
-               echo Could not find OOjs UI version
-               cd -
-               exit 1
-       fi
-fi
-if [ "$(git rev-parse $OLDVERSION)" == "$(git rev-parse HEAD)" ]
-then
-       echo "No changes (already at $OLDVERSION)"
-       cd -
-       exit 0
-fi
-# Build the distribution
-npm install || exit 1
-grunt || exit 1
-# Get the list of changes
-NEWCHANGES=$(git log $OLDVERSION.. --oneline --no-merges --reverse --color=never)
-NEWCHANGESDISPLAY=$(git log $OLDVERSION.. --oneline --no-merges --reverse --color=always)
-# cd back to the VisualEditor directory
-cd -
-
-# Copy files from dist/ to resources/lib/oojs-ui
-cp -a $1/dist/{oojs-ui.js,oojs-ui.svg.css,oojs-ui-apex.css,oojs-ui-agora.css,images,i18n} resources/lib/oojs-ui/
-# Figure out what the new version is
-NEWVERSION=$(oojsuiversion)
-# Generate commit summary
-COMMITMSG=$(cat <<END
-Update OOjs UI to $NEWVERSION
-
-New changes:
-$NEWCHANGES
-END
-)
-# Commit
-git commit resources/lib/oojs-ui/ -m "$COMMITMSG"
-cat >&2 <<END
-
-
-Created commit with changes:
-$NEWCHANGESDISPLAY
-END