Merge "Make update.php file executable"
[mediawiki.git] / maintenance / resources / update-oojs.sh
blob2c500029861e7b8a0e1691fa102ad16badb01eaf
1 #!/usr/bin/env bash
3 if [ -n "$2" ]
4 then
5 # Too many parameters
6 echo >&2 "Usage: $0 [<version>]"
7 exit 1
8 fi
10 REPO_DIR=$(cd $(dirname $0)/../..; pwd) # Root dir of the git repo working tree
11 TARGET_DIR=resources/lib/oojs # Destination relative to the root of the repo
12 NPM_DIR=`mktemp -d 2>/dev/null || mktemp -d -t 'update-oojs'` # e.g. /tmp/update-oojs.rI0I5Vir
14 # Prepare working tree
15 cd $REPO_DIR &&
16 git reset $TARGET_DIR && git checkout $TARGET_DIR && git fetch origin &&
17 git checkout -B upstream-oojs origin/master || exit 1
19 # Fetch upstream version
20 cd $NPM_DIR
21 if [ -n "$1" ]
22 then
23 npm install oojs@$1 || exit 1
24 else
25 npm install oojs || exit 1
28 OOJS_VERSION=$(node -e 'console.log(JSON.parse(require("fs").readFileSync("./node_modules/oojs/package.json")).version);')
29 if [ "$OOJS_VERSION" == "" ]
30 then
31 echo 'Could not find OOjs version'
32 exit 1
35 # Copy file(s)
36 rsync --recursive --delete --force ./node_modules/oojs/dist $REPO_DIR/$TARGET_DIR || exit 1
38 # Clean up temporary area
39 rm -rf $NPM_DIR
41 # Generate commit
42 cd $REPO_DIR || exit 1
44 COMMITMSG=$(cat <<END
45 Update OOjs to v$OOJS_VERSION
47 Release notes:
48 https://git.wikimedia.org/blob/oojs%2Fcore.git/v$OOJS_VERSION/History.md
49 END
52 # Stage deletion, modification and creation of files. Then commit.
53 git add --update $TARGET_DIR && git add $TARGET_DIR && git commit -m "$COMMITMSG" || exit 1