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

djwang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git


The following commit(s) were added to refs/heads/main by this push:
     new 94a81765e6 Update the version generation logic and info
94a81765e6 is described below

commit 94a81765e655be331de32d496a48fa461fba1108
Author: Dianjin Wang <[email protected]>
AuthorDate: Thu Apr 10 16:11:40 2025 +0800

    Update the version generation logic and info
    
    Fow now, if we build Cloudberry from a source zip file (not using git
    clone), the version information displayed is not matched the right info,
    always return 1.0.0 like this:
    
    ```
       PostgreSQL 14.4 (Apache Cloudberry 1.0.0 build dev)
    ```
    
    In this PR, these changes are made:
    
    - Update the PACKAGE_VERSION string from 1.0.0 to 2.0.0-devel
    - Generate the new configure file with the new configure.ac
    - Rewrite the `getversion` with a new logic to meet a various version
      demands for packaging and diagnostics, see the details in the
      `getversion` file.
    
    Co-authored-by: Ed Espino <[email protected]>
---
 configure                       |  18 +++---
 configure.ac                    |   2 +-
 getversion                      | 129 +++++++++++++++++++++++++++++++---------
 gpMgmt/bin/gppylib/gpversion.py |   2 +-
 4 files changed, 112 insertions(+), 39 deletions(-)

diff --git a/configure b/configure
index deb1a0e782..1708007ee1 100755
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.69 for Apache Cloudberry 1.0.0.
+# Generated by GNU Autoconf 2.69 for Apache Cloudberry 2.0.0-devel.
 #
 # Report bugs to <[email protected]>.
 #
@@ -582,8 +582,8 @@ MAKEFLAGS=
 # Identity of this package.
 PACKAGE_NAME='Apache Cloudberry'
 PACKAGE_TARNAME='apache-cloudberry'
-PACKAGE_VERSION='1.0.0'
-PACKAGE_STRING='Apache Cloudberry 1.0.0'
+PACKAGE_VERSION='2.0.0-devel'
+PACKAGE_STRING='Apache Cloudberry 2.0.0-devel'
 PACKAGE_BUGREPORT='[email protected]'
 PACKAGE_URL='https://cloudberry.apache.org/'
 
@@ -1513,7 +1513,7 @@ if test "$ac_init_help" = "long"; then
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-\`configure' configures Apache Cloudberry 1.0.0 to adapt to many kinds of 
systems.
+\`configure' configures Apache Cloudberry 2.0.0-devel to adapt to many kinds 
of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1579,7 +1579,7 @@ fi
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of Apache Cloudberry 1.0.0:";;
+     short | recursive ) echo "Configuration of Apache Cloudberry 
2.0.0-devel:";;
    esac
   cat <<\_ACEOF
 
@@ -1782,7 +1782,7 @@ fi
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-Apache Cloudberry configure 1.0.0
+Apache Cloudberry configure 2.0.0-devel
 generated by GNU Autoconf 2.69
 
 Copyright (C) 2012 Free Software Foundation, Inc.
@@ -2535,7 +2535,7 @@ cat >config.log <<_ACEOF
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by Apache Cloudberry $as_me 1.0.0, which was
+It was created by Apache Cloudberry $as_me 2.0.0-devel, which was
 generated by GNU Autoconf 2.69.  Invocation command line was
 
   $ $0 $@
@@ -23334,7 +23334,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
-This file was extended by Apache Cloudberry $as_me 1.0.0, which was
+This file was extended by Apache Cloudberry $as_me 2.0.0-devel, which was
 generated by GNU Autoconf 2.69.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -23405,7 +23405,7 @@ _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; 
s/[\\""\`\$]/\\\\&/g'`"
 ac_cs_version="\\
-Apache Cloudberry config.status 1.0.0
+Apache Cloudberry config.status 2.0.0-devel
 configured by $0, generated by GNU Autoconf 2.69,
   with options \\"\$ac_cs_config\\"
 
diff --git a/configure.ac b/configure.ac
index 500a20ae15..cd459973d3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -20,7 +20,7 @@ m4_pattern_forbid(^PGAC_)dnl to catch undefined macros
 dnl The PACKAGE_VERSION from upstream PostgreSQL is maintained in the
 dnl PG_PACKAGE_VERSION variable, when merging make sure to update this
 dnl variable with the merge conflict from the AC_INIT() statement.
-AC_INIT([Apache Cloudberry], [1.0.0], [[email protected]], [], 
[https://cloudberry.apache.org/])
+AC_INIT([Apache Cloudberry], [2.0.0-devel], [[email protected]], [], 
[https://cloudberry.apache.org/])
 [PG_PACKAGE_VERSION=14.4]
 AC_SUBST(PG_PACKAGE_VERSION)
 
diff --git a/getversion b/getversion
index 7d3d71691f..9f100bd7f0 100755
--- a/getversion
+++ b/getversion
@@ -1,46 +1,119 @@
 #!/usr/bin/env bash
+# ======================================================================
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# -----------------------------------------------------------------------------
+# getversion — determine the project version for packaging and diagnostics
+# -----------------------------------------------------------------------------
+#
+# This script computes a version string using the following logic:
+#
+#   1. Extract the base PACKAGE_VERSION from the `configure` script.
+#
+#   2. If running inside a Git repository and `git describe` is usable:
+#
+#      a. If the current commit matches an annotated tag exactly:
+#           VERSION = <tag>
+#         e.g.,     VERSION = 2.0.0+RC1
+#
+#      b. If the current commit is ahead of a tag:
+#           VERSION = <PACKAGE_VERSION>+dev.<N>.g<commit>
+#         e.g.,     VERSION = 2.0.1-devel+dev.3.gabcd123
+#
+#   3. If *not* in a Git repo but a `VERSION` file exists:
+#         VERSION and BUILDNUMBER are read from that file (format: "<version> 
build <build_number>")
+#
+#   4. If neither a Git repo nor a VERSION file is present:
+#         VERSION = <PACKAGE_VERSION> from configure
+#         BUILDNUMBER = dev
+#
+#   5. If a BUILD_NUMBER file is present and BUILDNUMBER is "dev", it will 
override the default:
+#         BUILDNUMBER = $(cat BUILD_NUMBER)
+#
+# Output:
+#   - Default: <version> build <build_number>
+#   - With --short: just <version>
+#
+# Examples:
+#   ./getversion
+#       → 2.0.1-devel+dev.3.gabcd123 build dev
+#
+#   ./getversion --short
+#       → 2.0.1-devel+dev.3.gabcd123
+#
+#   (On exact tag)
+#       → 2.0.0+RC1 build dev
+#
+# Supported Features:
+#   - Handles annotated tags with special characters like `+` or `-`
+#   - Produces semver-compatible version strings for CI/CD
+#   - Works with or without Git
+#
+# Intended for use in:
+#   - Release packaging
+#   - Diagnostic reporting
+#   - Embedding traceable version info into builds
+#
+# ======================================================================
 
-# Make sure we're running from the root git repository, not whatever submodule
-# we could have been called from.
-pushd $(dirname "$0") > /dev/null
+# Make sure we're running from the root git repository
+pushd "$(dirname "$0")" > /dev/null
 
-VERSION=$(perl -e 'while(<>){print $1 if (/^PACKAGE_VERSION='\''(.+)'\''$/)}' 
< configure)
+# Extract PACKAGE_VERSION from the configure script
+VERSION=$(perl -ne 'print $1 if /^PACKAGE_VERSION='\''(.+)'\''$/' < configure)
 BUILDNUMBER=dev
 
-# Call git describe, and convert it to a semi-semantic version, like
-# 5.0.0-alpha.0+dev.52.g123abc
+# Function to generate a dev suffix like "dev.1.gabcd123"
 generate_dev_version() {
-    git describe | perl -pe 's/(.*)-([0-9]*)-(g[0-9a-f]*)/\1+dev.\2.\3/'
+    local latest_tag
+    latest_tag=$(git describe --tags --abbrev=0)
+    local full_desc
+    full_desc=$(git describe --tags --long)
+    local suffix="${full_desc#$latest_tag-}"
+    echo "dev.${suffix//-/.}"
 }
 
-# If we are in a Git repository and have git installed, build the version
-# string using the latest tag in case it's reachable
-if type git >/dev/null 2>&1 && [ -d '.git' ] ; then
-
-       # Check for tag reachability, in case of shallow clones we might not
-       # be able to use git describe since the commit which was tagged is
-       # unreachable even if we have pulled the tags. If we can reach it,
-       # overwrite the VERSION from autoconf with the output, else append
-       # HEAD commit info
-       if git describe >/dev/null 2>&1 ; then
-               VERSION=$(generate_dev_version)
-       else
-               VERSION+=+
-               VERSION+=$(git rev-parse --short HEAD)
-       fi
-# If not a git repository and VERSION file exists, use version string from 
file.
+# Check if we're in a Git repo and git is available
+if type git >/dev/null 2>&1 && [ -d '.git' ]; then
+    # Ensure git describe doesn't fail due to shallow clone
+    if git describe --tags --long >/dev/null 2>&1; then
+        if git describe --exact-match >/dev/null 2>&1; then
+            # We're exactly on a tag
+            VERSION=$(git describe --exact-match)
+        else
+            # Not on a tag: add dev version suffix
+            VERSION+="+$(generate_dev_version)"
+        fi
+    fi
+# Not a git repo but VERSION file exists
 elif [[ -s ./VERSION ]]; then
-       VERSION=$(awk -F' build ' '{print $1}' ./VERSION)
-       BUILDNUMBER=$(awk -F' build ' '{print $2}' ./VERSION)
+    VERSION=$(awk -F' build ' '{print $1}' ./VERSION)
+    BUILDNUMBER=$(awk -F' build ' '{print $2}' ./VERSION)
 fi
 
+# Handle optional flag
 FLAG="${1:-noflag}"
-if [ "$FLAG" = '--short' ] ; then
+if [ "$FLAG" = "--short" ]; then
     echo "${VERSION}"
 else
-    if [[ ${BUILDNUMBER} = 'dev' && -f BUILD_NUMBER ]] ; then
-        BUILDNUMBER=`cat BUILD_NUMBER`
+    if [[ ${BUILDNUMBER} = "dev" && -f BUILD_NUMBER ]]; then
+        BUILDNUMBER=$(<BUILD_NUMBER)
     fi
     echo "${VERSION} build ${BUILDNUMBER}"
 fi
+
 popd > /dev/null
diff --git a/gpMgmt/bin/gppylib/gpversion.py b/gpMgmt/bin/gppylib/gpversion.py
index a30aef28e3..0e639a8d76 100644
--- a/gpMgmt/bin/gppylib/gpversion.py
+++ b/gpMgmt/bin/gppylib/gpversion.py
@@ -18,7 +18,7 @@ if sys.version_info < (3, 5, 0):
                      % os.path.split(__file__)[-1])
     sys.exit(1)
 
-MAIN_VERSION = [1,99]    # version number for main
+MAIN_VERSION = [2,99]    # version number for main
 
 
 #============================================================


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to