Skip to content

Commit 9e0649a

Browse files
committed
chore: enhance monorepo migration scripts with generic exclusions and BOM substitution guards
1 parent ba75e49 commit 9e0649a

3 files changed

Lines changed: 56 additions & 14 deletions

File tree

monorepo-migration/migrate-bigtable.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export SOURCE_REPO_URL="https://github.com/googleapis/java-bigtable"
2929
export MIGRATION_HEAD_BRANCH="main"
3030
export SQUASH_COMMITS="false"
3131
export CODEOWNER="@googleapis/bigtable-team"
32+
export BOM_SUBSTITUTIONS="gapic-libraries-bom:google-cloud-monitoring-bom"
33+
export PRE_INSTALL_DEPS="java-monitoring/google-cloud-monitoring-bom"
3234

3335
# 2. Execute the central migration script
3436
"${SCRIPT_DIR}/migrate.sh"

monorepo-migration/migrate.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,14 @@ sed -i.bak "s/'java-storage-nio'/'java-storage-nio'\n '${SOURCE_REPO_NAME}'/" "
443443
python3 "$UPDATE_CI_FILTERS_SCRIPT" ".github/workflows/ci.yaml" "$SOURCE_REPO_NAME"
444444
python3 "$UPDATE_CHANGES_FILTERS_SCRIPT" ".github/workflows/ci.yaml" "$SOURCE_REPO_NAME"
445445

446+
if [ -n "${PRE_INSTALL_DEPS}" ]; then
447+
echo "Injecting explicit dependencies into always_install_deps list inside .kokoro/common.sh..."
448+
for dep in $(echo "${PRE_INSTALL_DEPS}" | tr ',' ' '); do
449+
sed -i.bak "s|always_install_deps_list=(|always_install_deps_list=(\n '${dep}'|" ".kokoro/common.sh"
450+
done
451+
rm -f .kokoro/common.sh.bak
452+
fi
453+
446454
echo "Committing common.sh and ci.yaml updates..."
447455
git add .kokoro/common.sh .github/workflows/ci.yaml
448456
git commit -n --no-gpg-sign -m "chore($SOURCE_REPO_NAME): exempt from global integration testing matrix"
@@ -465,7 +473,6 @@ fi
465473
# 7.11 Verify compilation
466474
echo "Verifying compilation..."
467475
BUILD_SUBDIR="${SOURCE_REPO_NAME}" JOB_TYPE=test .kokoro/build.sh
468-
# (cd "$SOURCE_REPO_NAME" && mvn compile -DskipTests -T 1C)
469476

470477
# 7.13 Squash commits
471478
if [ "${SQUASH_COMMITS:-false}" = "true" ]; then

monorepo-migration/modernize_pom.py

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def get_monorepo_versions(monorepo_root='.'):
8585
versions = {}
8686
for root, dirs, files in os.walk(monorepo_root):
8787
# Skip common directories to improve performance and avoid noise
88-
dirs[:] = [d for d in dirs if d not in ['samples', 'test', 'target', '.git', '.cloud', 'verification', 'test_data']]
88+
dirs[:] = [d for d in dirs if d not in ['samples', 'test', 'target', '.git', '.cloud', 'verification', 'test_data', 'generation']]
8989

9090
if 'pom.xml' in files:
9191
pom_path = os.path.join(root, 'pom.xml')
@@ -95,6 +95,14 @@ def get_monorepo_versions(monorepo_root='.'):
9595
return versions
9696

9797
def modernize_pom(file_path, parent_version, source_repo_name=None, parent_artifactId='google-cloud-jar-parent', relative_path='../google-cloud-jar-parent/pom.xml', monorepo_versions=None):
98+
bom_substitutions_env = os.environ.get('BOM_SUBSTITUTIONS')
99+
bom_substitutions = {}
100+
if bom_substitutions_env:
101+
for pair in bom_substitutions_env.split(','):
102+
if ':' in pair:
103+
old, new = pair.split(':', 1)
104+
bom_substitutions[old.strip()] = new.strip()
105+
98106
with open(file_path, 'r') as f:
99107
lines = f.readlines()
100108

@@ -182,12 +190,30 @@ def modernize_pom(file_path, parent_version, source_repo_name=None, parent_artif
182190
current_group_id = None
183191
current_artifact_id = None
184192
has_version = False
193+
in_exclusions = False
185194
continue
186195
if '</dependency>' in line:
187196
in_dependency = False
188197
current_dependency_lines.append(line)
189198

190-
if current_artifact_id == 'google-cloud-shared-dependencies':
199+
if current_artifact_id == 'google-cloud-shared-dependencies' and '-deps-bom' not in file_path:
200+
continue
201+
202+
if current_artifact_id in bom_substitutions:
203+
target_bom = bom_substitutions[current_artifact_id]
204+
target_version = monorepo_versions.get(target_bom, '0.0.1-SNAPSHOT')
205+
target_marker = target_bom.replace('-bom', '')
206+
indent = " "
207+
current_dependency_lines = [
208+
f"{indent}<dependency>\n",
209+
f"{indent} <groupId>com.google.cloud</groupId>\n",
210+
f"{indent} <artifactId>{target_bom}</artifactId>\n",
211+
f"{indent} <version>{target_version}</version><!-- {{x-version-update:{target_marker}:current}} -->\n",
212+
f"{indent} <type>pom</type>\n",
213+
f"{indent} <scope>import</scope>\n",
214+
f"{indent}</dependency>\n"
215+
]
216+
new_lines.extend(current_dependency_lines)
191217
continue
192218

193219
# Preservation logic:
@@ -196,22 +222,29 @@ def modernize_pom(file_path, parent_version, source_repo_name=None, parent_artif
196222
# 3. Is com.google.cloud group AND artifactId starts with google-cloud- AND has a version tag
197223
is_external = current_group_id and not current_group_id.startswith('com.google')
198224
is_google_cloud_lib = current_group_id == 'com.google.cloud' and current_artifact_id and current_artifact_id.startswith('google-cloud-')
225+
is_truth = current_group_id and current_group_id.startswith('com.google.truth')
199226

200-
if should_preserve or (is_external and has_version) or (is_google_cloud_lib and has_version):
227+
if should_preserve or (is_external and has_version) or (is_google_cloud_lib and has_version) or (is_truth and has_version):
201228
new_lines.extend(current_dependency_lines)
202229
continue
203230

204231
if in_dependency:
205-
if '<groupId>' in line:
206-
match = re.search(r'<groupId>(.*?)</groupId>', line)
207-
if match:
208-
current_group_id = match.group(1).strip()
209-
if '<artifactId>' in line:
210-
match = re.search(r'<artifactId>(.*?)</artifactId>', line)
211-
if match:
212-
current_artifact_id = match.group(1).strip()
213-
if '<version>' in line:
214-
has_version = True
232+
if '<exclusions>' in line:
233+
in_exclusions = True
234+
if '</exclusions>' in line:
235+
in_exclusions = False
236+
237+
if not in_exclusions:
238+
if '<groupId>' in line:
239+
match = re.search(r'<groupId>(.*?)</groupId>', line)
240+
if match:
241+
current_group_id = match.group(1).strip()
242+
if '<artifactId>' in line:
243+
match = re.search(r'<artifactId>(.*?)</artifactId>', line)
244+
if match:
245+
current_artifact_id = match.group(1).strip()
246+
if '<version>' in line:
247+
has_version = True
215248

216249
if monorepo_versions and current_artifact_id and current_artifact_id in monorepo_versions:
217250
new_version = monorepo_versions[current_artifact_id]

0 commit comments

Comments
 (0)