summaryrefslogtreecommitdiff
path: root/maintenance/resources/update-oojs-ui.sh
blob: 1b3529225af04f1df3755932bbcb53289c89077f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/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
npm install && grunt git-build || 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' --exclude 'oojs-ui*.rtl.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