This is an automated email from the ASF dual-hosted git repository.

diqiu50 pushed a commit to branch feature/10448-non-interactive-release
in repository https://gitbox.apache.org/repos/asf/gravitino.git

commit 390613c9454355bc9f24fe4fd492e7b23466ac15
Author: diqiu50 <[email protected]>
AuthorDate: Tue Mar 17 08:04:43 2026 +0000

    [#10448] feat(release): enhance do-release scripts to support 
non-interactive mode
---
 dev/release/do-release.sh   | 59 ++++++++++++++++++++++++++++++++-------
 dev/release/release-util.sh | 68 ++++++++++++++++++++++++++++++---------------
 2 files changed, 95 insertions(+), 32 deletions(-)

diff --git a/dev/release/do-release.sh b/dev/release/do-release.sh
index 55ec5dada7..d58b3eca90 100755
--- a/dev/release/do-release.sh
+++ b/dev/release/do-release.sh
@@ -1,5 +1,7 @@
 #!/usr/bin/env bash
 
+set -euo pipefail
+
 #
 # Licensed to the Apache Software Foundation (ASF) under one or more
 # contributor license agreements.  See the NOTICE file distributed with
@@ -20,22 +22,46 @@
 # Referred from Apache Spark's release script
 # dev/create-release/do-release.sh
 
-SELF=$(cd $(dirname $0) && pwd)
+RUNNING_IN_DOCKER=${RUNNING_IN_DOCKER:-0}
+
+SELF=$(cd "$(dirname "$0")" && pwd)
 
-while getopts ":b:n" opt; do
+while getopts ":b:s:p:t:r:nyh" opt; do
   case $opt in
     b) GIT_BRANCH=$OPTARG ;;
     n) DRY_RUN=1 ;;
+    s) RELEASE_STEP=$OPTARG ;;
+    p) GPG_PASSPHRASE=$OPTARG ;;
+    t) ASF_PASSWORD=$OPTARG ;;
+    r) RC_COUNT=$OPTARG ;;
+    y) FORCE=1 ;;
+    h)
+      echo "Usage: $0 [options]"
+      echo "Options:"
+      echo "  -b <branch>   Git branch to release (e.g., branch-1.2)"
+      echo "  -s <step>     Release step to execute: tag, build, docs, 
publish, finalize"
+      echo "  -r <num>      Release candidate number (e.g., 6 for rc6)"
+      echo "  -n            Dry run mode"
+      echo "  -p <pass>     GPG passphrase"
+      echo "  -t <pass>     ASF password"
+      echo "  -y            Force continue without confirmation"
+      echo "  -h            Show this help message"
+      exit 0
+      ;;
     \?) error "Invalid option: $OPTARG" ;;
   esac
 done
 
-DRY_RUN=${DRY_RUN:-0}
-export DRY_RUN
+export DRY_RUN=${DRY_RUN:-0}
+export FORCE=${FORCE:-0}
+export RC_COUNT=${RC_COUNT:-0}
+export RELEASE_STEP=${RELEASE_STEP:-}
+
+echo "DRY_RUN=$DRY_RUN FORCE=$FORCE RC_COUNT=$RC_COUNT 
RELEASE_STEP=$RELEASE_STEP"
 
 cmds=("git" "gpg" "svn" "twine" "shasum" "sha1sum" "jq" "make")
 for cmd in "${cmds[@]}"; do
-  if ! command -v $cmd &> /dev/null; then
+  if ! command -v "$cmd" &> /dev/null; then
     echo "$cmd is required to run this script."
     exit 1
   fi
@@ -67,8 +93,15 @@ if [ "$RUNNING_IN_DOCKER" = "1" ]; then
     export JAVA_HOME=/usr
   fi
 else
-  # Outside docker, need to ask for information about the release.
-  get_release_info
+  # Outside docker, need to ask for information about the release if required 
vars are missing.
+  # Set default values to avoid unbound variable errors with set -u
+  RELEASE_VERSION=${RELEASE_VERSION:-}
+  GIT_BRANCH=${GIT_BRANCH:-}
+  RC_COUNT=${RC_COUNT:-0}
+
+  if [ -z "$GIT_BRANCH" ] || [ -z "$RELEASE_VERSION" ] || [ -z "$RC_COUNT" ]; 
then
+    get_release_info
+  fi
 fi
 
 function should_build {
@@ -80,8 +113,12 @@ if should_build "tag" && [ $SKIP_TAG = 0 ]; then
   run_silent "Creating release tag $RELEASE_TAG..." "tag.log" \
     "$SELF/release-tag.sh"
   echo "It may take some time for the tag to be synchronized to github."
-  echo "Press enter when you've verified that the new tag ($RELEASE_TAG) is 
available."
-  read
+  if [ "$FORCE" = "1" ]; then
+    echo "Force mode: skipping wait."
+  else
+    echo "Press enter when you've verified that the new tag ($RELEASE_TAG) is 
available."
+    read
+  fi
 else
   echo "Skipping tag creation for $RELEASE_TAG."
 fi
@@ -107,7 +144,9 @@ else
   echo "Skipping publish step."
 fi
 
-if [ ! -z "$RELEASE_STEP" ] && [ "$RELEASE_STEP" = "finalize" ]; then
+if [ "$RELEASE_STEP" = "finalize" ]; then
   run_silent "Finalizing release" "finalize.log" \
     "$SELF/release-build.sh" finalize
 fi
+
+echo "Release build and publish completed"
diff --git a/dev/release/release-util.sh b/dev/release/release-util.sh
index 1ab77c5aff..37988d3da5 100755
--- a/dev/release/release-util.sh
+++ b/dev/release/release-util.sh
@@ -34,12 +34,26 @@ function error {
 function read_config {
   local PROMPT="$1"
   local DEFAULT="$2"
+  local VAR_NAME="$3"  # Optional: environment variable name to check first
   local REPLY=
 
-  read -p "$PROMPT [$DEFAULT]: " REPLY
+  # If VAR_NAME is provided and the corresponding env var is set, use it
+  if [ -n "$VAR_NAME" ] && [ -n "${!VAR_NAME:-}" ] && [ "$FORCE" = "1" ]; then
+    echo "${!VAR_NAME}"
+    return
+  fi
+
+  # If DEFAULT is provided and not empty, show it as default
+  local DISPLAY_DEFAULT="$DEFAULT"
+  if [ -n "$DISPLAY_DEFAULT" ]; then
+    read -p "$PROMPT [$DISPLAY_DEFAULT]: " REPLY
+  else
+    read -p "$PROMPT: " REPLY
+  fi
+
   local RETVAL="${REPLY:-$DEFAULT}"
   if [ -z "$RETVAL" ]; then
-    error "$PROMPT is must be provided."
+    error "$PROMPT must be provided."
   fi
   echo "$RETVAL"
 }
@@ -81,7 +95,7 @@ function check_for_tag {
 
 function get_release_info {
   if [ -z "$GIT_BRANCH" ]; then
-    # If no branch is specified, found out the latest branch from the repo.
+    # If no branch is specified, find out the latest branch from the repo.
     GIT_BRANCH=$(git ls-remote --heads "$ASF_REPO" |
       grep -e "refs/heads/branch-.*" |
       awk '{print $2}' |
@@ -90,7 +104,7 @@ function get_release_info {
       cut -d/ -f3)
   fi
 
-  export GIT_BRANCH=$(read_config "Branch" "$GIT_BRANCH")
+  export GIT_BRANCH=$(read_config "Branch" "$GIT_BRANCH" GIT_BRANCH)
 
   # Find the current version for the branch.
   local VERSION=$(curl -s "$ASF_REPO_WEBUI/$GIT_BRANCH/gradle.properties" |
@@ -115,33 +129,40 @@ function get_release_info {
     local PREV_REL_REV=$((REV - 1))
     local PREV_REL_TAG="v${SHORT_VERSION}.${PREV_REL_REV}"
     if check_for_tag "$PREV_REL_TAG"; then
-      RC_COUNT=1
+      NRC_COUNT=1
       REV=$((REV + 1))
       NEXT_VERSION="${SHORT_VERSION}.${REV}-SNAPSHOT"
     else
       RELEASE_VERSION="${SHORT_VERSION}.${PREV_REL_REV}"
-      RC_COUNT=$(git ls-remote --tags "$ASF_REPO" "v${RELEASE_VERSION}-rc*" | 
wc -l)
-      RC_COUNT=$((RC_COUNT + 1))
+      NRC_COUNT=$(git ls-remote --tags "$ASF_REPO" "v${RELEASE_VERSION}-rc*" | 
wc -l)
+      NRC_COUNT=$((NRC_COUNT + 1))
     fi
   else
     REV=$((REV + 1))
     NEXT_VERSION="${SHORT_VERSION}.${REV}-SNAPSHOT"
-    RC_COUNT=1
+    NRC_COUNT=1
   fi
 
   export NEXT_VERSION
-  export RELEASE_VERSION=$(read_config "Release" "$RELEASE_VERSION")
+  export RELEASE_VERSION=$(read_config "Release" "$RELEASE_VERSION" 
RELEASE_VERSION)
 
-  RC_COUNT=$(read_config "RC #" "$RC_COUNT")
+  if [ "$FORCE" = "1" ]; then
+    NRC_COUNT=$RC_COUNT
+  fi
+  RC_COUNT=$(read_config "RC #" "$RC_COUNT" NRC_COUNT)
   export RC_COUNT
 
   # Check if the RC already exists, and if re-creating the RC, skip tag 
creation.
   RELEASE_TAG="v${RELEASE_VERSION}-rc${RC_COUNT}"
   SKIP_TAG=0
   if check_for_tag "$RELEASE_TAG"; then
-    read -p "$RELEASE_TAG already exists. Continue anyway [y/n]? " ANSWER
-    if [ "$ANSWER" != "y" ]; then
-      error "Exiting."
+    if [ "$FORCE" = "1" ]; then
+      echo "$RELEASE_TAG already exists. Force continuing."
+    else
+      read -p "$RELEASE_TAG already exists. Continue anyway [y/n]? " ANSWER
+      if [ "$ANSWER" != "y" ]; then
+        error "Exiting."
+      fi
     fi
     SKIP_TAG=1
   fi
@@ -155,23 +176,23 @@ function get_release_info {
     if [[ $SKIP_TAG = 0 ]]; then
       GIT_REF="$GIT_BRANCH"
     fi
-    GIT_REF=$(read_config "Ref" "$GIT_REF")
+    GIT_REF=$(read_config "Ref" "$GIT_REF" GIT_REF)
   fi
   export GIT_REF
   export GRAVITINO_PACKAGE_VERSION="$RELEASE_TAG"
 
   # Gather some user information.
   if [ -z "$ASF_USERNAME" ]; then
-    export ASF_USERNAME=$(read_config "ASF user" "$LOGNAME")
+    export ASF_USERNAME=$(read_config "ASF user" "$LOGNAME" ASF_USERNAME)
   fi
 
   if [ -z "$GIT_NAME" ]; then
     GIT_NAME=$(git config user.name || echo "")
-    export GIT_NAME=$(read_config "Full name" "$GIT_NAME")
+    export GIT_NAME=$(read_config "Full name" "$GIT_NAME" GIT_NAME)
   fi
 
   export GIT_EMAIL="[email protected]"
-  export GPG_KEY=$(read_config "GPG key" "$GIT_EMAIL")
+  export GPG_KEY=$(read_config "GPG key" "$GIT_EMAIL" GPG_KEY)
 
   cat <<EOF
 ================
@@ -188,10 +209,14 @@ E-MAIL:     $GIT_EMAIL
 ================
 EOF
 
-  read -p "Is this info correct [y/n]? " ANSWER
-  if [ "$ANSWER" != "y" ]; then
-    echo "Exiting."
-    exit 1
+  if [ "$FORCE" = "1" ]; then
+    echo "Force mode: proceeding without confirmation."
+  else
+    read -p "Is this info correct [y/n]? " ANSWER
+    if [ "$ANSWER" != "y" ]; then
+      echo "Exiting."
+      exit 1
+    fi
   fi
 
   if ! is_dry_run; then
@@ -226,7 +251,6 @@ function init_java {
   else
       error "javac not found in ${JAVA_HOME}/bin, please ensure you have a JDK 
installed."
   fi
-  JAVA_VERSION=$("${JAVA_HOME}"/bin/javac -version 2>&1 | cut -d " " -f 2)
   export JAVA_VERSION
   echo "Java version is $JAVA_VERSION"
 }

Reply via email to