cloudberry icon indicating copy to clipboard operation
cloudberry copied to clipboard

Ensure to return the right release version

Open tuhaihe opened this issue 10 months ago • 10 comments

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.0devel, which is similar to the way PostgreSQL is using.
  • Generate the new configure file with the new configure.ac
  • Update the getversion file to take the PACKAGE_VERSION as the base version info, and append +dev.<count>.g<sha> whenever possible unless the current commit is exactly on a tag.

After these changes, will return the right info no matter how they get the source code, like git-clone, source tarballs.

For each release, we also need to update the version string to match the right release version manually in each branch.

See: http://github.com/apache/cloudberry/discussions/909

What does this PR do?

Type of Change

  • [ ] Bug fix (non-breaking change)
  • [ ] New feature (non-breaking change)
  • [ ] Breaking change (fix or feature with breaking changes)
  • [ ] Documentation update

Breaking Changes

Test Plan

  • [ ] Unit tests added/updated
  • [ ] Integration tests added/updated
  • [ ] Passed make installcheck
  • [ ] Passed make -C src/test installcheck-cbdb-parallel

Impact

Performance:

User-facing changes:

Dependencies:

Checklist

Additional Context

CI Skip Instructions


tuhaihe avatar Feb 14 '25 10:02 tuhaihe

from the code dbeaver

public class CloudberryDataSource extends GreenplumDataSource {

    private static final Log log = Log.getLog(CloudberryDataSource.class);

    private Version cbVersion;

    public CloudberryDataSource(DBRProgressMonitor monitor, DBPDataSourceContainer container) throws DBException {
        super(monitor, container);
    }

    @Override
    public void initialize(@NotNull DBRProgressMonitor monitor) throws DBException {
        super.initialize(monitor);
        // Read server version
        if (serverVersion != null) {
            Matcher matcher = Pattern.compile("Cloudberry Database ([0-9\\.]+)").matcher(serverVersion);
            if (matcher.find()) {
                cbVersion = new Version(matcher.group(1));
            }
            gpVersion = new Version(7, 0, 0);
        }

        if (cbVersion == null) {
            cbVersion = new Version(1, 0, 0);
        }
    }
}

Cloudberry Database need a version, but not main .

yjhjstz avatar Feb 18 '25 14:02 yjhjstz

Cloudberry Database need a version, but not main .

Agreed. For PG, I found they always use the next release version + devel, like 18devel. It's hard for us to define the next major version, right? One simple way is to set the main branch release as 99.0.0 or 999.0.0?

https://github.com/postgres/postgres/blob/7da344b9f84f0c63590a34136f3fa5d0ab128657/configure.ac#L20

tuhaihe avatar Feb 20 '25 09:02 tuhaihe

This PR is ready for review now. This PR has two big changes:

  • Add the logic to choose the newer version as the final version
  • Adopt the Postgres way, letting the main branch be in the latest version. For each release, need to update the version manually.
    • https://github.com/postgres/postgres/commit/e26810d01d441a457217a6eae9c2989fba29b80f
    • https://github.com/postgres/postgres/commit/6304632eaa2107bb1763d29e213ff166ff6104c0

tuhaihe avatar Mar 27 '25 10:03 tuhaihe

If users build the cloudberry using git clone --depth 1 https://github.com/apache/cloudberry.git, they also will not receive the correct version information prior to this PR.

tuhaihe avatar Apr 01 '25 09:04 tuhaihe

Hey, @edespino thanks for your valuable feedback. I made updates to my PR after considering your suggestions. Please take a look again.

I also did some tests under different environments. The following are the outputs:

  1. Testing via git clone the source code with full commit log:
[gpadmin@cdw cloudberry]$ /usr/local/cloudberry-db/bin/postgres --gp-version
postgres (Apache Cloudberry) 2.0.0devel+dev.1533.gc73181c522 build dev

[gpadmin@cdw cloudberry]$ ./getversion
2.0.0devel+dev.1533.gc73181c522 build dev

[gpadmin@cdw cloudberry]$ psql template1 -c 'SELECT version()'
                                                                                                            version

----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------
 PostgreSQL 14.4 (Apache Cloudberry 2.0.0devel+dev.1533.gc73181c522 build dev) on x86_64-pc-linux-gnu, compiled by gcc (GCC) 11.5.0 20240719 (
Red Hat 11.5.0-5), 64-bit compiled on Apr  6 2025 23:09:03 (with assert checking)
(1 row)
  1. Testing via downloading the source .tar file:
[gpadmin@cdw cloudberry]$ /usr/local/cloudberry-db/bin/postgres --gp-version
postgres (Apache Cloudberry) 2.0.0devel build dev

[gpadmin@cdw cloudberry]$ ./getversion
2.0.0devel build dev

[gpadmin@cdw cloudberry]$ psql template1 -c 'SELECT version()'
                                                                                                  version

----------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------
 PostgreSQL 14.4 (Apache Cloudberry 2.0.0devel build dev) on x86_64-pc-linux-gnu, compiled by gcc (GCC) 11.5.0 20240719 (Red Hat 11.5.0-5), 64
-bit compiled on Apr  6 2025 23:22:50 (with assert checking)
(1 row)
  1. Testing when the current HEAD is on a tag
[gpadmin@cdw cloudberry]$ ./getversion
2.0.0devel+dev.1533.gc73181c522 build dev

[gpadmin@cdw cloudberry]$ git config --global user.email "[email protected]"
[gpadmin@cdw cloudberry]$ git config --global user.name "Dianjin Wang"
[gpadmin@cdw cloudberry]$ git tag -a 2.0.0 c73181c522056878361e3279c3934043fd27a4d9 -m "Test 2.0.0 tag"
[gpadmin@cdw cloudberry]$ ./getversion
2.0.0devel build dev

[gpadmin@cdw cloudberry]$ /usr/local/cloudberry-db/bin/postgres --gp-version
postgres (Apache Cloudberry) 2.0.0devel build dev

[gpadmin@cdw cloudberry]$ psql template1 -c 'SELECT version()'
                                                                                                  version

----------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------
 PostgreSQL 14.4 (Apache Cloudberry 2.0.0devel build dev) on x86_64-pc-linux-gnu, compiled by gcc (GCC) 11.5.0 20240719 (Red Hat 11.5.0-5), 64
-bit compiled on Apr  6 2025 23:35:50 (with assert checking)
(1 row)

tuhaihe avatar Apr 07 '25 06:04 tuhaihe

Hi guys, now this PR is ready for review again. Thanks for your help! @edespino @yjhjstz @avamingli

tuhaihe avatar Apr 10 '25 10:04 tuhaihe

Hey @jiaqizho I use the command autoreconf -i to regenerate the configure file after updating the configure.ac. Some PAX-related options have changed. Could you help take a look to see if the changes are okay?

The changes are in the latest commit:https://github.com/apache/cloudberry/pull/929/commits/25e4e792121e729852e25733ce73e6e2cd761223

tuhaihe avatar Apr 23 '25 10:04 tuhaihe

New testing when the current HEAD is on a tag:


[gpadmin@cdw cloudberry]$ ./getversion
1.6.0+dev.1932.g5d0e2ef730 build dev
[gpadmin@cdw cloudberry]$ git switch tuhaihe/match-release-version
Switched to branch 'tuhaihe/match-release-version'
[gpadmin@cdw cloudberry]$ ./getversion
2.0.0devel+dev.1933.g9e4166e0d6 build dev
[gpadmin@cdw cloudberry]$ git config --global user.email "[email protected]"
[gpadmin@cdw cloudberry]$ git config --global user.name "Dianjin Wang"
[gpadmin@cdw cloudberry]$ git tag -a 2.0.0 9e4166e0d6 -m "Test 2.0.0 tag"
[gpadmin@cdw cloudberry]$ ./getversion
2.0.0 build dev



[gpadmin@cdw cloudberry]$ /usr/local/cloudberry-db/bin/postgres --gp-version
postgres (Apache Cloudberry) 2.0.0 build dev

[gpadmin@cdw cloudberry]$ psql template1 -c 'SELECT version()'
                                                                                               version

-----------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------
 PostgreSQL 14.4 (Apache Cloudberry 2.0.0 build dev) on x86_64-pc-linux-gnu, compiled by gcc (GCC) 11.5.0 20240719 (Red Hat 1
1.5.0-5), 64-bit compiled on Apr 29 2025 21:12:49 (with assert checking)
(1 row)

tuhaihe avatar Apr 30 '25 04:04 tuhaihe

I droped this commit https://github.com/apache/cloudberry/commit/25e4e792121e729852e25733ce73e6e2cd761223 as we will disable the PAX option by default.

tuhaihe avatar Apr 30 '25 04:04 tuhaihe

@tuhaihe Here is my version of getversion. There was an issue if previous annotated tag had a "+" character.

example: git tag -a 2.0.0+RC1 -m "Apache Cloudberry (Incubating) 2.0.0 RC1"

This version of the script handles that case. Please review when you get a chance.

#!/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.1devel+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.1devel+dev.3.gabcd123 build dev
#
#   ./getversion --short
#       → 2.0.1devel+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
pushd "$(dirname "$0")" > /dev/null

# Extract PACKAGE_VERSION from the configure script
VERSION=$(perl -ne 'print $1 if /^PACKAGE_VERSION='\''(.+)'\''$/' < configure)
BUILDNUMBER=dev

# Function to generate a dev suffix like "dev.1.gabcd123"
generate_dev_version() {
    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//-/.}"
}

# 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)
fi

# Handle optional flag
FLAG="${1:-noflag}"
if [ "$FLAG" = "--short" ]; then
    echo "${VERSION}"
else
    if [[ ${BUILDNUMBER} = "dev" && -f BUILD_NUMBER ]]; then
        BUILDNUMBER=$(<BUILD_NUMBER)
    fi
    echo "${VERSION} build ${BUILDNUMBER}"
fi

popd > /dev/null

edespino avatar Apr 30 '25 07:04 edespino

@tuhaihe Here is my version of getversion. There was an issue if previous annotated tag had a "+" character.

example: git tag -a 2.0.0+RC1 -m "Apache Cloudberry (Incubating) 2.0.0 RC1"

This version of the script handles that case. Please review when you get a chance.

Hi @edespino thanks. I tested the different versions' logics, and your new file worked very well. So I replaced the old file with yours and added you as the co-author in the commit.

tuhaihe avatar May 08 '25 08:05 tuhaihe

We can wait for PR #1081 for a few days to see the final result. Then will rebase the configure file.

tuhaihe avatar May 12 '25 09:05 tuhaihe