update-oojs.sh: Rewrite to fetch from npm repo instead of building from git
authorTimo Tijhof <krinklemail@gmail.com>
Mon, 7 Apr 2014 22:15:06 +0000 (15:15 -0700)
committerTimo Tijhof <krinklemail@gmail.com>
Mon, 7 Apr 2014 23:46:12 +0000 (16:46 -0700)
* Fetch upstream build from npm repository instead of building it locally
  from git (to avoid different timestamps and checksums not matching, no
  need for MediaWiki code to know how to build a oojs distribution).

* Ran it which changed the oojs.js file slightly (it now contains the file
  as released on npmjs.org instead of the local build by the person who
  last updated it in mediawiki).

Follows-up:
648667a - Split up resources/ into resources/lib/ and resources/src/
c68b967 - Add scripts to generate update builds of OOjs

Change-Id: I63f79293e21781c1db3d7c43658c22f58ba9102d

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

diff --git a/maintenance/resources/update-oojs.sh b/maintenance/resources/update-oojs.sh
new file mode 100755 (executable)
index 0000000..f26350f
--- /dev/null
@@ -0,0 +1,51 @@
+#!/usr/bin/env bash
+
+if [ "$2" != "" ]
+then
+       echo >&2 "Usage: $0 [<version>]"
+       exit 1
+fi
+
+MW_DIR=$(cd $(dirname $0)/../..; pwd) # e.g. mediawiki-core/
+NPM_DIR=`mktemp -d 2>/dev/null || mktemp -d -t 'mw-update-oojs'` # e.g. /tmp/mw-update-oojs.rI0I5Vir
+
+# Prepare MediaWiki working copy
+cd $MW_DIR
+git reset resources/lib/oojs/ && git checkout resources/lib/oojs/ && git fetch origin || exit 1
+
+git checkout -B upstream-oojs origin/master || exit 1
+
+# Fetch upstream version
+cd $NPM_DIR
+if [ "$1" != "" ]
+then
+       npm install oojs@$1 || exit 1
+else
+       npm install oojs || exit 1
+fi
+
+OOJS_VERSION=$(node -e 'console.log(JSON.parse(require("fs").readFileSync("./node_modules/oojs/package.json")).version);')
+if [ "$OOJS_VERSION" == "" ]
+then
+       echo 'Could not find OOjs version'
+       exit 1
+fi
+
+# Copy file(s)
+mv ./node_modules/oojs/dist/* $MW_DIR/resources/lib/oojs/ || exit 1
+
+# Generate commit
+cd $MW_DIR || exit 1
+
+# Clean up temporary area
+rm -rf $NPM_DIR
+
+COMMITMSG=$(cat <<END
+Update OOjs to v$OOJS_VERSION
+
+Release notes:
+ https://git.wikimedia.org/blob/oojs%2Fcore.git/v$OOJS_VERSION/History.md
+END
+)
+
+git commit resources/lib/oojs/ -m "$COMMITMSG" || exit 1
index f953878..8ca3aed 100644 (file)
@@ -6,7 +6,7 @@
  * Released under the MIT license
  * http://oojs.mit-license.org
  *
- * Date: Wed Apr 02 2014 14:29:36 GMT-0700 (PDT)
+ * Date: Wed Apr 02 2014 14:20:50 GMT-0700 (PDT)
  */
 ( function ( global ) {
 
diff --git a/resources/lib/oojs/update-oojs.sh b/resources/lib/oojs/update-oojs.sh
deleted file mode 100755 (executable)
index 57c7625..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-#!/usr/bin/env bash
-
-# FIXME this script is duplicated from update-oojs-ui.sh - factor this out
-
-# This script generates a commit that updates the oojs distribution
-# ./bin/update-oojs.sh path/to/repo/for/oojs
-
-function oojshash() {
-       grep "OOjs v" resources/oojs/oojs.js \
-               | head -n 1 \
-               | grep -Eo '\([a-z0-9]+\)' \
-               | sed 's/^(//' \
-               | sed 's/)$//'
-}
-
-function oojstag() {
-       grep "OOjs v" resources/oojs/oojs.js \
-               | head -n 1 \
-               | grep -Eo '\bv[0-9a-z.-]+\b'
-}
-
-function oojsversion() {
-       grep "OOjs v" resources/oojs/oojs.js \
-               | head -n 1 \
-               | grep -Eo '\bv[0-9a-z.-]+\b.*$'
-}
-
-# cd to the MW directory
-cd $(cd $(dirname $0)/../..; pwd)
-
-if [ "x$1" == "x" ]
-then
-       echo >&2 "Usage: update-oojs.sh path/to/repo/for/oojs"
-       exit 1
-fi
-
-# Undo any changes in the oojs directory
-git reset resources/oojs/
-git checkout resources/oojs/
-
-git fetch origin
-# Create a branch of MW if needed, and reset it to master
-git checkout -B update-oojs origin/master
-
-# Get the old oojs version
-OLDVERSION=$(oojshash)
-if [ "x$OLDVERSION" == "x" ]
-then
-       TAG=$(oojstag)
-fi
-
-# cd to the oojs 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 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/oojs/
-cp -a $1/dist/* resources/oojs/
-# Figure out what the new version is
-NEWVERSION=$(oojsversion)
-# Generate commit summary
-COMMITMSG=$(cat <<END
-Update OOjs to $NEWVERSION
-
-New changes:
-$NEWCHANGES
-END
-)
-# Commit
-git commit resources/oojs/ -m "$COMMITMSG"
-cat >&2 <<END
-
-
-Created commit with changes:
-$NEWCHANGESDISPLAY
-END