@@ -105,26 +105,18 @@ jobs:
105
105
print("All attempts failed")
106
106
return []
107
107
108
- def parse_current_versions(workflow_file):
109
- """Parse current Spring Boot versions from workflow file"""
110
- content = Path(workflow_file).read_text()
111
-
112
- # Find the springboot-version matrix line
113
- pattern = r'springboot-version:\s*\[\s*([^\]]+)\s*\]'
114
- match = re.search(pattern, content)
115
-
116
- if not match:
108
+ def parse_current_versions(json_file):
109
+ """Parse current Spring Boot versions from JSON data file"""
110
+ if not Path(json_file).exists():
117
111
return []
118
112
119
- # Extract versions from the match
120
- versions_str = match.group(1)
121
- versions = []
122
- for v in versions_str.split(','):
123
- v = v.strip().strip("'\"")
124
- if v:
125
- versions.append(v)
126
-
127
- return versions
113
+ try:
114
+ with open(json_file, 'r') as f:
115
+ data = json.load(f)
116
+ return data.get('versions', [])
117
+ except Exception as e:
118
+ print(f"Error reading {json_file}: {e}")
119
+ return []
128
120
129
121
def get_latest_patch(all_versions, minor_version):
130
122
"""Get the latest patch version for a given minor version"""
@@ -202,24 +194,17 @@ jobs:
202
194
203
195
return final_versions, changes_made
204
196
205
- def update_workflow_file(workflow_file, new_versions):
206
- """Update the workflow file with new versions"""
207
- content = Path(workflow_file).read_text()
208
-
209
- # Format new versions for YAML
210
- versions_str = ", ".join([f"'{v}'" for v in new_versions])
211
- new_matrix_line = f" springboot-version: [ {versions_str} ]"
212
-
213
- # Replace the matrix line
214
- pattern = r'(\s*)springboot-version:\s*\[\s*[^\]]+\s*\]'
215
- replacement = new_matrix_line
216
-
217
- updated_content = re.sub(pattern, replacement, content)
218
-
219
- if updated_content != content:
220
- Path(workflow_file).write_text(updated_content)
197
+ def update_json_file(json_file, new_versions):
198
+ """Update the JSON data file with new versions"""
199
+ try:
200
+ # Write new versions to JSON file
201
+ data = {"versions": new_versions}
202
+ with open(json_file, 'w') as f:
203
+ json.dump(data, f, indent=2)
221
204
return True
222
- return False
205
+ except Exception as e:
206
+ print(f"Error writing to {json_file}: {e}")
207
+ return False
223
208
224
209
def main():
225
210
print("Fetching Spring Boot versions...")
@@ -231,22 +216,22 @@ jobs:
231
216
232
217
print(f"Found {len(all_versions)} versions")
233
218
234
- workflows = [
235
- (".github/workflows /spring-boot-2-matrix.yml ", "2"),
236
- (".github/workflows /spring-boot-3-matrix.yml ", "3"),
237
- (".github/workflows /spring-boot-4-matrix.yml ", "4")
219
+ data_files = [
220
+ (".github/data /spring-boot-2-versions.json ", "2"),
221
+ (".github/data /spring-boot-3-versions.json ", "3"),
222
+ (".github/data /spring-boot-4-versions.json ", "4")
238
223
]
239
224
240
225
changes_made = False
241
226
change_summary = []
242
227
243
- for workflow_file , major_version in workflows :
244
- if not Path(workflow_file ).exists():
228
+ for json_file , major_version in data_files :
229
+ if not Path(json_file ).exists():
245
230
continue
246
231
247
- print(f"\nProcessing {workflow_file } (Spring Boot {major_version}.x)")
232
+ print(f"\nProcessing {json_file } (Spring Boot {major_version}.x)")
248
233
249
- current_versions = parse_current_versions(workflow_file )
234
+ current_versions = parse_current_versions(json_file )
250
235
if not current_versions:
251
236
continue
252
237
@@ -256,7 +241,7 @@ jobs:
256
241
257
242
if file_changed:
258
243
print(f"New versions: {new_versions}")
259
- if update_workflow_file(workflow_file , new_versions):
244
+ if update_json_file(json_file , new_versions):
260
245
changes_made = True
261
246
change_summary.append(f"Spring Boot {major_version}.x: {' -> '.join([str(current_versions), str(new_versions)])}")
262
247
else:
0 commit comments