Merge "Remove alto carbon jobs"
[releng/builder.git] / jjb / integration / multipatch-distribution.sh
index ce0fcb4f7f319ea147f3d58102743d4ec5ee6ad8..ae9791d7446c7ff0c94f35b7d5cb7d66b32b6fa6 100644 (file)
@@ -29,10 +29,58 @@ export GIT_COMMITTER_NAME="Multipatch Job"
 #
 # multipatch-build:openflowplugin:45/69445/1,genius:46/69446/1,netvirt:47/69447/1
 if [ -n "$GERRIT_EVENT_COMMENT_TEXT" ]; then
-    # Grep the multipatch-build: line and then strip from the beginning to the :
-    PATCHES_TO_BUILD=$(echo "$GERRIT_EVENT_COMMENT_TEXT" | grep 'multipatch-build:')
+    if [[ "$GERRIT_EVENT_COMMENT_TEXT" == *fast* ]]; then
+        BUILD_FAST="true"
+        PATCHES_TO_BUILD=$(echo "$GERRIT_EVENT_COMMENT_TEXT" | grep 'multipatch-build-fast:')
+    else
+        BUILD_FAST="false"
+        PATCHES_TO_BUILD=$(echo "$GERRIT_EVENT_COMMENT_TEXT" | grep 'multipatch-build:')
+    fi
     PATCHES_TO_BUILD=${PATCHES_TO_BUILD#*:}
 fi
+if ${BUILD_FAST}; then
+    fast_option="-Pq"
+else
+    fast_option=""
+fi
+# check if topic exists, e.g. topic=binding-tlc-rpc
+if [[ "${PATCHES_TO_BUILD}" == *topic* ]]; then
+    TOPIC="${PATCHES_TO_BUILD#*=}"
+    echo "Create topic ${TOPIC} patch list"
+    PATCHES_TO_BUILD=""
+    read -ra PROJECT_LIST <<< "${BUILD_ORDER}"
+    for PROJECT in "${PROJECT_LIST[@]}"; do
+        # get all patches number for a topic for a given project
+        IFS=$'\n' read -rd '' -a GERRIT_PATCH_LIST <<< "$(ssh -p 29418 jenkins-$SILO@git.opendaylight.org gerrit query status:open topic:${TOPIC} project:${PROJECT} \
+        | grep 'number:' | awk '{{ print $2 }}')" || true
+        echo "Add ${PROJECT}:${GERRIT_PATCH_LIST[*]}"
+        # add project if it is the first with patches or it is not the first
+        if [[ -z "${PATCHES_TO_BUILD}" && ! -z "${GERRIT_PATCH_LIST[*]}" ]]; then
+            PATCHES_TO_BUILD="${PROJECT}"
+        elif [[ ! -z "${PATCHES_TO_BUILD}" ]]; then
+            PATCHES_TO_BUILD="${PATCHES_TO_BUILD},${PROJECT}"
+        fi
+        # sort project patches
+        if [[ ! -z "${GERRIT_PATCH_LIST[*]}" ]]; then
+            REF_LIST=()
+            # create reference list with patch number-refspec
+            for PATCH in "${GERRIT_PATCH_LIST[@]}"; do
+                REFSPEC=$(ssh -p 29418 jenkins-$SILO@git.opendaylight.org gerrit query change:${PATCH} --current-patch-set \
+                | grep 'ref:' | awk '{{ print $2 }}')
+                REF_LIST+=("${PATCH}-${REFSPEC/refs\/changes\/}")
+            done
+            # sort reference list by patch number
+            IFS=$'\n' SORT_REF=$(sort <<<"${REF_LIST[*]}") && unset IFS
+            read -rd '' -a SORT_REF_LIST <<< "${SORT_REF[*]}" || true
+            # add refspec to patches to build list
+            for PATCH in "${SORT_REF_LIST[@]}"; do
+                PATCHES_TO_BUILD="${PATCHES_TO_BUILD}:${PATCH/*-/}"
+            done
+        fi
+    done
+fi
+
+echo "Patches to build: ${PATCHES_TO_BUILD}"
 IFS=',' read -ra PATCHES <<< "${PATCHES_TO_BUILD}"
 
 # For each patch:
@@ -100,7 +148,7 @@ do
     fi
     # Build project
     "$MVN" clean install \
-    -e -Pq \
+    -e ${fast_option} \
     -Dstream=oxygen \
     -Dgitid.skip=false \
     -Dmaven.gitcommitid.skip=false \
@@ -108,6 +156,9 @@ do
     --settings "$SETTINGS_FILE" \
     $MAVEN_OPTIONS
     cd "${BUILD_DIR}" || exit 1
+    # Since we've installed the artifacts, we can delete the build and save
+    # disk space
+    rm -rf "${PROJECT_SHORTNAME}"
 done
 
 if [ "${distribution_status}" == "not_included" ]; then