diff --git a/.bumpversion.toml b/.bumpversion.toml index 2f11c5688..11dc0b6ad 100644 --- a/.bumpversion.toml +++ b/.bumpversion.toml @@ -29,10 +29,7 @@ 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 + NEW_VERSION="$BVHOOK_NEW_VERSION" echo "Constructed new version: $NEW_VERSION" cd java && mvn versions:set -DnewVersion=$NEW_VERSION && mvn versions:commit diff --git a/.github/workflows/ci-scripts.yml b/.github/workflows/ci-scripts.yml index 9b9124ab2..e814279b7 100644 --- a/.github/workflows/ci-scripts.yml +++ b/.github/workflows/ci-scripts.yml @@ -5,11 +5,13 @@ on: branches: - main paths: + - .bumpversion.toml - ci/set_lance_version.py - ci/tests/** - .github/workflows/ci-scripts.yml pull_request: paths: + - .bumpversion.toml - ci/set_lance_version.py - ci/tests/** - .github/workflows/ci-scripts.yml @@ -26,5 +28,7 @@ jobs: - uses: actions/setup-python@v6 with: python-version: "3.13" + - name: Install release tooling + run: pip install bump-my-version - name: Run tests run: python -m unittest discover -s ci/tests -v diff --git a/.github/workflows/java-publish.yml b/.github/workflows/java-publish.yml index 094aa552a..777f83a7d 100644 --- a/.github/workflows/java-publish.yml +++ b/.github/workflows/java-publish.yml @@ -12,6 +12,13 @@ name: Build and publish Java packages on: + workflow_dispatch: + inputs: + dry_run: + description: Build without publishing to Maven Central + type: boolean + default: true + required: true push: tags: - "v*" @@ -48,12 +55,25 @@ jobs: run: | git config --global user.email "dev+gha@lancedb.com" git config --global user.name "LanceDB Github Runner" + - name: Validate package version + run: | + python - <<'PYTHON' + import tomllib + import xml.etree.ElementTree as ET + from pathlib import Path + + expected = tomllib.loads(Path("../.bumpversion.toml").read_text())["tool"]["bumpversion"]["current_version"] + actual = ET.parse("pom.xml").findtext("{http://maven.apache.org/POM/4.0.0}version") + if actual != expected: + raise ValueError(f"Maven version {actual} differs from release version {expected}") + print(f"Validated Maven version {actual}") + PYTHON - name: Dry run - if: github.event_name == 'pull_request' + if: github.event_name == 'pull_request' || (github.event_name == 'workflow_dispatch' && inputs.dry_run) run: | ./mvnw --batch-mode -DskipTests package -pl lancedb-core -am - name: Publish - if: startsWith(github.ref, 'refs/tags/v') + if: startsWith(github.ref, 'refs/tags/v') || (github.event_name == 'workflow_dispatch' && !inputs.dry_run) run: | echo "use-agent" >> ~/.gnupg/gpg.conf echo "pinentry-mode loopback" >> ~/.gnupg/gpg.conf @@ -68,7 +88,7 @@ jobs: name: Report Workflow Failure runs-on: ubuntu-latest needs: [publish] - if: always() && failure() && startsWith(github.ref, 'refs/tags/v') + if: always() && failure() && (startsWith(github.ref, 'refs/tags/v') || (github.event_name == 'workflow_dispatch' && !inputs.dry_run)) permissions: contents: read issues: write diff --git a/ci/tests/test_release_version.py b/ci/tests/test_release_version.py new file mode 100644 index 000000000..c184887d4 --- /dev/null +++ b/ci/tests/test_release_version.py @@ -0,0 +1,79 @@ +# SPDX-License-Identifier: Apache-2.0 +# SPDX-FileCopyrightText: Copyright The LanceDB Authors + +import os +import re +import subprocess +import tempfile +import unittest +from pathlib import Path + + +REPO_ROOT = Path(__file__).resolve().parents[2] + + +class ReleaseVersionTests(unittest.TestCase): + def check_bump(self, part, expected): + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + config = (REPO_ROOT / ".bumpversion.toml").read_text() + config = config.split("[[tool.bumpversion.files]]", 1)[0] + config = re.sub( + r'^current_version = ".*"$', + 'current_version = "0.40.0-beta.12"', + config, + flags=re.MULTILINE, + ) + config += '\n[[tool.bumpversion.files]]\nfilename = "version.txt"\n' + (root / ".bumpversion.toml").write_text(config) + (root / "version.txt").write_text("0.40.0-beta.12\n") + (root / "java").mkdir() + (root / "java" / "pom.xml").write_text("0.40.0-beta.12\n") + (root / "bin").mkdir() + maven = root / "bin" / "mvn" + # Record the effective Maven version while exercising the real + # bump-my-version parser, serialization, hook environment, and git hook. + maven.write_text( + '#!/bin/sh\nfor arg in "$@"; do\n' + ' case "$arg" in\n' + ' -DnewVersion=*) printf "%s\\n" "${arg#-DnewVersion=}" > pom.xml;;\n' + " esac\ndone\n" + ) + maven.chmod(0o755) + env = dict( + os.environ, PATH=f"{root / 'bin'}{os.pathsep}{os.environ['PATH']}" + ) + + def run(*args): + return subprocess.run( + args, + cwd=root, + env=env, + text=True, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + check=True, + ) + + run("git", "init", "-q") + run("git", "config", "user.name", "Release Test") + run("git", "config", "user.email", "release-test@example.invalid") + run("git", "config", "commit.gpgsign", "false") + run("git", "add", ".") + run("git", "commit", "-qm", "Initial version") + run("bump-my-version", "bump", part) + self.assertEqual((root / "version.txt").read_text().strip(), expected) + self.assertEqual((root / "java" / "pom.xml").read_text().strip(), expected) + self.assertEqual( + run("git", "describe", "--exact-match").stdout.strip(), f"v{expected}" + ) + + def test_stable_maven_version_matches_release(self): + self.check_bump("pre_l", "0.40.0") + + def test_preview_maven_version_matches_release(self): + self.check_bump("pre_n", "0.40.0-beta.13") + + +if __name__ == "__main__": + unittest.main() diff --git a/java/lancedb-core/pom.xml b/java/lancedb-core/pom.xml index 4a143b027..b60f61f52 100644 --- a/java/lancedb-core/pom.xml +++ b/java/lancedb-core/pom.xml @@ -8,7 +8,7 @@ com.lancedb lancedb-parent - 0.40.0-final.0 + 0.40.0 ../pom.xml diff --git a/java/pom.xml b/java/pom.xml index 9ecac71e0..0683e5ec8 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -6,7 +6,7 @@ com.lancedb lancedb-parent - 0.40.0-final.0 + 0.40.0 pom ${project.artifactId} LanceDB Java SDK Parent POM