Merge "Add two new debug log groups"
[lhc/web/wiklou.git] / resources / oojs / update-oojs.sh
1 #!/usr/bin/env bash
2
3 # FIXME this script is duplicated from update-oojs-ui.sh - factor this out
4
5 # This script generates a commit that updates the oojs distribution
6 # ./bin/update-oojs.sh path/to/repo/for/oojs
7
8 function oojshash() {
9 grep "OOjs v" resources/oojs/oojs.js \
10 | head -n 1 \
11 | grep -Eo '\([a-z0-9]+\)' \
12 | sed 's/^(//' \
13 | sed 's/)$//'
14 }
15
16 function oojstag() {
17 grep "OOjs v" resources/oojs/oojs.js \
18 | head -n 1 \
19 | grep -Eo '\bv[0-9a-z.-]+\b'
20 }
21
22 function oojsversion() {
23 grep "OOjs v" resources/oojs/oojs.js \
24 | head -n 1 \
25 | grep -Eo '\bv[0-9a-z.-]+\b.*$'
26 }
27
28 # cd to the MW directory
29 cd $(cd $(dirname $0)/../..; pwd)
30
31 if [ "x$1" == "x" ]
32 then
33 echo >&2 "Usage: update-oojs.sh path/to/repo/for/oojs"
34 exit 1
35 fi
36
37 # Undo any changes in the oojs directory
38 git reset resources/oojs/
39 git checkout resources/oojs/
40
41 git fetch origin
42 # Create a branch of MW if needed, and reset it to master
43 git checkout -B update-oojs origin/master
44
45 # Get the old oojs version
46 OLDVERSION=$(oojshash)
47 if [ "x$OLDVERSION" == "x" ]
48 then
49 TAG=$(oojstag)
50 fi
51
52 # cd to the oojs directory
53 cd $1 || exit 1
54 if [ "x$OLDVERSION" == "x" ]
55 then
56 # Try the tag
57 OLDVERSION=$(git rev-parse $TAG)
58 if [ $? != 0 ]
59 then
60 echo Could not find OOjs version
61 cd -
62 exit 1
63 fi
64 fi
65 if [ "$(git rev-parse $OLDVERSION)" == "$(git rev-parse HEAD)" ]
66 then
67 echo "No changes (already at $OLDVERSION)"
68 cd -
69 exit 0
70 fi
71 # Build the distribution
72 npm install || exit 1
73 grunt || exit 1
74 # Get the list of changes
75 NEWCHANGES=$(git log $OLDVERSION.. --oneline --no-merges --reverse --color=never)
76 NEWCHANGESDISPLAY=$(git log $OLDVERSION.. --oneline --no-merges --reverse --color=always)
77 # cd back to the VisualEditor directory
78 cd -
79
80 # Copy files from dist/ to resources/oojs/
81 cp -a $1/dist/* resources/oojs/
82 # Figure out what the new version is
83 NEWVERSION=$(oojsversion)
84 # Generate commit summary
85 COMMITMSG=$(cat <<END
86 Update OOjs to $NEWVERSION
87
88 New changes:
89 $NEWCHANGES
90 END
91 )
92 # Commit
93 git commit resources/oojs/ -m "$COMMITMSG"
94 cat >&2 <<END
95
96
97 Created commit with changes:
98 $NEWCHANGESDISPLAY
99 END