Skip to content

Commit bd62f0b

Browse files
committed
chore: partial release script that uses the main branch
1 parent ce3d3fb commit bd62f0b

File tree

3 files changed

+60
-29
lines changed

3 files changed

+60
-29
lines changed

.github/release/partial_release.py

Lines changed: 15 additions & 3 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)
@@ -49,7 +50,7 @@ def main(ctx):
4950
default="patch",
5051
type=str,
5152
help="""
52-
The type of version bump, one of major, minor or patch.
53+
The type of version bump, one of major, minor, patch.
5354
""",
5455
)
5556
@click.option(
@@ -61,7 +62,14 @@ def main(ctx):
6162
The path to the versions.txt.
6263
""",
6364
)
65+
66+
def bump_snapshot_version(artifact_ids: str, versions: str) -> None:
67+
bump_version(artifact_ids, "snapshot", versions)
68+
6469
def bump_released_version(artifact_ids: str, version_type: str, versions: str) -> None:
70+
bump_version(artifact_ids, version_type, versions)
71+
72+
def bump_version(artifact_ids: str, version_type: str, versions: str) -> None:
6573
target_artifact_ids = set(artifact_ids.split(","))
6674
version_enum = _parse_type_or_raise(version_type)
6775
newlines = []
@@ -88,15 +96,19 @@ def bump_released_version(artifact_ids: str, version_type: str, versions: str) -
8896
major, minor, patch = [
8997
int(ver_num) for ver_num in released_version.split(".")
9098
]
99+
suffix=""
91100
match version_enum:
92101
case VersionType.MAJOR:
93102
major += 1
94103
case VersionType.MINOR:
95104
minor += 1
96105
case VersionType.PATCH:
97106
patch += 1
107+
case VersionType.SNAPSHOT:
108+
minor += 1
109+
suffix = "-SNAPSHOT"
98110
newlines.append(
99-
f"{artifact_id}:{major}.{minor}.{patch}:{major}.{minor}.{patch}"
111+
f"{artifact_id}:{major}.{minor}.{patch}{suffix}:{major}.{minor}.{patch}{suffix}"
100112
)
101113
with open(versions, "w") as versions_file:
102114
versions_file.writelines("\n".join(newlines))

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)