Whamcloud - gitweb
LU-17064 build: check for Build-Parameters in commit 48/52448/19
authorAndreas Dilger <adilger@whamcloud.com>
Wed, 20 Sep 2023 23:39:09 +0000 (17:39 -0600)
committerOleg Drokin <green@whamcloud.com>
Mon, 10 Jun 2024 06:09:48 +0000 (06:09 +0000)
Check if the commit message contains any "Build-Parameters:" lines
embedded in the commit message, like "clientdistro=el9.2" to limit
builds to only the specified distros/arches.  Expect one directive
(for either client or server build) at a time.  The arch is optional,
in which case all architectures are built.

Also accept the "ignore" keyword in the Build-Parameters: line as
well as Test-Parameters: lines, since it is really a build directive.

Build-Parameters: clientdistro=el9.3 clientarch=aarch64
Build-Parameters: distro=el9.3 arch=x86_64
Build-Parameters: distro=el8.9 arch=x86_64
Test-Parameters: trivial
Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Change-Id: I6fe1c59748e287b671a21cc3f3fdb0c4473ebbe5
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/52448
Tested-by: Maloo <maloo@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Patrick Farrell <patrick.farrell@oracle.com>
Reviewed-by: Jian Yu <yujian@whamcloud.com>
Reviewed-by: Alex Zhuravlev <bzzz@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
contrib/git-hooks/commit-msg
contrib/lbuild/lbuild

index d8d400e..0ac8eb1 100755 (executable)
@@ -20,6 +20,7 @@ init() {
        readonly SIGNOFF="Signed-off-by:"
        readonly CHANGEID="Change-Id:"
        readonly FIXES="Fixes:"
+       readonly BUILD_PARAMS="Build-Parameters:"
        readonly TEST_PARAMS="Test-Parameters:"
        readonly TEST_PARAMS2="Test-parameters:"
        readonly LUSTRE_CHANGE="Lustre-change:"
@@ -118,6 +119,13 @@ function do_changeid() {
        HAS_CHANGEID=true
 }
 
+function do_buildparams() {
+       ck_wrapup
+
+       grep -Eq "\<client|\<server|arch=|distro=" <<< $LINE ||
+               error "only {client,server}{distro,arch}= supported"
+}
+
 function do_testparams() {
        ck_wrapup
 
@@ -271,6 +279,7 @@ for full details.  A good example of a valid commit comment is:
     commit/submission.  Keep the same $CHANGEID for ported patches. It
     will automatically be added by the Git commit-msg hook if missing.
 
+    $BUILD_PARAMS extra build options, see https://build.whamcloud.com/
     $TEST_PARAMS extra test options, see https://wiki.whamcloud.com/x/dICC
     $FIXES 12-char-hash ("commit summary line of original broken patch")
     $SIGNOFF Your Real Name <your_email@domain.name>
@@ -295,6 +304,7 @@ while IFS= read -u3 LINE; do
        $SIGNOFF* )             do_signoff ;;
        $CHANGEID* )            do_changeid ;;
        $FIXES* )               do_fixes ;;
+       $BUILD_PARAMS* )        do_buildparams ;;
        $TEST_PARAMS* )         do_testparams ;;
        $TEST_PARAMS2* )        do_testparams ;;
        $LUSTRE_CHANGE* )       do_change ;;
index b822b1e..3c081f5 100755 (executable)
@@ -334,6 +334,60 @@ check_options() {
                        ;;
        esac
 
+    echo "### GIT COMMIT BUILD-PARAMETERS CHECK: git log -1 ###"
+    git log -1
+    echo "### GIT COMMIT BUILD-PARAMETERS CHECK: parsing ###"
+    local build_params="Build-Parameters:"
+    local build_distro=""
+
+    case $DISTRO in
+    rhel*)  build_distro=${DISTRO#rh} ;;
+    sles*)  build_distro=${DISTRO/\./sp} ;;
+    *)      build_distro=$DISTRO ;;
+    esac
+
+    echo "### GIT COMMIT BUILD-PARAMETERS CHECK: environment ###"
+    echo "TARGET_ARCH='$TARGET_ARCH'"
+    echo "DISTRO='$DISTRO'"
+    echo "PATCHLESS='$PATCHLESS'"
+    echo "build_distro='$build_distro'"
+
+    echo "### GIT COMMIT BUILD-PARAMETERS CHECK: eval ###"
+    # Default should be to build everything, unless Build-Parameters are set,
+    # in which case only the specified builds will be done, all others skipped.
+    # Expect lines with one directive per line, possibly comma-separated:
+    #    Build-Parameters: clientdistro=el8.7,el9.2 [clientarch=aarch64]
+    #    Build-Parameters: serverdistro=el8.8 [serverarch=x86_64]
+    #    Build-Parameters: ignore
+    # Having both clientdistro and serverdistro on the same line will not work.
+    local skip=false
+
+    while read build_parameters param1 param2 ignored_params; do
+        local arch=""
+        local distro=""
+
+        skip=true
+        [[ "$param1" =~ "ignore" ]] && break # skip all builds, only for review
+        [[ "$param1" =~ "client" && "$PATCHLESS" == "false" ]] && continue
+        [[ "$param1" =~ "server" && "$PATCHLESS" == "true" ]] && continue
+        [[ "$param1" =~ "distro" ]] && distro="$param1" || distro="$param2"
+        [[ "$param1" =~ "arch" ]] && arch="$param1" || arch="$param2"
+        [[ -z "$arch" || "$arch" =~ "$TARGET_ARCH" ]] &&
+            [[ -z "$distro" || "$distro" =~ "$build_distro" ]] &&
+            skip=false && break
+    done < <(git log -1 | grep -i "^    $build_params" || echo "")
+
+    if $skip; then
+        local msg="SKIP: $build_distro:$TARGET_ARCH not found in $build_params"
+        # create some empty directories to keep createrepo in caller happy
+        mkdir -p RPMS SRPMS
+        echo "$msg" >> SRPMS/README
+        echo "$msg" >> README
+
+        fatal 0 "$msg"
+    fi
+    echo "### GIT COMMIT BUILD-PARAMETERS CHECK: fini ###"
+
     local timestampnodig=$(echo $TIMESTAMP | sed -e s/[0-9]*//g)
     [ "$timestampnodig" = "" ] || TIMESTAMP=$(date -d "$DATE" "+%Y%m%d%H%M%S")
     local timestamplength="${#TIMESTAMP}"