mediawiki.page.gallery.resize: Remove weird mw.hook call
[lhc/web/wiklou.git] / maintenance / resources / update-oojs-ui.sh
1 #!/usr/bin/env bash
2
3 # This script generates a commit that updates our distribution copy of OOjs UI
4
5 if [ -z "$1" ]
6 then
7 # Missing required parameter
8 echo >&2 "Usage: $0 path/to/repo/for/oojs-ui"
9 exit 1
10 fi
11
12 TARGET_REPO=$(cd $(dirname $0)/../..; pwd)
13 TARGET_DIR=resources/lib/oojs-ui
14 UI_REPO=$1
15
16 function oojsuihash() {
17 grep "OOjs UI v" $TARGET_REPO/$TARGET_DIR/oojs-ui.js \
18 | head -n 1 \
19 | grep -Eo '\([a-z0-9]+\)' \
20 | sed 's/^(//' \
21 | sed 's/)$//'
22 }
23
24 function oojsuitag() {
25 grep "OOjs UI v" $TARGET_REPO/$TARGET_DIR/oojs-ui.js \
26 | head -n 1 \
27 | grep -Eo '\bv[0-9a-z.-]+\b'
28 }
29
30 function oojsuiversion() {
31 grep "OOjs UI v" $TARGET_REPO/$TARGET_DIR/oojs-ui.js \
32 | head -n 1 \
33 | grep -Eo '\bv[0-9a-z.-]+\b.*$'
34 }
35
36 # Prepare working tree
37 cd $TARGET_REPO &&
38 git reset $TARGET_DIR && git checkout $TARGET_DIR && git fetch origin &&
39 git checkout -B upstream-oojsui origin/master || exit 1
40
41 cd $UI_REPO || exit 1
42
43 # Read the old version and check for changes
44 OLDHASH=$(oojsuihash)
45 if [ -z "$OLDHASH" ]
46 then
47 OLDTAG=$(oojsuitag)
48 fi
49 if [ "$OLDHASH" == "" ]
50 then
51 OLDHASH=$(git rev-parse $OLDTAG)
52 if [ $? != 0 ]
53 then
54 echo Could not find OOjs UI version
55 cd -
56 exit 1
57 fi
58 fi
59 if [ "$(git rev-parse $OLDHASH)" == "$(git rev-parse HEAD)" ]
60 then
61 echo "No changes (already at $OLDHASH)"
62 cd -
63 exit 0
64 fi
65
66 # Build the distribution (using grunt-test instead of grunt-build, because we
67 # want to run unit tests first, and because grunt-build is for a release build
68 # and wouldn't put a git hash in the file headers)
69 npm install && grunt test || exit 1
70
71 # Get the list of changes
72 NEWCHANGES=$(git log $OLDHASH.. --oneline --no-merges --reverse --color=never)
73 NEWCHANGESDISPLAY=$(git log $OLDHASH.. --oneline --no-merges --reverse --color=always)
74
75 # Copy files
76 # - Exclude the default non-svg stylesheet
77 rsync --recursive --delete --force --exclude 'oojs-ui.css' ./dist/ $TARGET_REPO/$TARGET_DIR || exit 1
78
79 # Read the new version
80 NEWVERSION=$(oojsuiversion)
81
82 # Generate commit
83 cd $TARGET_REPO
84 COMMITMSG=$(cat <<END
85 Update OOjs UI to $NEWVERSION
86
87 New changes:
88 $NEWCHANGES
89 END
90 )
91 git add -u $TARGET_DIR && git add $TARGET_DIR && git commit -m "$COMMITMSG"
92 cat >&2 <<END
93
94
95 Created commit with changes:
96 $NEWCHANGESDISPLAY
97 END