| 1 | #!/bin/bash -eu |
| 2 | |
| 3 | # This script generates a commit that updates our copy of OOUI |
| 4 | |
| 5 | if [ -n "${2:-}" ] |
| 6 | then |
| 7 | # Too many parameters |
| 8 | echo >&2 "Usage: $0 [<version>]" |
| 9 | exit 1 |
| 10 | fi |
| 11 | |
| 12 | REPO_DIR=$(cd "$(dirname $0)/.."; pwd) # Root dir of the git repo working tree |
| 13 | TARGET_DIR="lib/oojs-ui" # Destination relative to the root of the repo |
| 14 | NPM_DIR=$(mktemp -d 2>/dev/null || mktemp -d -t 'update-ooui') # e.g. /tmp/update-ooui.rI0I5Vir |
| 15 | |
| 16 | # Prepare working tree |
| 17 | cd "$REPO_DIR" |
| 18 | git reset -- $TARGET_DIR |
| 19 | git checkout -- $TARGET_DIR |
| 20 | git fetch origin |
| 21 | git checkout -B upstream-ooui origin/master |
| 22 | |
| 23 | # Fetch upstream version |
| 24 | cd $NPM_DIR |
| 25 | if [ -n "${1:-}" ] |
| 26 | then |
| 27 | npm install "oojs-ui@$1" |
| 28 | else |
| 29 | npm install oojs-ui |
| 30 | fi |
| 31 | |
| 32 | OOUI_VERSION=$(node -e 'console.log(require("./node_modules/oojs-ui/package.json").version);') |
| 33 | if [ "$OOUI_VERSION" == "" ] |
| 34 | then |
| 35 | echo 'Could not find OOUI version' |
| 36 | exit 1 |
| 37 | fi |
| 38 | |
| 39 | # Copy files |
| 40 | # - Exclude the minimised distribution files and PNG image assets (VE requires SVG support) |
| 41 | rsync --force --recursive --delete --exclude 'oojs-ui*.min.*' --exclude 'oojs-ui.js' --exclude 'themes/**/images/*/*.png' ./node_modules/oojs-ui/dist/ "$REPO_DIR/$TARGET_DIR" |
| 42 | |
| 43 | # Clean up temporary area |
| 44 | rm -rf "$NPM_DIR" |
| 45 | |
| 46 | # Generate commit |
| 47 | cd $REPO_DIR |
| 48 | |
| 49 | COMMITMSG=$(cat <<END |
| 50 | Update OOUI to v$OOUI_VERSION |
| 51 | |
| 52 | Release notes: |
| 53 | https://gerrit.wikimedia.org/g/oojs/ui/+/v$OOUI_VERSION/History.md |
| 54 | END |
| 55 | ) |
| 56 | |
| 57 | # Stage deletion, modification and creation of files. Then commit. |
| 58 | git add --update $TARGET_DIR |
| 59 | git add $TARGET_DIR |
| 60 | git commit -m "$COMMITMSG" |