| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. -eu |
| 2 | |
| 3 | # This script generates a commit that updates our copy of OOjs |
| 4 | |
| 5 | if [scip-shell system . . `[`. -n "${2:-}" ] |
| 6 | then |
| 7 | # Too many parameters |
| 8 | echoscip-shell system . . echo. >&2 "Usage: $0 [<version>]" |
| 9 | exit 1 |
| 10 | fi |
| 11 | |
| 12 | REPO_DIR=$(cd "$(dirnamescip-shell system . . dirname. $0)/.."; pwdscip-shell system . . pwd.) # Root dir of the git repo working tree |
| 13 | TARGET_DIR="lib/oojs" # Destination relative to the root of the repo |
| 14 | NPM_DIR=$(mktempscip-shell system . . mktemp. -d 2>/dev/nullscip-shell filesystem . . `/dev/null`. || mktempscip-shell system . . mktemp. -d -t 'update-oojs') # e.g. /tmp/update-oojs.rI0I5Vir |
| 15 | |
| 16 | # Prepare working tree |
| 17 | cd "$REPO_DIR" |
| 18 | gitscip-shell system . . git. reset -- $TARGET_DIR |
| 19 | gitscip-shell system . . git. checkout -- $TARGET_DIR |
| 20 | gitscip-shell system . . git. fetch origin |
| 21 | gitscip-shell system . . git. checkout -B upstream-oojs origin/master |
| 22 | |
| 23 | # Fetch upstream version |
| 24 | cd $NPM_DIR |
| 25 | if [scip-shell system . . `[`. -n "${1:-}" ] |
| 26 | then |
| 27 | npmscip-shell system . . npm. install "oojs@$1" |
| 28 | else |
| 29 | npmscip-shell system . . npm. install oojs |
| 30 | fi |
| 31 | |
| 32 | OOJS_VERSION=$(nodescip-shell system . . node. -e 'console.log(require("./node_modules/oojs/package.json").version);') |
| 33 | if [scip-shell system . . `[`. "$OOJS_VERSION" == "" ] |
| 34 | then |
| 35 | echoscip-shell system . . echo. 'Could not find OOjs version' |
| 36 | exit 1 |
| 37 | fi |
| 38 | |
| 39 | # Copy file(s) |
| 40 | rsyncscip-shell system . . rsync. --force ./node_modules/oojs/dist/oojs.js "$REPO_DIR/$TARGET_DIR" |
| 41 | rsyncscip-shell system . . rsync. --force ./node_modules/oojs/AUTHORS.txt "$REPO_DIR/$TARGET_DIR" |
| 42 | rsyncscip-shell system . . rsync. --force ./node_modules/oojs/LICENSE-MIT "$REPO_DIR/$TARGET_DIR" |
| 43 | rsyncscip-shell system . . rsync. --force ./node_modules/oojs/README.md "$REPO_DIR/$TARGET_DIR" |
| 44 | |
| 45 | # Clean up temporary area |
| 46 | rmscip-shell system . . rm. -rf "$NPM_DIR" |
| 47 | |
| 48 | # Generate commit |
| 49 | cd $REPO_DIR |
| 50 | |
| 51 | COMMITMSG=$(catscip-shell system . . cat. <<END |
| 52 | Update OOjs to v$OOJS_VERSION |
| 53 | |
| 54 | Release notes: |
| 55 | https://gerrit.wikimedia.org/g/oojs/core/+/v$OOJS_VERSION/History.md |
| 56 | END |
| 57 | ) |
| 58 | |
| 59 | # Stage deletion, modification and creation of files. Then commit. |
| 60 | gitscip-shell system . . git. add --update $TARGET_DIR |
| 61 | gitscip-shell system . . git. add $TARGET_DIR |
| 62 | gitscip-shell system . . git. commit -m "$COMMITMSG" |