Skip to content

Commit 10288b3

Browse files
committed
specify spring boot versions in separate file so it can be updated
1 parent 261a569 commit 10288b3

7 files changed

+77
-47
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"versions": ["2.1.0", "2.2.5", "2.4.13", "2.5.15", "2.6.15", "2.7.0", "2.7.18"]
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"versions": ["3.0.0", "3.2.10", "3.3.5", "3.4.5", "3.5.6"]
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"versions": ["4.0.0-M1", "4.0.0-M2", "4.0.0-M3"]
3+
}

.github/workflows/spring-boot-2-matrix.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,25 @@ concurrency:
1111
cancel-in-progress: true
1212

1313
jobs:
14+
load-versions:
15+
runs-on: ubuntu-latest
16+
outputs:
17+
matrix: ${{ steps.set-matrix.outputs.matrix }}
18+
steps:
19+
- name: Checkout Repo
20+
uses: actions/checkout@v5
21+
- name: Set matrix data
22+
id: set-matrix
23+
run: echo "matrix=$(cat .github/data/spring-boot-2-versions.json | jq -c .versions)" >> $GITHUB_OUTPUT
24+
1425
spring-boot-2-matrix:
26+
needs: load-versions
1527
timeout-minutes: 45
1628
runs-on: ubuntu-latest
1729
strategy:
1830
fail-fast: false
1931
matrix:
20-
springboot-version: [ '2.1.0', '2.2.5', '2.4.13', '2.5.15', '2.6.15', '2.7.0', '2.7.18' ]
32+
springboot-version: ${{ fromJSON(needs.load-versions.outputs.matrix) }}
2133

2234
name: Spring Boot ${{ matrix.springboot-version }}
2335
env:

.github/workflows/spring-boot-3-matrix.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,25 @@ concurrency:
1111
cancel-in-progress: true
1212

1313
jobs:
14+
load-versions:
15+
runs-on: ubuntu-latest
16+
outputs:
17+
matrix: ${{ steps.set-matrix.outputs.matrix }}
18+
steps:
19+
- name: Checkout Repo
20+
uses: actions/checkout@v5
21+
- name: Set matrix data
22+
id: set-matrix
23+
run: echo "matrix=$(cat .github/data/spring-boot-3-versions.json | jq -c .versions)" >> $GITHUB_OUTPUT
24+
1425
spring-boot-3-matrix:
26+
needs: load-versions
1527
timeout-minutes: 45
1628
runs-on: ubuntu-latest
1729
strategy:
1830
fail-fast: false
1931
matrix:
20-
springboot-version: [ '3.0.0', '3.2.10', '3.3.5', '3.4.5', '3.5.6' ]
32+
springboot-version: ${{ fromJSON(needs.load-versions.outputs.matrix) }}
2133

2234
name: Spring Boot ${{ matrix.springboot-version }}
2335
env:

.github/workflows/spring-boot-4-matrix.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,25 @@ concurrency:
1111
cancel-in-progress: true
1212

1313
jobs:
14+
load-versions:
15+
runs-on: ubuntu-latest
16+
outputs:
17+
matrix: ${{ steps.set-matrix.outputs.matrix }}
18+
steps:
19+
- name: Checkout Repo
20+
uses: actions/checkout@v5
21+
- name: Set matrix data
22+
id: set-matrix
23+
run: echo "matrix=$(cat .github/data/spring-boot-4-versions.json | jq -c .versions)" >> $GITHUB_OUTPUT
24+
1425
spring-boot-4-matrix:
26+
needs: load-versions
1527
timeout-minutes: 45
1628
runs-on: ubuntu-latest
1729
strategy:
1830
fail-fast: false
1931
matrix:
20-
springboot-version: [ '4.0.0-M1', '4.0.0-M2', '4.0.0-M3' ]
32+
springboot-version: ${{ fromJSON(needs.load-versions.outputs.matrix) }}
2133

2234
name: Spring Boot ${{ matrix.springboot-version }}
2335
env:

.github/workflows/update-spring-boot-versions.yml

Lines changed: 29 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -105,26 +105,18 @@ jobs:
105105
print("All attempts failed")
106106
return []
107107
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():
117111
return []
118112
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 []
128120
129121
def get_latest_patch(all_versions, minor_version):
130122
"""Get the latest patch version for a given minor version"""
@@ -202,24 +194,17 @@ jobs:
202194
203195
return final_versions, changes_made
204196
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)
221204
return True
222-
return False
205+
except Exception as e:
206+
print(f"Error writing to {json_file}: {e}")
207+
return False
223208
224209
def main():
225210
print("Fetching Spring Boot versions...")
@@ -231,22 +216,22 @@ jobs:
231216
232217
print(f"Found {len(all_versions)} versions")
233218
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")
238223
]
239224
240225
changes_made = False
241226
change_summary = []
242227
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():
245230
continue
246231
247-
print(f"\nProcessing {workflow_file} (Spring Boot {major_version}.x)")
232+
print(f"\nProcessing {json_file} (Spring Boot {major_version}.x)")
248233
249-
current_versions = parse_current_versions(workflow_file)
234+
current_versions = parse_current_versions(json_file)
250235
if not current_versions:
251236
continue
252237
@@ -256,7 +241,7 @@ jobs:
256241
257242
if file_changed:
258243
print(f"New versions: {new_versions}")
259-
if update_workflow_file(workflow_file, new_versions):
244+
if update_json_file(json_file, new_versions):
260245
changes_made = True
261246
change_summary.append(f"Spring Boot {major_version}.x: {' -> '.join([str(current_versions), str(new_versions)])}")
262247
else:

0 commit comments

Comments
 (0)