update-oojs.sh 1.3 KB

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