Skip to content

Commit 43fade5

Browse files
committed
chore: partial release script to handle sdk-platform-java
1 parent 3c5fb14 commit 43fade5

File tree

2 files changed

+83
-14
lines changed

2 files changed

+83
-14
lines changed

.github/release/partial_release.py

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,20 @@ def main(ctx):
3838
@main.command()
3939
@click.option(
4040
"--artifact-ids",
41-
required=True,
41+
required=False,
4242
type=str,
4343
help="""
4444
Artifact IDs whose version needs to update, separated by comma.
4545
""",
4646
)
47+
@click.option(
48+
"--sdk-platform-java",
49+
is_flag=True,
50+
default=False,
51+
help="""
52+
If set, bump versions for all modules in sdk-platform-java.
53+
""",
54+
)
4755
@click.option(
4856
"--versions",
4957
required=False,
@@ -53,18 +61,29 @@ def main(ctx):
5361
The path to the versions.txt.
5462
""",
5563
)
56-
def bump_snapshot_version(artifact_ids: str, versions: str) -> None:
64+
def bump_snapshot_version(artifact_ids: str, sdk_platform_java: bool, versions: str) -> None:
65+
if sdk_platform_java:
66+
artifact_ids = _get_sdk_platform_java_artifacts(artifact_ids)
5767
bump_version(artifact_ids, "snapshot", versions)
5868

69+
5970
@main.command()
6071
@click.option(
6172
"--artifact-ids",
62-
required=True,
73+
required=False,
6374
type=str,
6475
help="""
6576
Artifact IDs whose version needs to update, separated by comma.
6677
""",
6778
)
79+
@click.option(
80+
"--sdk-platform-java",
81+
is_flag=True,
82+
default=False,
83+
help="""
84+
If set, bump versions for all modules in sdk-platform-java.
85+
""",
86+
)
6887
@click.option(
6988
"--version-type",
7089
required=False,
@@ -83,9 +102,45 @@ def bump_snapshot_version(artifact_ids: str, versions: str) -> None:
83102
The path to the versions.txt.
84103
""",
85104
)
86-
def bump_released_version(artifact_ids: str, version_type: str, versions: str) -> None:
105+
def bump_released_version(
106+
artifact_ids: str, sdk_platform_java: bool, version_type: str, versions: str
107+
) -> None:
108+
if sdk_platform_java:
109+
artifact_ids = _get_sdk_platform_java_artifacts(artifact_ids)
87110
bump_version(artifact_ids, version_type, versions)
88111

112+
113+
def _get_sdk_platform_java_artifacts(artifact_ids: str) -> str:
114+
sdk_artifacts = [
115+
"gapic-generator-java",
116+
"api-common",
117+
"gax",
118+
"gax-grpc",
119+
"gax-httpjson",
120+
"proto-google-common-protos",
121+
"grpc-google-common-protos",
122+
"proto-google-iam-v1",
123+
"grpc-google-iam-v1",
124+
"proto-google-iam-v2beta",
125+
"grpc-google-iam-v2beta",
126+
"proto-google-iam-v2",
127+
"grpc-google-iam-v2",
128+
"proto-google-iam-v3",
129+
"grpc-google-iam-v3",
130+
"proto-google-iam-v3beta",
131+
"grpc-google-iam-v3beta",
132+
"google-cloud-core",
133+
"google-cloud-shared-dependencies",
134+
"google-iam-policy",
135+
"gapic-showcase",
136+
"proto-gapic-showcase-v1beta1",
137+
"grpc-gapic-showcase-v1beta1",
138+
]
139+
if artifact_ids:
140+
return ",".join(sdk_artifacts + artifact_ids.split(","))
141+
return ",".join(sdk_artifacts)
142+
143+
89144
def bump_version(artifact_ids: str, version_type: str, versions: str) -> None:
90145
target_artifact_ids = set(artifact_ids.split(","))
91146
version_enum = _parse_type_or_raise(version_type)
@@ -130,7 +185,8 @@ def bump_version(artifact_ids: str, version_type: str, versions: str) -> None:
130185
f"{artifact_id}:{major}.{minor}.{patch}:{major}.{minor}.{patch}"
131186
)
132187
with open(versions, "w") as versions_file:
133-
versions_file.writelines("\n".join(newlines))
188+
for line in newlines:
189+
versions_file.write(f"{line}\n")
134190

135191

136192
def _parse_type_or_raise(version_type: str) -> VersionType:

generation/apply_versions.sh

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,38 @@ if [[ -z "$versions_file" || -z "$column_name" ]]; then
2121
echo "Usage: $0 path/to/versions.txt (released|current)"
2222
exit 1
2323
fi
24-
if [[ "$column_name" == "released" ]]; then
24+
if [[ "$column_name" == "released" ]]; then
2525
column_index=2
2626
elif [[ "$column_name" == "current" ]]; then
2727
column_index=3
28-
elif "$column_name" != "current" ]]; then
28+
else
2929
echo "Error: column_name must be either 'released' or 'current'"
3030
exit 1
3131
fi
3232

33+
SED_SCRIPT=$(mktemp)
34+
trap "rm -f $SED_SCRIPT" EXIT
3335

34-
SED_OPTIONS=""
35-
36-
# The second column is
3736
for KV in $(cut -f1,"${column_index}" -d: $versions_file |grep -v "#"); do
3837
K=${KV%:*}; V=${KV#*:}
39-
echo Key:$K, Value:$V;
40-
SED_OPTIONS="$SED_OPTIONS -e /x-version-update:$K:current/{s|<version>.*<\/version>|<version>$V<\/version>|;}"
38+
echo "Key:$K, Value:$V";
39+
# Pattern 1: XML <version> tags and property tags (e.g., <google-cloud-shared-dependencies.version>)
40+
echo "/x-version-update:$K:\(current\|released\)/{s|>\([^<]*\)<|>$V<|;}" >> "$SED_SCRIPT"
41+
# Pattern 2: YAML _VERSION: '...' or "..."
42+
echo "/x-version-update:$K:\(current\|released\)/{s|: [\'\"][^\'\"]*[\'\"]|: \'$V\'|;}" >> "$SED_SCRIPT"
43+
# Pattern 3: Java static final String VERSION = "..."
44+
echo "/x-version-update-start:$K:\(current\|released\)/{n;s|\".*\"|\"$V\"|;}" >> "$SED_SCRIPT"
4145
done
4246

47+
4348
echo "Running sed command. It may take few minutes."
44-
find . -maxdepth 3 -name pom.xml |sort --dictionary-order |xargs sed -i.bak $SED_OPTIONS
45-
find . -maxdepth 3 -name pom.xml.bak |xargs rm
49+
# Including pom.xml, *.yaml, and Version.java files.
50+
FILES=$(find . \( -name pom.xml -o -name "*.yaml" -o -name "Version.java" \) | sort --dictionary-order)
51+
TOTAL_FILES=$(echo "$FILES" | grep -c .)
52+
CURRENT_FILE=0
53+
while read -r FILE; do
54+
CURRENT_FILE=$((CURRENT_FILE + 1))
55+
echo -ne "Progress: $CURRENT_FILE/$TOTAL_FILES ($((CURRENT_FILE * 100 / TOTAL_FILES))%)\r"
56+
sed -i -f "$SED_SCRIPT" "$FILE"
57+
done <<< "$FILES"
58+
echo

0 commit comments

Comments
 (0)