Skip to content

Commit 586d487

Browse files
committed
Fix workflow YAML syntax: extract Python heredoc to standalone script
1 parent 6e3405a commit 586d487

2 files changed

Lines changed: 95 additions & 93 deletions

File tree

.github/workflows/main.yml

Lines changed: 1 addition & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -61,99 +61,7 @@ jobs:
6161
if git diff --name-only --diff-filter=U | grep -q "^pom.xml$"; then
6262
echo "Resolving pom.xml conflicts intelligently..."
6363
git show upstream/master:pom.xml > /tmp/upstream-pom.xml
64-
python3 << 'PYTHON_SCRIPT'
65-
import re
66-
import sys
67-
68-
def smart_merge_pom(our_file, upstream_file, output_file):
69-
with open(our_file, 'r', encoding='utf-8') as f:
70-
our_content = f.read()
71-
with open(upstream_file, 'r', encoding='utf-8') as f:
72-
upstream_content = f.read()
73-
74-
critical_fixes = {
75-
(r'<artifactId>flatten-maven-plugin</artifactId>\s*<version>1\.3\.0</version>',
76-
'<artifactId>flatten-maven-plugin</artifactId>\n <version>1.6.0</version>'):
77-
"Upgrade flatten plugin for Maven 3.9.6 compatibility",
78-
(r'(</flatten-maven-plugin>\s*</plugin>)',
79-
r'''\1
80-
<plugin>
81-
<groupId>org.apache.maven.plugins</groupId>
82-
<artifactId>maven-jar-plugin</artifactId>
83-
<version>3.3.0</version>
84-
<dependencies>
85-
<dependency>
86-
<groupId>org.codehaus.plexus</groupId>
87-
<artifactId>plexus-archiver</artifactId>
88-
<version>4.4.0</version>
89-
</dependency>
90-
<dependency>
91-
<groupId>org.codehaus.plexus</groupId>
92-
<artifactId>plexus-io</artifactId>
93-
<version>3.2.0</version>
94-
</dependency>
95-
<dependency>
96-
<groupId>org.codehaus.plexus</groupId>
97-
<artifactId>plexus-interpolation</artifactId>
98-
<version>1.27</version>
99-
</dependency>
100-
<dependency>
101-
<groupId>commons-io</groupId>
102-
<artifactId>commons-io</artifactId>
103-
<version>2.8.0</version>
104-
</dependency>
105-
<dependency>
106-
<groupId>org.apache.commons</groupId>
107-
<artifactId>commons-compress</artifactId>
108-
<version>1.20</version>
109-
</dependency>
110-
</dependencies>
111-
</plugin>'''):
112-
"Add jar plugin configuration with required dependencies"
113-
}
114-
115-
merged_content = our_content
116-
117-
upstream_repos = re.search(r'<repositories>(.*?)</repositories>', upstream_content, re.DOTALL)
118-
our_repos = re.search(r'<repositories>(.*?)</repositories>', our_content, re.DOTALL)
119-
120-
if upstream_repos and our_repos:
121-
upstream_repo_list = re.findall(r'<repository>.*?</repository>', upstream_repos.group(1), re.DOTALL)
122-
our_repo_list = re.findall(r'<repository>.*?</repository>', our_repos.group(1), re.DOTALL)
123-
our_repo_ids = set()
124-
for repo in our_repo_list:
125-
match = re.search(r'<id>(.*?)</id>', repo)
126-
if match:
127-
our_repo_ids.add(match.group(1))
128-
new_repos = []
129-
for repo in upstream_repo_list:
130-
match = re.search(r'<id>(.*?)</id>', repo)
131-
if match and match.group(1) not in our_repo_ids:
132-
new_repos.append(repo)
133-
if new_repos:
134-
print(f"Adding {len(new_repos)} new repositories from upstream")
135-
new_repos_str = '\n '.join(new_repos)
136-
merged_content = re.sub(
137-
r'(</repositories>)',
138-
f' {new_repos_str}\n </repositories>',
139-
merged_content
140-
)
141-
142-
for pattern, replacement in critical_fixes.items():
143-
if isinstance(pattern, tuple):
144-
merged_content = re.sub(pattern[0], replacement, merged_content)
145-
else:
146-
merged_content = re.sub(pattern, replacement, merged_content)
147-
148-
with open(output_file, 'w', encoding='utf-8') as f:
149-
f.write(merged_content)
150-
print("Smart merge completed")
151-
return True
152-
153-
if __name__ == '__main__':
154-
success = smart_merge_pom('/tmp/our-pom.xml', '/tmp/upstream-pom.xml', 'pom.xml')
155-
sys.exit(0 if success else 1)
156-
PYTHON_SCRIPT
64+
python3 scripts/smart_merge_pom.py /tmp/our-pom.xml /tmp/upstream-pom.xml pom.xml
15765
git add pom.xml
15866
git commit -m "Smart merge: resolve pom.xml conflicts with upstream" -m "- Preserved GitHub Actions build fixes" -m "- Merged new repositories from upstream" -m "- Kept flatten-maven-plugin at 1.6.0 for compatibility" -m "- Maintained jar plugin configuration with required dependencies"
15967
fi

scripts/smart_merge_pom.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import re
2+
import sys
3+
4+
def smart_merge_pom(our_file, upstream_file, output_file):
5+
with open(our_file, 'r', encoding='utf-8') as f:
6+
our_content = f.read()
7+
with open(upstream_file, 'r', encoding='utf-8') as f:
8+
upstream_content = f.read()
9+
10+
critical_fixes = {
11+
(r'<artifactId>flatten-maven-plugin</artifactId>\s*<version>1\.3\.0</version>',
12+
'<artifactId>flatten-maven-plugin</artifactId>\n <version>1.6.0</version>'):
13+
"Upgrade flatten plugin for Maven 3.9.6 compatibility",
14+
(r'(</flatten-maven-plugin>\s*</plugin>)',
15+
r'''\1
16+
<plugin>
17+
<groupId>org.apache.maven.plugins</groupId>
18+
<artifactId>maven-jar-plugin</artifactId>
19+
<version>3.3.0</version>
20+
<dependencies>
21+
<dependency>
22+
<groupId>org.codehaus.plexus</groupId>
23+
<artifactId>plexus-archiver</artifactId>
24+
<version>4.4.0</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.codehaus.plexus</groupId>
28+
<artifactId>plexus-io</artifactId>
29+
<version>3.2.0</version>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.codehaus.plexus</groupId>
33+
<artifactId>plexus-interpolation</artifactId>
34+
<version>1.27</version>
35+
</dependency>
36+
<dependency>
37+
<groupId>commons-io</groupId>
38+
<artifactId>commons-io</artifactId>
39+
<version>2.8.0</version>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.apache.commons</groupId>
43+
<artifactId>commons-compress</artifactId>
44+
<version>1.20</version>
45+
</dependency>
46+
</dependencies>
47+
</plugin>'''):
48+
"Add jar plugin configuration with required dependencies"
49+
}
50+
51+
merged_content = our_content
52+
53+
upstream_repos = re.search(r'<repositories>(.*?)</repositories>', upstream_content, re.DOTALL)
54+
our_repos = re.search(r'<repositories>(.*?)</repositories>', our_content, re.DOTALL)
55+
56+
if upstream_repos and our_repos:
57+
upstream_repo_list = re.findall(r'<repository>.*?</repository>', upstream_repos.group(1), re.DOTALL)
58+
our_repo_list = re.findall(r'<repository>.*?</repository>', our_repos.group(1), re.DOTALL)
59+
our_repo_ids = set()
60+
for repo in our_repo_list:
61+
match = re.search(r'<id>(.*?)</id>', repo)
62+
if match:
63+
our_repo_ids.add(match.group(1))
64+
new_repos = []
65+
for repo in upstream_repo_list:
66+
match = re.search(r'<id>(.*?)</id>', repo)
67+
if match and match.group(1) not in our_repo_ids:
68+
new_repos.append(repo)
69+
if new_repos:
70+
print(f"Adding {len(new_repos)} new repositories from upstream")
71+
new_repos_str = '\n '.join(new_repos)
72+
merged_content = re.sub(
73+
r'(</repositories>)',
74+
f' {new_repos_str}\n </repositories>',
75+
merged_content
76+
)
77+
78+
for pattern, replacement in critical_fixes.items():
79+
if isinstance(pattern, tuple):
80+
merged_content = re.sub(pattern[0], replacement, merged_content)
81+
else:
82+
merged_content = re.sub(pattern, replacement, merged_content)
83+
84+
with open(output_file, 'w', encoding='utf-8') as f:
85+
f.write(merged_content)
86+
print("Smart merge completed")
87+
return True
88+
89+
if __name__ == '__main__':
90+
if len(sys.argv) < 4:
91+
print("Usage: python smart_merge_pom.py <our_pom> <upstream_pom> <output_pom>")
92+
sys.exit(1)
93+
success = smart_merge_pom(sys.argv[1], sys.argv[2], sys.argv[3])
94+
sys.exit(0 if success else 1)

0 commit comments

Comments
 (0)