[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] scripts/git: Let git-push-all.sh skip unchanged test branches



commit b47b71ad2fc095b43437317011d127424188eb4f
Author: teor <teor@xxxxxxxxxxxxxx>
Date:   Mon Aug 12 11:12:41 2019 +1000

    scripts/git: Let git-push-all.sh skip unchanged test branches
    
    Skip test branches that are the same as remote maint/release/master
    branches.
    
    Add a TOR_PUSH_SAME and -s argument to git-push-all.sh to change this
    default.
    
    Part of 31314.
---
 changes/ticket31314         |  4 +++
 scripts/git/git-push-all.sh | 73 ++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 73 insertions(+), 4 deletions(-)

diff --git a/changes/ticket31314 b/changes/ticket31314
index 8b5f5da8f..7ce96e96c 100644
--- a/changes/ticket31314
+++ b/changes/ticket31314
@@ -12,3 +12,7 @@
     - Add a "--" command-line argument, to
       separate git-push-all.sh script arguments from arguments that are passed
       through to git push. Closes ticket 31314.
+    - Skip pushing test branches that are the same as a remote
+      maint/release/master branch in git-push-all.sh by default. Add a -s
+      argument, so git-push-all.sh can push all test branches.
+      Closes ticket 31314.
diff --git a/scripts/git/git-push-all.sh b/scripts/git/git-push-all.sh
index 2d6e77a8c..8a8ef1f2d 100755
--- a/scripts/git/git-push-all.sh
+++ b/scripts/git/git-push-all.sh
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 
-# Usage: git-push-all.sh -t <test-branch-prefix> -r <remote-name>
+# Usage: git-push-all.sh -t <test-branch-prefix> -r <remote-name> -s
 #                        -- <git-opts>
 #        env vars: TOR_UPSTREAM_REMOTE_NAME=upstream TOR_PUSH_DELAY=0
 #        git-opts: --no-atomic --dry-run (any other git push option)
@@ -20,10 +20,17 @@ set -e
 # git push command and default arguments
 GIT_PUSH=${TOR_GIT_PUSH:-"git push --atomic"}
 # The upstream remote which git.torproject.org/tor.git points to.
-# In test branch mode, override this setting with -r <remote-name>
-UPSTREAM_REMOTE=${TOR_UPSTREAM_REMOTE_NAME:-"upstream"}
+DEFAULT_UPSTREAM_REMOTE=${TOR_UPSTREAM_REMOTE_NAME:-"upstream"}
+# Push to a different upstream remote using -r <remote-name>
+UPSTREAM_REMOTE=${DEFAULT_UPSTREAM_REMOTE}
 # Add a delay between pushes, so CI runs on the most important branches first
 PUSH_DELAY=${TOR_PUSH_DELAY:-0}
+# Push (1) or skip (0) test branches that are the same as an upstream
+# maint/master branch. Push if you are testing that the CI environment still
+# works on old code, skip if you are testing new code in the branch.
+# Default: skip unchanged branches.
+# Inverted by the -s option.
+PUSH_SAME=${TOR_PUSH_SAME:-0}
 
 #######################
 # Argument processing #
@@ -34,7 +41,7 @@ PUSH_DELAY=${TOR_PUSH_DELAY:-0}
 # <tbbn>_029, <tbbn>_035, ... , <tbbn>_master, and merge forward.
 TEST_BRANCH_PREFIX=
 
-while getopts ":r:t:" opt; do
+while getopts ":r:st:" opt; do
   case "$opt" in
     r) UPSTREAM_REMOTE="$OPTARG"
        echo "    *** PUSHING TO REMOTE: ${UPSTREAM_REMOTE} ***"
@@ -42,6 +49,15 @@ while getopts ":r:t:" opt; do
        shift
        OPTIND=$[$OPTIND - 2]
        ;;
+    s) PUSH_SAME=$[! "$PUSH_SAME" ]
+       if [ "$PUSH_SAME" -eq 0 ]; then
+         echo "    *** SKIPPING UNCHANGED TEST BRANCHES ***"
+       else
+         echo "    *** PUSHING UNCHANGED TEST BRANCHES ***"
+       fi
+       shift
+       OPTIND=$[$OPTIND - 1]
+       ;;
     t) TEST_BRANCH_PREFIX="$OPTARG"
        echo "    *** PUSHING TEST BRANCHES: ${TEST_BRANCH_PREFIX}_nnn ***"
        shift
@@ -73,6 +89,29 @@ if [ "$TEST_BRANCH_PREFIX" ]; then
   fi
 fi
 
+################################
+# Git upstream remote branches #
+################################
+
+DEFAULT_UPSTREAM_BRANCHES=
+if [ "$DEFAULT_UPSTREAM_REMOTE" != "$UPSTREAM_REMOTE" ]; then
+  DEFAULT_UPSTREAM_BRANCHES=`echo \
+    ${DEFAULT_UPSTREAM_REMOTE}/master \
+    ${DEFAULT_UPSTREAM_REMOTE}/{release,maint}-0.4.1 \
+    ${DEFAULT_UPSTREAM_REMOTE}/{release,maint}-0.4.0 \
+    ${DEFAULT_UPSTREAM_REMOTE}/{release,maint}-0.3.5 \
+    ${DEFAULT_UPSTREAM_REMOTE}/{release,maint}-0.2.9 \
+    `
+fi
+
+UPSTREAM_BRANCHES=`echo \
+  ${UPSTREAM_REMOTE}/master \
+  ${UPSTREAM_REMOTE}/{release,maint}-0.4.1 \
+  ${UPSTREAM_REMOTE}/{release,maint}-0.4.0 \
+  ${UPSTREAM_REMOTE}/{release,maint}-0.3.5 \
+  ${UPSTREAM_REMOTE}/{release,maint}-0.2.9 \
+  `
+
 ########################
 # Git branches to push #
 ########################
@@ -115,6 +154,32 @@ fi
 # Entry point #
 ###############
 
+# Skip the test branches that are the same as the upstream branches
+if [ "$PUSH_SAME" -eq 0 -a "$TEST_BRANCH_PREFIX" ]; then
+  NEW_PUSH_BRANCHES=
+  for b in $PUSH_BRANCHES; do
+    PUSH_COMMIT=`git rev-parse $b`
+    SKIP_UPSTREAM=
+    for u in $DEFAULT_UPSTREAM_BRANCHES $UPSTREAM_BRANCHES; do
+      UPSTREAM_COMMIT=`git rev-parse "$u"`
+      if [ "$PUSH_COMMIT" = "$UPSTREAM_COMMIT" ]; then
+        SKIP_UPSTREAM="$u"
+      fi
+    done
+    if [ "$SKIP_UPSTREAM" ]; then
+      printf "Skipping unchanged: %s remote: %s\n" \
+        "$b" "$SKIP_UPSTREAM"
+    else
+      if [ "$NEW_PUSH_BRANCHES" ]; then
+        NEW_PUSH_BRANCHES="${NEW_PUSH_BRANCHES} ${b}"
+      else
+        NEW_PUSH_BRANCHES="${b}"
+      fi
+    fi
+  done
+  PUSH_BRANCHES=${NEW_PUSH_BRANCHES}
+fi
+
 if [ "$PUSH_DELAY" -le 0 ]; then
   echo "Pushing $PUSH_BRANCHES"
   # We know that there are no spaces in any branch within $PUSH_BRANCHES, so



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits