Improve branch cutting scripts 75/61575/1
authorAnil Belur <abelur@linuxfoundation.org>
Sat, 12 Aug 2017 06:58:27 +0000 (16:58 +1000)
committerAnil Belur <abelur@linuxfoundation.org>
Mon, 14 Aug 2017 02:54:50 +0000 (12:54 +1000)
Improve handling 'new-release-tag' parameter for different
autorelease project streams and also handle 'jre' and 'jdk'
parameter correctly depending on the job.
Re-organize CLI options with example usage and update excludes
list.

Change-Id: Ia24f85d1aa9eadc1b676e084b8fa255763aafbdf
Signed-off-by: Anil Belur <abelur@linuxfoundation.org>
scripts/branch_cut/branch_cut.awk
scripts/branch_cut/branch_cutter.sh

index 06a409b079b37b2dc90a65848061afddbc0a9398..b93b84bad0911c34a7f260d56d1dc87815053821 100755 (executable)
@@ -24,7 +24,7 @@ BEGIN {
     endpat = startpat                              # end pattern
     op = "^" ws "---" ws "$"                       # match files starts with "---"
 
-    next_release_tag            = "^" ws "next-release-tag: " curr_tag
+    next_release_tag            = "^" ws "next-release-tag: '{stream}'"
     master                      = "'master'"
     new_branch                  = "'stable/" new_release "'"
     curr_branch                 = "'stable/" curr_release "'"
@@ -39,20 +39,22 @@ BEGIN {
 
     # replace block for autorelease-projects
     #new_rel_yaml_tag           = "- " new_release ":";
-    next_rel_tag_new_yaml_tag   = "    next-release-tag: " new_tag;
+    next_rel_tag_new_yaml_tag   = "    next-release-tag: '{stream}'";
     #br_master_yaml_tag         = "    branch: 'master'";
     jdk_yaml_tag                = "    jdk: 'openjdk8'";
     intg_test_yaml_tag          = "    integration-test: " new_release;
     #curr_rel_yaml_tag          = "- " curr_release ":";
-    next_rel_tag_curr_yaml_tag  = "    next-release-tag: " curr_tag;
+    next_rel_tag_curr_yaml_tag  = "    next-release-tag: '{stream}'";
     #br_stable_curr_yaml_tag    = "    branch: 'stable/" curr_release "'";
 
     # search patterns
     smaster = "^" ws "- master:"
     sstream = "^" ws "stream:"
     srelease = "^" ws "- " curr_release ":"
+    snext_release_tag = "^" ws "next-release-tag:"
     #if (l ~ next_release_tag) { next_release_tag = 1; continue; }
     sbranch = "^" ws "branch: " master
+    sfunctionality = "^" ws "functionality:"
 
     debug = 0                                   # set to 1 to print debug info
     file_format = 2                             # project stream format
@@ -60,6 +62,7 @@ BEGIN {
     release_found = 0
     stream_found = 0
     nrt_found = 0
+    func_found = 0
 }
 
 {
@@ -155,16 +158,24 @@ function process_blk(bs, be, bn,   i, l) {
             l = firstblk[i]
             if (l ~ sstream) { stream_found = 1; }
             if (l ~ srelease) { release_found = 1; indent = substr(l, 1, index(l, "-")-1); continue; }
-            if (l ~ next_release_tag) { nrt_found = 1; continue; }
+            if (l ~ sfunctionality) { func_found = 1; }
+            if (l ~ snext_release_tag) { nrt_found = 1; }
             if (l ~ sbranch) {
                 # append lines
                 if (stream_found && release_found && !nrt_found) {
                     newblk[++nex3] = indent new_rel_yaml_tag;
                     newblk[++nex3] = indent br_master_yaml_tag;
-                    newblk[++nex3] = indent jre_yaml_tag;
+                    # set 'jdk' macro for patch-test jobs
+                    if (!func_found) {
+                        newblk[++nex3] = indent jdk_yaml_tag;
+                    } else {
+                        newblk[++nex3] = indent jre_yaml_tag;
+                    }
                     newblk[++nex3] = indent curr_rel_yaml_tag;
                     newblk[++nex3] = indent br_stable_curr_yaml_tag;
-                    stream_found = 0; release_found = 0;
+                    stream_found = 0;
+                    release_found = 0;
+                    func_found = 0;
                     continue;
                 }
                 if (stream_found && release_found && nrt_found) {
index 780b5a6ea1e73bb8fbbd618d8d916074bb8ca94c..9ee5dafd623d32e8fb3093c1ae816c2ecfb70cbe 100755 (executable)
 #
 ##############################################################################
 
-# List of files exclude
+# List of directories, files to exclude
 declare -a excludes=("releng-defaults.yaml"
-                     "releng-macros.yaml")
+                     "releng-macros.yaml"
+                     "global-jjb"
+                     "lf-infra"
+                     "-macros.yaml"
+                     "validate-autorelease"
+                     "opflex-dependencies.yaml")
 
 TEMP="/tmp/tmp.yaml"
 mod=0
 count=0
 
 function usage {
-    echo "Usage: $(basename $0) options (-n [next release]) (-c [current release]) (-p [previous release]) -h for help";
-    exit 1;
+    echo "Usage: $(basename $0) options (-c [current release]) (-n [next release]) (-p [previous release]) -h for help";
+    echo "example:"
+    echo "branch_cutter.sh -n oxygen -c nitrogen -p carbon"
+    exit 0;
 }
 
 if ( ! getopts ":n:c:p:h" opt ); then
@@ -54,20 +61,20 @@ done
 
 echo "Start Branch Cutting:"
 
-while IFS="" read -r y; do
+while IFS="" read -r file; do
     found=0
-    for f in "${excludes[@]}"; do
-        if [[ $y =~ $f && $found -eq 0 ]]; then
+    for exclude in "${excludes[@]}"; do
+        if [[ $file =~ $exclude && $found -eq 0 ]]; then
             found=1
             break
         fi
     done
     if [[ $found -eq 1 ]]; then
-        echo "Ignore file $y found in excludes list"
+        echo "Ignore file $file found in excludes list"
     else
-        ./branch_cut.awk -v new_reltag="$new_reltag" -v curr_reltag="$curr_reltag" -v prev_reltag="$prev_reltag" "$y" > "$TEMP"
-        [[ ! -s "$TEMP" ]] && echo "$y: excluded"
-        [[ -s "$TEMP" ]] && mv "$TEMP" "$y" && echo "$y: Done" && let "mod++"
+        ./branch_cut.awk -v new_reltag="$new_reltag" -v curr_reltag="$curr_reltag" -v prev_reltag="$prev_reltag" "$file" > "$TEMP"
+        [[ ! -s "$TEMP" ]] && echo "$file: excluded"
+        [[ -s "$TEMP" ]] && mv "$TEMP" "$file" && echo "$file: Done" && let "mod++"
         let "count++"
     fi
 done < <(find ../../jjb -name "*.yaml")