Skip to content

Commit 05df6bd

Browse files
authored
chore: partial release script (#11806)
partial_release.py to take "bump-snapshot-version" as argument. These script created a change in #11804. - apply_current_version.sh is renamed to apply_version.sh and it now takes the path to versions.txt file and "current|released" option. ## To create release versions of the modules ``` ~/google-cloud-java$ python3 .github/release/partial_release.py bump-released-version --artifact-ids=google-cloud-java,google-cloud-asset --version-type=patch ~/google-cloud-java$ cd java-asset ~/google-cloud-java/java-asset$ ../generation/apply_versions.sh ../versions.txt released ``` ## To create SNAPSHOT versions for the released modules ``` ~/google-cloud-java$ python3 .github/release/partial_release.py bump-snapshot-version --artifact-ids=google-cloud-java,google-cloud-asset ~/google-cloud-java$ ./generation/apply_versions.sh ./versions.txt current ```
1 parent 4acc65f commit 05df6bd

File tree

6 files changed

+97
-29
lines changed

6 files changed

+97
-29
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
google-cloud-asset:1.2.3:1.2.3

.github/release/partial_release.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
class VersionType(Enum):
2525
MAJOR = (1,)
2626
MINOR = (2,)
27-
PATCH = 3
27+
PATCH = (3,)
28+
SNAPSHOT = (4,)
2829

2930

3031
@click.group(invoke_without_command=False)
@@ -34,6 +35,27 @@ def main(ctx):
3435
pass
3536

3637

38+
@main.command()
39+
@click.option(
40+
"--artifact-ids",
41+
required=True,
42+
type=str,
43+
help="""
44+
Artifact IDs whose version needs to update, separated by comma.
45+
""",
46+
)
47+
@click.option(
48+
"--versions",
49+
required=False,
50+
default="./versions.txt",
51+
type=str,
52+
help="""
53+
The path to the versions.txt.
54+
""",
55+
)
56+
def bump_snapshot_version(artifact_ids: str, versions: str) -> None:
57+
bump_version(artifact_ids, "snapshot", versions)
58+
3759
@main.command()
3860
@click.option(
3961
"--artifact-ids",
@@ -49,7 +71,7 @@ def main(ctx):
4971
default="patch",
5072
type=str,
5173
help="""
52-
The type of version bump, one of major, minor or patch.
74+
The type of version bump, one of major, minor, patch.
5375
""",
5476
)
5577
@click.option(
@@ -62,6 +84,9 @@ def main(ctx):
6284
""",
6385
)
6486
def bump_released_version(artifact_ids: str, version_type: str, versions: str) -> None:
87+
bump_version(artifact_ids, version_type, versions)
88+
89+
def bump_version(artifact_ids: str, version_type: str, versions: str) -> None:
6590
target_artifact_ids = set(artifact_ids.split(","))
6691
version_enum = _parse_type_or_raise(version_type)
6792
newlines = []
@@ -95,6 +120,12 @@ def bump_released_version(artifact_ids: str, version_type: str, versions: str) -
95120
minor += 1
96121
case VersionType.PATCH:
97122
patch += 1
123+
case VersionType.SNAPSHOT:
124+
# Keep the released version as is.
125+
newlines.append(
126+
f"{artifact_id}:{major}.{minor}.{patch}:{major}.{minor + 1}.0-SNAPSHOT"
127+
)
128+
continue
98129
newlines.append(
99130
f"{artifact_id}:{major}.{minor}.{patch}:{major}.{minor}.{patch}"
100131
)

.github/release/release_unit_tests.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import shutil
55
import tempfile
66
import unittest
7-
from partial_release import bump_released_version
7+
from partial_release import bump_released_version, bump_snapshot_version
88

99
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
1010
GOLDEN = os.path.join(SCRIPT_DIR, "testdata")
@@ -45,6 +45,22 @@ def test_bump_multiple_versions_success(self):
4545
actual = f.read()
4646
self.assertEqual(expected, actual)
4747

48+
def test_bump_snapshot_version_success(self):
49+
golden = f"{GOLDEN}/snapshot/versions-snapshot-golden.txt"
50+
with copied_fixtures_dir(f"{FIXTURES}/snapshot"):
51+
runner.invoke(
52+
bump_snapshot_version,
53+
[
54+
"--artifact-ids=google-cloud-asset",
55+
"--versions=versions-snapshot.txt",
56+
],
57+
)
58+
with open(golden) as g:
59+
expected = g.read()
60+
with open("./versions-snapshot.txt") as f:
61+
actual = f.read()
62+
self.assertEqual(expected, actual)
63+
4864

4965
@contextlib.contextmanager
5066
def change_dir_to(path: str) -> str:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
google-cloud-asset:1.2.3:1.3.0-SNAPSHOT

generation/apply_current_versions.sh

Lines changed: 0 additions & 26 deletions
This file was deleted.

generation/apply_versions.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
# This script sets the "current-version" written in versions.txt applied to all
4+
# pom.xml files in this monorepo.
5+
# This script plays supplemental role just in case Release Please pull request
6+
# fails to update all files.
7+
8+
# Usage:
9+
# # Run this script at the root of the monorepo
10+
# bash generation/apply_current_versions.sh
11+
12+
set -e
13+
14+
versions_file=$1
15+
column_name=$2
16+
if [[ -z "$versions_file" || -z "$column_name" ]]; then
17+
echo "Replaces the versions annotated with the x-version-update tag in"
18+
echo "all pom.xml files in the current working directory and its subdirectories"
19+
echo "with the versions specified in the versions.txt file (current or released)."
20+
echo
21+
echo "Usage: $0 path/to/versions.txt (released|current)"
22+
exit 1
23+
fi
24+
if [[ "$column_name" == "released" ]]; then
25+
column_index=2
26+
elif [[ "$column_name" == "current" ]]; then
27+
column_index=3
28+
elif "$column_name" != "current" ]]; then
29+
echo "Error: column_name must be either 'released' or 'current'"
30+
exit 1
31+
fi
32+
33+
34+
SED_OPTIONS=""
35+
36+
# The second column is
37+
for KV in $(cut -f1,"${column_index}" -d: $versions_file |grep -v "#"); do
38+
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>|;}"
41+
done
42+
43+
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

0 commit comments

Comments
 (0)