Skip to content

Commit 2bd0821

Browse files
committed
feat: insert new module in root pom.xml
1 parent e7df2ba commit 2bd0821

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

monorepo-migration/migrate.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ git reset --hard HEAD
7777
git clean -fd
7878
git checkout -f main
7979
git reset --hard origin/main
80+
git clean -fdx
8081

8182
# Check if the repository is already migrated
8283
if [ -d "$SOURCE_REPO_NAME" ]; then
@@ -128,6 +129,46 @@ if [ -n "$CODEOWNER" ]; then
128129
git commit -n --no-gpg-sign -m "chore($SOURCE_REPO_NAME): add code owners for $SOURCE_REPO_NAME"
129130
fi
130131

132+
# 7.2 Update root pom.xml modules
133+
echo "Updating root pom.xml modules..."
134+
python3 -c "
135+
import sys
136+
pom_path = sys.argv[1]
137+
module_name = sys.argv[2]
138+
new_module = f' <module>{module_name}</module>\n'
139+
with open(pom_path, 'r') as f:
140+
content = f.read()
141+
start_tag = '<modules>'
142+
end_tag = '</modules>'
143+
start_idx = content.find(start_tag)
144+
end_idx = content.find(end_tag)
145+
if start_idx != -1 and end_idx != -1:
146+
modules_section = content[start_idx + len(start_tag):end_idx]
147+
lines = [l for l in modules_section.splitlines(keepends=True) if l.strip()]
148+
149+
java_indices = [i for i, l in enumerate(lines) if '<module>java-' in l]
150+
if java_indices:
151+
start_java = java_indices[0]
152+
end_java = java_indices[-1] + 1
153+
java_lines = lines[start_java:end_java]
154+
if not any(f'<module>{module_name}</module>' in l for l in java_lines):
155+
java_lines.append(new_module)
156+
java_lines.sort()
157+
lines = lines[:start_java] + java_lines + lines[end_java:]
158+
else:
159+
if not any(f'<module>{module_name}</module>' in l for l in lines):
160+
lines.append(new_module)
161+
162+
new_content = content[:start_idx + len(start_tag)] + '\n' + ''.join(lines) + ' ' + content[end_idx:]
163+
with open(pom_path, 'w') as f:
164+
f.write(new_content)
165+
" "pom.xml" "$SOURCE_REPO_NAME"
166+
167+
echo "Committing root pom.xml modules update..."
168+
git add pom.xml
169+
git commit -n --no-gpg-sign -m "chore($SOURCE_REPO_NAME): add module to root pom.xml"
170+
171+
131172
# 7.5 Migrate GitHub Actions workflows
132173
echo "Checking for GitHub Actions workflows..."
133174
if [ -d "$SOURCE_REPO_NAME/.github/workflows" ]; then

0 commit comments

Comments
 (0)