From 2754dc6be5f9a0e339f4dd42fe1d16f6f9e4a203 Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Wed, 20 Sep 2023 17:39:09 -0600 Subject: [PATCH] LU-17064 build: check for Build-Parameters in commit 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 Change-Id: I6fe1c59748e287b671a21cc3f3fdb0c4473ebbe5 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/52448 Tested-by: Maloo Tested-by: jenkins Reviewed-by: Patrick Farrell Reviewed-by: Jian Yu Reviewed-by: Alex Zhuravlev Reviewed-by: Oleg Drokin --- contrib/git-hooks/commit-msg | 10 ++++++++ contrib/lbuild/lbuild | 54 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/contrib/git-hooks/commit-msg b/contrib/git-hooks/commit-msg index d8d400e..0ac8eb1 100755 --- a/contrib/git-hooks/commit-msg +++ b/contrib/git-hooks/commit-msg @@ -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 "\ @@ -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 ;; diff --git a/contrib/lbuild/lbuild b/contrib/lbuild/lbuild index b822b1e..3c081f5 100755 --- a/contrib/lbuild/lbuild +++ b/contrib/lbuild/lbuild @@ -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}" -- 1.8.3.1