From bd62f0b26805d54e65b9f38758abe9b2abfc694e Mon Sep 17 00:00:00 2001 From: Tomo Suzuki Date: Wed, 3 Dec 2025 16:51:33 +0000 Subject: [PATCH 1/4] chore: partial release script that uses the main branch --- .github/release/partial_release.py | 18 +++++++++-- generation/apply_current_versions.sh | 26 ---------------- generation/apply_versions.sh | 45 ++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 29 deletions(-) delete mode 100644 generation/apply_current_versions.sh create mode 100755 generation/apply_versions.sh diff --git a/.github/release/partial_release.py b/.github/release/partial_release.py index 3800a164ac9c..b61e851ef4ef 100644 --- a/.github/release/partial_release.py +++ b/.github/release/partial_release.py @@ -24,7 +24,8 @@ class VersionType(Enum): MAJOR = (1,) MINOR = (2,) - PATCH = 3 + PATCH = (3,) + SNAPSHOT = (4,) @click.group(invoke_without_command=False) @@ -49,7 +50,7 @@ def main(ctx): default="patch", type=str, help=""" - The type of version bump, one of major, minor or patch. + The type of version bump, one of major, minor, patch. """, ) @click.option( @@ -61,7 +62,14 @@ def main(ctx): The path to the versions.txt. """, ) + +def bump_snapshot_version(artifact_ids: str, versions: str) -> None: + bump_version(artifact_ids, "snapshot", versions) + def bump_released_version(artifact_ids: str, version_type: str, versions: str) -> None: + bump_version(artifact_ids, version_type, versions) + +def bump_version(artifact_ids: str, version_type: str, versions: str) -> None: target_artifact_ids = set(artifact_ids.split(",")) version_enum = _parse_type_or_raise(version_type) newlines = [] @@ -88,6 +96,7 @@ def bump_released_version(artifact_ids: str, version_type: str, versions: str) - major, minor, patch = [ int(ver_num) for ver_num in released_version.split(".") ] + suffix="" match version_enum: case VersionType.MAJOR: major += 1 @@ -95,8 +104,11 @@ def bump_released_version(artifact_ids: str, version_type: str, versions: str) - minor += 1 case VersionType.PATCH: patch += 1 + case VersionType.SNAPSHOT: + minor += 1 + suffix = "-SNAPSHOT" newlines.append( - f"{artifact_id}:{major}.{minor}.{patch}:{major}.{minor}.{patch}" + f"{artifact_id}:{major}.{minor}.{patch}{suffix}:{major}.{minor}.{patch}{suffix}" ) with open(versions, "w") as versions_file: versions_file.writelines("\n".join(newlines)) diff --git a/generation/apply_current_versions.sh b/generation/apply_current_versions.sh deleted file mode 100644 index 7c87a8f60a14..000000000000 --- a/generation/apply_current_versions.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -# This script sets the "current-version" written in versions.txt applied to all -# pom.xml files in this monorepo. -# This script plays supplemental role just in case Release Please pull request -# fails to update all files. - -# Usage: -# # Run this script at the root of the monorepo -# bash generation/apply_current_versions.sh - -set -e - -SED_OPTIONS="" -for versions_file in $(find . -mindepth 0 -maxdepth 2 -name versions.txt \ - |sort --dictionary-order); do - for KV in $(cut -f1,3 -d: $versions_file |grep -v "#"); do - K=${KV%:*}; V=${KV#*:} - echo Key:$K, Value:$V; - SED_OPTIONS="$SED_OPTIONS -e /x-version-update:$K:current/{s|.*<\/version>|$V<\/version>|;}" - done -done - -echo "Running sed command. It may take few minutes." -find . -maxdepth 3 -name pom.xml |sort --dictionary-order |xargs sed -i.bak $SED_OPTIONS -find . -maxdepth 3 -name pom.xml.bak |xargs rm diff --git a/generation/apply_versions.sh b/generation/apply_versions.sh new file mode 100755 index 000000000000..99d1ab3a3109 --- /dev/null +++ b/generation/apply_versions.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +# This script sets the "current-version" written in versions.txt applied to all +# pom.xml files in this monorepo. +# This script plays supplemental role just in case Release Please pull request +# fails to update all files. + +# Usage: +# # Run this script at the root of the monorepo +# bash generation/apply_current_versions.sh + +set -e + +versions_file=$1 +column_name=$2 +if [[ -z "$versions_file" || -z "$column_name" ]]; then + echo "Replaces the versions annotated with the x-version-update tag in" + echo "all pom.xml files in the current working directory and its subdirectories" + echo "with the versions specified in the versions.txt file (current or released)." + echo + echo "Usage: $0 path/to/versions.txt (released|current)" + exit 1 +fi +if [[ "$column_name" == "released" ]]; then + column_index=2 +elif [[ "$column_name" == "current" ]]; then + column_index=3 +elif "$column_name" != "current" ]]; then + echo "Error: column_name must be either 'released' or 'current'" + exit 1 +fi + + +SED_OPTIONS="" + +# The second column is +for KV in $(cut -f1,"${column_index}" -d: $versions_file |grep -v "#"); do + K=${KV%:*}; V=${KV#*:} + echo Key:$K, Value:$V; + SED_OPTIONS="$SED_OPTIONS -e /x-version-update:$K:current/{s|.*<\/version>|$V<\/version>|;}" +done + +echo "Running sed command. It may take few minutes." +find . -maxdepth 3 -name pom.xml |sort --dictionary-order |xargs sed -i.bak $SED_OPTIONS +find . -maxdepth 3 -name pom.xml.bak |xargs rm From 72a3a0e3206dfe2b7a9a07a02c3afabb1da7f131 Mon Sep 17 00:00:00 2001 From: Tomo Suzuki Date: Wed, 3 Dec 2025 18:02:56 +0000 Subject: [PATCH 2/4] chore: partial_release to handle SNAPSHOT version --- .github/release/partial_release.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/release/partial_release.py b/.github/release/partial_release.py index b61e851ef4ef..46a7f341cedd 100644 --- a/.github/release/partial_release.py +++ b/.github/release/partial_release.py @@ -63,7 +63,8 @@ def main(ctx): """, ) -def bump_snapshot_version(artifact_ids: str, versions: str) -> None: +def bump_snapshot_version(artifact_ids: str, version_type: str, versions: str) -> None: + # version_type is ignored for snapshot version bumping. bump_version(artifact_ids, "snapshot", versions) def bump_released_version(artifact_ids: str, version_type: str, versions: str) -> None: @@ -96,7 +97,6 @@ def bump_version(artifact_ids: str, version_type: str, versions: str) -> None: major, minor, patch = [ int(ver_num) for ver_num in released_version.split(".") ] - suffix="" match version_enum: case VersionType.MAJOR: major += 1 @@ -105,10 +105,13 @@ def bump_version(artifact_ids: str, version_type: str, versions: str) -> None: case VersionType.PATCH: patch += 1 case VersionType.SNAPSHOT: - minor += 1 - suffix = "-SNAPSHOT" + # Keep the released version as is. + newlines.append( + f"{artifact_id}:{major}.{minor}.{patch}:{major}.{minor + 1}.0-SNAPSHOT" + ) + continue newlines.append( - f"{artifact_id}:{major}.{minor}.{patch}{suffix}:{major}.{minor}.{patch}{suffix}" + f"{artifact_id}:{major}.{minor}.{patch}:{major}.{minor}.{patch}" ) with open(versions, "w") as versions_file: versions_file.writelines("\n".join(newlines)) From f5ca03dfb79d86d38608ec81c4c20d7655d4a3f7 Mon Sep 17 00:00:00 2001 From: Tomo Suzuki Date: Wed, 3 Dec 2025 18:23:17 +0000 Subject: [PATCH 3/4] fixed annotations --- .github/release/partial_release.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/.github/release/partial_release.py b/.github/release/partial_release.py index 46a7f341cedd..b1f4723ca7f1 100644 --- a/.github/release/partial_release.py +++ b/.github/release/partial_release.py @@ -35,6 +35,27 @@ def main(ctx): pass +@main.command() +@click.option( + "--artifact-ids", + required=True, + type=str, + help=""" + Artifact IDs whose version needs to update, separated by comma. + """, +) +@click.option( + "--versions", + required=False, + default="./versions.txt", + type=str, + help=""" + The path to the versions.txt. + """, +) +def bump_snapshot_version(artifact_ids: str, versions: str) -> None: + bump_version(artifact_ids, "snapshot", versions) + @main.command() @click.option( "--artifact-ids", @@ -62,11 +83,6 @@ def main(ctx): The path to the versions.txt. """, ) - -def bump_snapshot_version(artifact_ids: str, version_type: str, versions: str) -> None: - # version_type is ignored for snapshot version bumping. - bump_version(artifact_ids, "snapshot", versions) - def bump_released_version(artifact_ids: str, version_type: str, versions: str) -> None: bump_version(artifact_ids, version_type, versions) From 93bdf0bd6936a9c291050d01dccefc383c43d566 Mon Sep 17 00:00:00 2001 From: Tomo Suzuki Date: Fri, 5 Dec 2025 16:29:48 +0000 Subject: [PATCH 4/4] adding a unit test --- .../fixture/snapshot/versions-snapshot.txt | 1 + .github/release/release_unit_tests.py | 18 +++++++++++++++++- .../snapshot/versions-snapshot-golden.txt | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 .github/release/fixture/snapshot/versions-snapshot.txt create mode 100644 .github/release/testdata/snapshot/versions-snapshot-golden.txt diff --git a/.github/release/fixture/snapshot/versions-snapshot.txt b/.github/release/fixture/snapshot/versions-snapshot.txt new file mode 100644 index 000000000000..f34ed1cac069 --- /dev/null +++ b/.github/release/fixture/snapshot/versions-snapshot.txt @@ -0,0 +1 @@ +google-cloud-asset:1.2.3:1.2.3 diff --git a/.github/release/release_unit_tests.py b/.github/release/release_unit_tests.py index e46192a6c2dd..5cac7dc6dfdd 100644 --- a/.github/release/release_unit_tests.py +++ b/.github/release/release_unit_tests.py @@ -4,7 +4,7 @@ import shutil import tempfile import unittest -from partial_release import bump_released_version +from partial_release import bump_released_version, bump_snapshot_version SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) GOLDEN = os.path.join(SCRIPT_DIR, "testdata") @@ -45,6 +45,22 @@ def test_bump_multiple_versions_success(self): actual = f.read() self.assertEqual(expected, actual) + def test_bump_snapshot_version_success(self): + golden = f"{GOLDEN}/snapshot/versions-snapshot-golden.txt" + with copied_fixtures_dir(f"{FIXTURES}/snapshot"): + runner.invoke( + bump_snapshot_version, + [ + "--artifact-ids=google-cloud-asset", + "--versions=versions-snapshot.txt", + ], + ) + with open(golden) as g: + expected = g.read() + with open("./versions-snapshot.txt") as f: + actual = f.read() + self.assertEqual(expected, actual) + @contextlib.contextmanager def change_dir_to(path: str) -> str: diff --git a/.github/release/testdata/snapshot/versions-snapshot-golden.txt b/.github/release/testdata/snapshot/versions-snapshot-golden.txt new file mode 100644 index 000000000000..db7e117dfa73 --- /dev/null +++ b/.github/release/testdata/snapshot/versions-snapshot-golden.txt @@ -0,0 +1 @@ +google-cloud-asset:1.2.3:1.3.0-SNAPSHOT \ No newline at end of file