Mobrovac has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/280914

Change subject: git-update: Update the deps only when required
......................................................................

git-update: Update the deps only when required

Up until now, `vagrant git-update` would blindly try to update all of
the services' dependencies regardless of whether that's actually needed
or not. This patch makes the git-update script inspect the list of files
that have actually changed, and if npm, composer or pip config files
have, it updates the dependencies. Otherwise, no such action is taken.

Bug: T126098
Change-Id: I65bdc56ec7415237652e394a4634637b6e7c2b25
---
M puppet/modules/mediawiki/templates/run-git-update.erb
1 file changed, 23 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/vagrant 
refs/changes/14/280914/1

diff --git a/puppet/modules/mediawiki/templates/run-git-update.erb 
b/puppet/modules/mediawiki/templates/run-git-update.erb
index 4607185..cbdf155 100644
--- a/puppet/modules/mediawiki/templates/run-git-update.erb
+++ b/puppet/modules/mediawiki/templates/run-git-update.erb
@@ -17,15 +17,21 @@
 UPDATE_ERRORS=( )
 
 function mwv_service_update {
-  ERR=''
+  local ERR=''
+  local PULL_RESULT=0
   source "$1"
   echo -e "\e[36m==> Updating ${SERVICE_NAME} ...\e[0m"
   if [[ -n $NEED_CHDIR && -d $SERVICE_DIR ]]; then
     if [[ -n $DO_PULL ]]; then
       mwv_git_pull "$SERVICE_DIR" inline
+      PULL_RESULT=$?
+    fi
+    if [[ ${PULL_RESULT} -eq 2 ]]; then
+      # git pull failed, bail out
+      return 1
     fi
     cd $SERVICE_DIR
-    if [[ -n $UPDATE_CMD ]]; then
+    if [[ -n "${UPDATE_CMD}" && ${PULL_RESULT} -eq 1 ]]; then
       echo "[*] Updating dependencies for ${SERVICE_NAME} ..."
       [[ -n ${DO_RESTART} ]] && sudo service ${RESTART_NAME} stop
       if ! /bin/sh -c "$UPDATE_CMD"; then
@@ -37,7 +43,7 @@
   fi
   if [[ -n $DO_RESTART && -z $ERR ]]; then
     echo "[*] Restarting service ${RESTART_NAME} ..."
-    sudo service ${RESTART_NAME} start
+    sudo service ${RESTART_NAME} restart
   fi
   echo
 }
@@ -45,6 +51,7 @@
 
 function mwv_git_pull {
   local OUTPUT_INLINE=${2:-}
+  local RETVAL=0
   cd "$1"
   if [[ -z $OUTPUT_INLINE ]]; then
     echo -e "\e[36m==> Updating $(pwd) ...\e[0m"
@@ -62,18 +69,24 @@
   fi
 
   local ERR=''
+  local PULL_CMD='git pull --rebase'
   if [[ -n $BRANCH ]]; then
     local REMOTE=$(git config branch.${BRANCH}.remote)
     if [[ -n $REMOTE ]]; then
       local URL=$(git config --get remote.${REMOTE}.url)
       if [[ $URL == ssh://* ]]; then
         # Convert remote git url from ssh:// to anonymous https://
-        local TEMPURL=$(echo $URL | sed -e 's!ssh://[^@]\+@!https://!g' -e 
's!:29418!/r!g')
-        git pull --rebase $TEMPURL
-      else
-        git pull --rebase
+        URL=$(echo $URL | sed -e 's!ssh://[^@]\+@!https://!g' -e 
's!:29418!/r!g')
+        PULL_CMD="${PULL_CMD} ${URL}"
       fi
-
+      # fetch the updates, but don't apply them just yet
+      git fetch ${REMOTE}
+      if git diff --name-only ${REMOTE}/${BRANCH} | grep -E 
'package.json|requirements.txt|composer.json' >/dev/null; then
+        # some dependencies have changed, we need to signal it
+        RETVAL=1
+      fi
+      # update the repo
+      ${PULL_CMD}
       if [[ $? -ne 0 ]]; then
         # If we didn't successfully update (possibly because we're on
         # a local branch), leave the submodules alone.
@@ -94,9 +107,11 @@
   if [[ -n $ERR ]]; then
     echo -e "\e[1;31m ***** ${ERR}\e[0m"
     UPDATE_ERRORS+=("$ERR")
+    RETVAL=2
   fi
 
   [[ -z $OUTPUT_INLINE ]] && echo
+  return ${RETVAL}
 }
 export -f mwv_git_pull
 

-- 
To view, visit https://gerrit.wikimedia.org/r/280914
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I65bdc56ec7415237652e394a4634637b6e7c2b25
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/vagrant
Gerrit-Branch: master
Gerrit-Owner: Mobrovac <mobro...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to