From a0e65400a9c53bb07e80e2a94f9e083f6982fd95 Mon Sep 17 00:00:00 2001 From: wangshun <96341168+xixi-box@users.noreply.github.com> Date: Mon, 23 Nov 2026 14:12:57 +0800 Subject: [PATCH] fix(java): keep Maven coordinates in sync with release tags (#5151) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #4937 ## Summary The `v0.42.0-beta.21` release commit retained `0.42.0-beta.20` in both Java POMs, so its Maven build produced coordinates for the previous beta. The release bump used a Maven version hook whose final shell commands could return success after Maven failed, allowing the tag to be created with stale coordinates. [Issue #4937](https://github.com/lancedb/lancedb/issues/4937) Declare both Maven version fields in the shared version-bump configuration and align the checked-in POMs with the current release version. Preview and stable release bumps now apply the same version to the parent POM and the core module's parent reference before tagging. Package names, dependencies, and publication destinations are preserved. ## Verification Tests: `/bin/sh -c 'PATH=/tmp/osscout-release-venv/bin:$PATH bash ci/tests/test_bump_version.sh'`. Result: PATH=/tmp/osscout-release-venv/bin:$PATH bash ci/tests/test_bump_version.sh — base exit 1 with the tag/POM mismatch, patched exit 0 with both preview and stable cases passing. Result: python -m unittest discover -s ci/tests -v — base, 35 passed. Result: /tmp/osscout-release-venv/bin/python -m unittest discover -s ci/tests -v — patched, 35 passed. Result: bash ci/tests/test_cli_installer.sh — passed. Result: cd java && ./mvnw --batch-mode test -pl lancedb-core — base, 37 passed on JDK 25. Result: cd java && JAVA_HOME=/usr/lib/jvm/temurin-17-jdk-amd64 ./mvnw --batch-mode -Dspotless.skip=true clean test -pl lancedb-core — patched, 37 passed. Surefire XML reports are in java/lancedb-core/target/surefire-reports/. Result: osscout_base_work=$(mktemp -d) && git archive HEAD java | tar -xf - -C "$osscout_base_work" && cd "$osscout_base_work/java" && JAVA_HOME=/tmp/osscout-jdk8 ./mvnw --batch-mode -DskipTests -Dspotless.skip=true clean deploy -pl lancedb-core -am -P deploy-to-fury -DaltDeploymentRepository=fury::file:///tmp/osscout-fury-base — base build succeeded and emitted stale 0.42.0-beta.20 artifacts for the 0.42.0-beta.21 release sources. Result: cd java && JAVA_HOME=/tmp/osscout-jdk8 ./mvnw --batch-mode -DskipTests -Dspotless.skip=true clean deploy -pl lancedb-core -am -P deploy-to-fury -DaltDeploymentRepository=fury::file:///tmp/osscout-fury-deploy — patched build succeeded and emitted both 0.42.0-beta.21 POMs and the main, sources and Javadoc JARs. Regression coverage: `ci/tests/test_bump_version.sh`. Signed-off-by: wangshun <96341168+xixi-box@users.noreply.github.com> --- .bumpversion.toml | 37 +++++--------- ci/tests/test_bump_version.sh | 91 +++++++++++++++++++++++++++++++++++ java/lancedb-core/pom.xml | 2 +- java/pom.xml | 2 +- 4 files changed, 104 insertions(+), 28 deletions(-) create mode 100644 ci/tests/test_bump_version.sh diff --git a/.bumpversion.toml b/.bumpversion.toml index edb4dbbd4..990a5d968 100644 --- a/.bumpversion.toml +++ b/.bumpversion.toml @@ -23,31 +23,6 @@ allow_dirty = true commit = true message = "Bump version: {current_version} → {new_version}" commit_args = "" -# bump-my-version >=1.4.0 rejects pre_commit_hooks containing shell syntax unless opted in. -allow_shell_hooks = true - -# Java maven files -pre_commit_hooks = [ - """ - NEW_VERSION="${BVHOOK_NEW_MAJOR}.${BVHOOK_NEW_MINOR}.${BVHOOK_NEW_PATCH}" - if [ ! -z "$BVHOOK_NEW_PRE_L" ] && [ ! -z "$BVHOOK_NEW_PRE_N" ]; then - NEW_VERSION="${NEW_VERSION}-${BVHOOK_NEW_PRE_L}.${BVHOOK_NEW_PRE_N}" - fi - echo "Constructed new version: $NEW_VERSION" - cd java && mvn versions:set -DnewVersion=$NEW_VERSION && mvn versions:commit - - # Check for any modified but unstaged pom.xml files - MODIFIED_POMS=$(git ls-files -m | grep pom.xml) - if [ ! -z "$MODIFIED_POMS" ]; then - echo "The following pom.xml files were modified but not staged. Adding them now:" - echo "$MODIFIED_POMS" | while read -r file; do - git add "$file" - echo "Added: $file" - done - fi - """, -] - [tool.bumpversion.parts.pre_l] optional_value = "final" values = ["beta", "final"] @@ -87,7 +62,17 @@ filename = "python/Cargo.toml" replace = "\nversion = \"{new_version}\"" search = "\nversion = \"{current_version}\"" -# Java documentation +# Java Maven coordinates and documentation +[[tool.bumpversion.files]] +filename = "java/pom.xml" +search = "lancedb-parent\n {current_version}" +replace = "lancedb-parent\n {new_version}" + +[[tool.bumpversion.files]] +filename = "java/lancedb-core/pom.xml" +search = "lancedb-parent\n {current_version}" +replace = "lancedb-parent\n {new_version}" + [[tool.bumpversion.files]] filename = "docs/src/java/java.md" replace = "{new_version}" diff --git a/ci/tests/test_bump_version.sh b/ci/tests/test_bump_version.sh new file mode 100644 index 000000000..09f60760e --- /dev/null +++ b/ci/tests/test_bump_version.sh @@ -0,0 +1,91 @@ +#!/usr/bin/env bash +# Run from the repository root with bump-my-version and packaging installed. +set -euo pipefail + +work=$(mktemp -d) +trap 'rm -rf "$work"' EXIT +mkdir -p "$work/repo" "$work/bin" + +# Release tagging must still include Java's versions when Maven cannot update them. +cat > "$work/bin/mvn" <<'MOCK' +#!/bin/sh +echo "Unable to run Maven versions plugin" >&2 +exit 1 +MOCK +chmod +x "$work/bin/mvn" +export PATH="$work/bin:$PATH" + +git ls-files -z .bumpversion.toml ci/bump_version.sh ci/semver_sort.py \ + nodejs/package.json 'nodejs/npm/*/package.json' nodejs/Cargo.toml \ + rust/lancedb/Cargo.toml rust/lancedb/cli/Cargo.toml python/Cargo.toml \ + docs/src/java/java.md java/pom.xml java/lancedb-core/pom.xml | + tar --null -T - -cf - | tar -xf - -C "$work/repo" +cd "$work/repo" + +# The breaking-change check needs GitHub access and runs after the release tag is set. +printf 'pass\n' > ci/check_breaking_changes.py +git init --quiet +git config user.name "Release test" +git config user.email "release-test@example.com" +git add . +git commit --quiet --message "Release baseline" +git tag v0.0.0 + +current_version=$(python -c 'import tomllib; print(tomllib.load(open(".bumpversion.toml", "rb"))["tool"]["bumpversion"]["current_version"])') +git tag "v$current_version" + +# Verify the current baseline before bumping; stale Java POMs must fail. +python - "$current_version" <<'PY' +import sys +import xml.etree.ElementTree as ET + +expected = sys.argv[1] +ns = {"m": "http://maven.apache.org/POM/4.0.0"} +for path, xpath in ( + ("java/pom.xml", "m:version"), + ("java/lancedb-core/pom.xml", "m:parent/m:version"), +): + actual = ET.parse(path).getroot().findtext(xpath, namespaces=ns) + if actual != expected: + raise SystemExit(f"Java baseline mismatch in {path}: expected {expected}, got {actual}") +print(f"Java baseline matches {expected} in both POMs") +PY + +check_java_release() { + local release_type=$1 + local expected_version=$2 + bash ci/bump_version.sh "$release_type" false > "$work/bump.log" 2>&1 || { + cat "$work/bump.log" + return 1 + } + python - "$release_type" "$expected_version" <<'PY' +import subprocess +import sys +import xml.etree.ElementTree as ET + +release_type, expected_version = sys.argv[1:] +case = f"test_java_release_version_matches_tag ({release_type})" +tag = subprocess.check_output(["git", "describe", "--tags", "--exact-match", "HEAD"], text=True).strip() +assert tag == f"v{expected_version}", f"{case}: expected v{expected_version}, got {tag}" +namespace = {"m": "http://maven.apache.org/POM/4.0.0"} +for path, version_path in ( + ("java/pom.xml", "m:version"), + ("java/lancedb-core/pom.xml", "m:parent/m:version"), +): + content = subprocess.check_output(["git", "show", f"{tag}:{path}"]) + version = ET.fromstring(content).findtext(version_path, namespaces=namespace) + assert version == expected_version, f"{case}: {path}: expected {expected_version}, got {version}" +print(f"{case}: passed") +PY +} + +case "$current_version" in + *-beta.*) + preview_version="${current_version%.*}.$((${current_version##*.} + 1))" + ;; + *) + preview_version="${current_version%.*}.$((${current_version##*.} + 1))-beta.0" + ;; +esac +check_java_release preview "$preview_version" +check_java_release stable "${preview_version%-beta.*}" diff --git a/java/lancedb-core/pom.xml b/java/lancedb-core/pom.xml index 0d96439b1..ace9991fb 100644 --- a/java/lancedb-core/pom.xml +++ b/java/lancedb-core/pom.xml @@ -8,7 +8,7 @@ com.lancedb lancedb-parent - 0.42.0-beta.24 + 0.42.0-beta.25 ../pom.xml diff --git a/java/pom.xml b/java/pom.xml index e4c3c0d3d..1f749f87c 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -6,7 +6,7 @@ com.lancedb lancedb-parent - 0.42.0-beta.24 + 0.42.0-beta.25 pom ${project.artifactId} LanceDB Java SDK Parent POM