Skip to content

Commit ab86864

Browse files
committed
migrate .OwlBot-hermetic.yaml
1 parent 60470eb commit ab86864

File tree

2 files changed

+98
-3
lines changed

2 files changed

+98
-3
lines changed

monorepo-migration/migrate.sh

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ MODERNIZE_POM_SCRIPT="$TRANSFORM_SCRIPT_DIR/modernize_pom.py"
5454
UPDATE_ROOT_POM_SCRIPT="$TRANSFORM_SCRIPT_DIR/update_root_pom.py"
5555
FIX_COPYRIGHT_SCRIPT="$TRANSFORM_SCRIPT_DIR/fix_copyright_headers.py"
5656
UPDATE_GENERATION_CONFIG_SCRIPT="$TRANSFORM_SCRIPT_DIR/update_generation_config.py"
57+
UPDATE_OWLBOT_HERMETIC_SCRIPT="$TRANSFORM_SCRIPT_DIR/update_owlbot_hermetic.py"
5758

5859
echo "Starting migration using git read-tree with isolated clones..."
5960

@@ -258,15 +259,32 @@ if [ -f "$SOURCE_VERSIONS" ]; then
258259
git commit -n --no-gpg-sign -m "chore($SOURCE_REPO_NAME): consolidate versions.txt into root"
259260
fi
260261

261-
# 7.8 Fix copyright headers in Java files
262+
# 7.8 Migrate .OwlBot-hermetic.yaml
263+
echo "Migrating .OwlBot-hermetic.yaml..."
264+
if [ -f "$SOURCE_DIR/.github/.OwlBot-hermetic.yaml" ]; then
265+
SOURCE_OWLBOT="$SOURCE_DIR/.github/.OwlBot-hermetic.yaml"
266+
else
267+
SOURCE_OWLBOT=""
268+
fi
269+
270+
if [ -n "$SOURCE_OWLBOT" ]; then
271+
TARGET_OWLBOT="$SOURCE_REPO_NAME/.OwlBot-hermetic.yaml"
272+
python3 "$UPDATE_OWLBOT_HERMETIC_SCRIPT" "$TARGET_OWLBOT" "$SOURCE_OWLBOT" "$SOURCE_REPO_NAME"
273+
274+
echo "Committing .OwlBot-hermetic.yaml migration..."
275+
git add "$TARGET_OWLBOT"
276+
git commit -n --no-gpg-sign -m "chore($SOURCE_REPO_NAME): migrate .OwlBot-hermetic.yaml"
277+
fi
278+
279+
# 7.9 Fix copyright headers in Java files
262280
echo "Fixing copyright headers in Java files..."
263281
python3 "$FIX_COPYRIGHT_SCRIPT" "$SOURCE_REPO_NAME"
264282

265283
echo "Committing copyright header fixes..."
266284
git add "$SOURCE_REPO_NAME"
267285
git commit -n --no-gpg-sign -m "chore($SOURCE_REPO_NAME): update copyright headers to 2026 Google LLC"
268286

269-
# 7.9 Modernize root pom.xml
287+
# 7.10 Modernize root pom.xml
270288
echo "Modernizing root pom.xml..."
271289
PARENT_VERSION=$(grep -m 1 "<version>.*{x-version-update:google-cloud-java:current}" google-cloud-jar-parent/pom.xml | sed -E 's/.*<version>(.*)<\/version>.*/\1/')
272290
python3 "$MODERNIZE_POM_SCRIPT" "$SOURCE_REPO_NAME/pom.xml" "$PARENT_VERSION" "$SOURCE_REPO_NAME"
@@ -275,7 +293,7 @@ echo "Committing root pom.xml modernization..."
275293
git add "$SOURCE_REPO_NAME/pom.xml"
276294
git commit -n --no-gpg-sign -m "chore($SOURCE_REPO_NAME): modernize root pom.xml"
277295

278-
# 7.10 Verify compilation
296+
# 7.11 Verify compilation
279297
echo "Verifying compilation..."
280298
(cd "$SOURCE_REPO_NAME" && mvn compile -DskipTests -T 1C)
281299

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env python3
2+
# Copyright 2026 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
import sys
17+
import yaml
18+
import re
19+
20+
def update_config(target_path, source_path, prefix):
21+
"""
22+
Reads source_path, prepends prefix to paths in deep-remove-regex and deep-preserve-regex,
23+
and writes to target_path.
24+
"""
25+
with open(source_path, 'r') as f:
26+
source_content = f.read()
27+
28+
# Load source data
29+
source_data = yaml.safe_load(source_content) or {}
30+
31+
# Define fields to update
32+
fields_to_update = ['deep-remove-regex', 'deep-preserve-regex']
33+
34+
for field in fields_to_update:
35+
if field in source_data:
36+
updated_list = []
37+
for item in source_data[field]:
38+
# If item is a string, prepend prefix
39+
# Regex might need handling if it starts with ^
40+
# But usually these are just paths.
41+
# Assuming simple concatenation for now as per requirement.
42+
# "When referencing paths in the deep-remove-regex and deep-preserve-regex, the new directory name should be prefixed"
43+
44+
# If the regex starts with ^, insert the prefix after it.
45+
if item.startswith('^'):
46+
updated_list.append(f"^{prefix}/{item[1:]}")
47+
else:
48+
updated_list.append(f"/{prefix}{item}")
49+
source_data[field] = updated_list
50+
51+
if 'deep-copy-regex' in source_data:
52+
for item in source_data['deep-copy-regex']:
53+
if 'dest' in item and item['dest'].startswith('/owl-bot-staging/'):
54+
item['dest'] = item['dest'].replace('/owl-bot-staging/', f'/owl-bot-staging/{prefix}/', 1)
55+
56+
# Write to target_path
57+
with open(target_path, 'w') as f:
58+
# Check if there was a license header in the original file
59+
# Match a block of lines starting with # at the beginning of the file
60+
header_match = re.search(r'^((?:#[^\n]*\n)+)', source_content)
61+
if header_match:
62+
f.write(header_match.group(1))
63+
f.write("\n") # Add a newline after the header
64+
65+
# Use yaml.dump to write the data.
66+
yaml.dump(source_data, f, sort_keys=False, default_flow_style=False, indent=2)
67+
68+
if __name__ == "__main__":
69+
if len(sys.argv) != 4:
70+
print("Usage: python3 update_owlbot_hermetic.py <target_file> <source_file> <prefix>")
71+
sys.exit(1)
72+
73+
target_path = sys.argv[1]
74+
source_path = sys.argv[2]
75+
prefix = sys.argv[3]
76+
77+
update_config(target_path, source_path, prefix)

0 commit comments

Comments
 (0)