@@ -2,7 +2,6 @@ name: Auto Sync Upstream & Build
22
33on :
44 schedule :
5- # 每天凌晨 2 点检查上游更新
65 - cron : ' 0 2 * * *'
76 workflow_dispatch :
87 inputs :
1211 default : ' false'
1312
1413env :
15- UPSTREAM_REPO : PQguanfang /UltimateShop
14+ UPSTREAM_REPO : ManyouTeam /UltimateShop
1615 JAVA_VERSION : ' 21'
17- MAVEN_VERSION : ' 3.9.6'
1816
1917jobs :
2018 sync-and-build :
@@ -38,19 +36,15 @@ jobs:
3836 - name : Check for upstream changes
3937 id : check_changes
4038 run : |
41- # 获取上游最新提交
4239 UPSTREAM_SHA=$(git rev-parse upstream/master)
4340 LOCAL_SHA=$(git rev-parse origin/master)
44-
4541 echo "Upstream SHA: $UPSTREAM_SHA"
4642 echo "Local SHA: $LOCAL_SHA"
47-
4843 if [ "$UPSTREAM_SHA" = "$LOCAL_SHA" ] && [ "${{ github.event.inputs.force_build }}" != "true" ]; then
4944 echo "No upstream changes detected"
5045 echo "has_changes=false" >> $GITHUB_OUTPUT
5146 exit 0
5247 fi
53-
5448 echo "Upstream changes detected!"
5549 echo "has_changes=true" >> $GITHUB_OUTPUT
5650 echo "upstream_sha=$UPSTREAM_SHA" >> $GITHUB_OUTPUT
@@ -60,68 +54,29 @@ jobs:
6054 run : |
6155 git config user.name "GitHub Actions Bot"
6256 git config user.email "actions@github.com"
63-
64- # 创建临时分支进行合并
6557 git checkout -b temp-merge upstream/master
66-
67- # 保存我们的 pom.xml 修改
6858 cp pom.xml /tmp/our-pom.xml
69-
70- # 尝试合并到 master
7159 git checkout master
72-
73- # 使用 ort 合并策略,优先保留我们的 pom.xml 修改
7460 git merge temp-merge -m "Merge upstream changes" || true
75-
76- # 如果 pom.xml 有冲突,使用智能合并
7761 if git diff --name-only --diff-filter=U | grep -q "^pom.xml$"; then
7862 echo "Resolving pom.xml conflicts intelligently..."
79-
80- # 提取上游 pom.xml 的关键版本信息
8163 git show upstream/master:pom.xml > /tmp/upstream-pom.xml
82-
83- # 使用 Python 进行智能合并
8464 python3 << 'PYTHON_SCRIPT'
85- import xml.etree.ElementTree as ET
86- import re
87- import sys
88-
89- def parse_pom(filepath):
90- """解析 pom.xml 文件"""
91- tree = ET.parse(filepath)
92- return tree.getroot()
93-
94- def get_plugin_version(root, group_id, artifact_id):
95- """获取插件版本"""
96- ns = {'maven': 'http://maven.apache.org/POM/4.0.0'}
97- for plugin in root.findall('.//maven:plugin', ns):
98- gid = plugin.find('maven:groupId', ns)
99- aid = plugin.find('maven:artifactId', ns)
100- ver = plugin.find('maven:version', ns)
101- if gid is not None and aid is not None and ver is not None:
102- if gid.text == group_id and aid.text == artifact_id:
103- return ver.text
104- return None
105-
106- def smart_merge_pom(our_file, upstream_file, output_file):
107- """智能合并 pom.xml"""
108-
109- with open(our_file, 'r', encoding='utf-8') as f:
110- our_content = f.read()
111-
112- with open(upstream_file, 'r', encoding='utf-8') as f:
113- upstream_content = f.read()
114-
115- # 保留我们的关键修复(这些修复是为了解决 GitHub Actions 构建问题)
116- critical_fixes = {
117- # flatten-maven-plugin 版本升级
118- (r'<artifactId>flatten-maven-plugin</artifactId>\s*<version>1\.3\.0</version>',
119- '<artifactId>flatten-maven-plugin</artifactId>\n <version>1.6.0</version>'):
120- "Upgrade flatten plugin for Maven 3.9.6 compatibility",
121-
122- # 确保我们的 jar 插件配置存在(GitHub Actions 中只需要 jar 插件,不需要 surefire 跳过测试)
123- (r'(</flatten-maven-plugin>\s*</plugin>)',
124- r'''\1
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
12580 <plugin>
12681 <groupId>org.apache.maven.plugins</groupId>
12782 <artifactId>maven-jar-plugin</artifactId>
@@ -153,68 +108,56 @@ jobs:
153108 <version>1.20</version>
154109 </dependency>
155110 </dependencies>
156- </plugin>'''):
157- "Add jar plugin configuration with required dependencies"
158- }
159-
160- merged_content = our_content
161-
162- # 检查上游是否有新的依赖或仓库配置,合并进来
163- # 提取上游的 repositories 和 dependencies
164- upstream_repos = re.search(r'<repositories>(.*?)</repositories>', upstream_content, re.DOTALL)
165- our_repos = re.search(r'<repositories>(.*?)</repositories>', our_content, re.DOTALL)
166-
167- if upstream_repos and our_repos:
168- # 提取上游独有的仓库
169- upstream_repo_list = re.findall(r'<repository>.*?</repository>', upstream_repos.group(1), re.DOTALL)
170- our_repo_list = re.findall(r'<repository>.*?</repository>', our_repos.group(1), re.DOTALL)
171-
172- our_repo_ids = set()
173- for repo in our_repo_list:
174- match = re.search(r'<id>(.*?)</id>', repo)
175- if match:
176- our_repo_ids.add(match.group(1))
177-
178- new_repos = []
179- for repo in upstream_repo_list:
180- match = re.search(r'<id>(.*?)</id>', repo)
181- if match and match.group(1) not in our_repo_ids:
182- new_repos.append(repo)
183-
184- if new_repos:
185- print(f"Adding {len(new_repos)} new repositories from upstream")
186- new_repos_str = '\n '.join(new_repos)
187- merged_content = re.sub(
188- r'(</repositories>)',
189- f' {new_repos_str}\n </repositories>',
190- merged_content
191- )
192-
193- # 应用关键修复
194- for pattern, replacement in critical_fixes.items():
195- if isinstance(pattern, tuple):
196- merged_content = re.sub(pattern[0], replacement, merged_content)
197- else:
198- merged_content = re.sub(pattern, replacement, merged_content)
199-
200- with open(output_file, 'w', encoding='utf-8') as f:
201- f.write(merged_content)
202-
203- print("Smart merge completed")
204- return True
205-
206- if __name__ == '__main__':
207- success = smart_merge_pom('/tmp/our-pom.xml', '/tmp/upstream-pom.xml', 'pom.xml')
208- sys.exit(0 if success else 1)
209- PYTHON_SCRIPT
210-
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
211157 git add pom.xml
212158 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"
213159 fi
214-
215- # 清理临时分支
216160 git branch -D temp-merge || true
217-
218161 echo "Merge completed successfully"
219162
220163 - name : Setup Java
@@ -225,25 +168,14 @@ jobs:
225168 distribution : ' temurin'
226169 cache : maven
227170
228- - name : Setup Maven
229- if : steps.check_changes.outputs.has_changes == 'true' || github.event.inputs.force_build == 'true'
230- run : |
231- wget -q https://dlcdn.apache.org/maven/maven-3/${{ env.MAVEN_VERSION }}/binaries/apache-maven-${{ env.MAVEN_VERSION }}-bin.tar.gz
232- tar -xzf apache-maven-${{ env.MAVEN_VERSION }}-bin.tar.gz
233- sudo mv apache-maven-${{ env.MAVEN_VERSION }} /opt/maven
234- sudo ln -sf /opt/maven/bin/mvn /usr/local/bin/mvn
235- mvn -version
236-
237171 - name : Build with Maven
238172 if : steps.check_changes.outputs.has_changes == 'true' || github.event.inputs.force_build == 'true'
239173 run : |
240- # GitHub Actions 环境可以正常下载依赖,不需要跳过测试
241174 mvn clean package -B
242-
243- # 检查构建结果
244- if [ -f "plugin/target/UltimateShop-*.jar" ]; then
175+ JAR_FILE=$(find plugin/target -name "UltimateShop-*.jar" ! -name "*sources.jar" ! -name "*javadoc.jar" | head -1)
176+ if [ -n "$JAR_FILE" ]; then
245177 echo "Build successful!"
246- ls -lh plugin/target/*.jar
178+ ls -lh "$JAR_FILE"
247179 else
248180 echo "Build failed - no JAR file found"
249181 exit 1
@@ -268,9 +200,7 @@ jobs:
268200 name : Auto Build - ${{ steps.check_changes.outputs.upstream_sha }}
269201 body : |
270202 Automated build after syncing with upstream ${{ env.UPSTREAM_REPO }}
271-
272203 Upstream Commit: ${{ steps.check_changes.outputs.upstream_sha }}
273- Build Date: ${{ github.event.repository.updated_at }}
274204 files : |
275205 plugin/target/UltimateShop-*.jar
276206 draft : false
@@ -287,11 +217,9 @@ jobs:
287217 - name : Notify on success
288218 if : success() && (steps.check_changes.outputs.has_changes == 'true' || github.event.inputs.force_build == 'true')
289219 run : |
290- echo "✅ Build completed successfully!"
291- echo "📦 Artifact: UltimateShop-*.jar"
292- echo "🏷️ Release: v${{ github.run_number }}-${{ steps.check_changes.outputs.upstream_sha }}"
220+ echo "Build completed successfully!"
293221
294222 - name : Notify on no changes
295223 if : steps.check_changes.outputs.has_changes == 'false'
296224 run : |
297- echo "ℹ️ No upstream changes detected. Skipping build."
225+ echo "No upstream changes detected. Skipping build."
0 commit comments