Skip to content

Commit b28564b

Browse files
committed
Harden workflow triggers and version comparison
1 parent 3ad4064 commit b28564b

5 files changed

Lines changed: 69 additions & 81 deletions

.github/workflows/test-spring-boot-rc-version.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
name: Test Spring Boot RC Version
22
on:
3-
pull_request:
4-
branches:
5-
- main
6-
paths:
7-
- '.github/workflows/test-spring-boot-rc-version.yml'
8-
- 'sdk/spring/scripts/generate_spring_versions_and_pr_description.py'
9-
- 'sdk/spring/scripts/generate_spring_cloud_azure_support_file.py'
10-
- 'sdk/spring/scripts/**'
113
workflow_dispatch:
124

135
permissions:

.github/workflows/update-spring-cloud-azure-support-file.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@ name: Update Spring Cloud Azure Support File
22
on:
33
schedule:
44
- cron: '0 0 * * *'
5-
pull_request:
6-
branches:
7-
- main
8-
paths:
9-
- '.github/workflows/update-spring-cloud-azure-support-file.yml'
10-
- 'sdk/spring/scripts/generate_spring_cloud_azure_support_file.py'
115
workflow_dispatch:
126

137
env:

.github/workflows/update-spring-dependencies.yml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@ name: Update Spring Dependencies
22
on:
33
schedule:
44
- cron: '0 0 * * *'
5-
pull_request:
6-
branches:
7-
- main
8-
paths:
9-
- '.github/workflows/update-spring-dependencies.yml'
10-
- 'sdk/spring/scripts/generate_spring_versions_and_pr_description.py'
11-
- 'sdk/spring/scripts/generate_spring_cloud_azure_support_file.py'
12-
- 'sdk/spring/scripts/**'
135
workflow_dispatch:
146

157
env:
@@ -34,7 +26,7 @@ jobs:
3426
with:
3527
script: |
3628
const prTitlePrefix = process.env.PR_TITLE_PREFIX;
37-
const { data: pullRequests } = await github.rest.pulls.list({
29+
const pullRequests = await github.paginate(github.rest.pulls.list, {
3830
owner: context.repo.owner,
3931
repo: context.repo.repo,
4032
state: 'open',

sdk/spring/scripts/generate_spring_cloud_azure_support_file.py

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,46 @@
1313
NONE_SUPPORTED = "NONE_SUPPORTED_SPRING_CLOUD_VERSION"
1414

1515

16+
def version_key(version):
17+
match = re.match(r"^(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:[-.]?([A-Za-z]+)(\d*)?)?$", version)
18+
if not match:
19+
return (0, 0, 0, 0, 0, version)
20+
21+
major = int(match.group(1) or 0)
22+
minor = int(match.group(2) or 0)
23+
patch = int(match.group(3) or 0)
24+
qualifier = (match.group(4) or "").upper()
25+
qualifier_num = int(match.group(5) or 0)
26+
27+
# Higher rank means newer release status for the same base version.
28+
if not qualifier:
29+
qualifier_rank = 3 # GA
30+
elif qualifier.startswith("RC"):
31+
qualifier_rank = 2
32+
elif qualifier.startswith("M"):
33+
qualifier_rank = 1
34+
elif qualifier.startswith("SNAPSHOT"):
35+
qualifier_rank = 0
36+
else:
37+
qualifier_rank = 0
38+
39+
return (major, minor, patch, qualifier_rank, qualifier_num, qualifier)
40+
41+
1642
def fetch_json(url):
1743
req = urllib.request.Request(url, headers={"User-Agent": "spring-cloud-azure-tools-migration"})
1844
with urllib.request.urlopen(req, timeout=30) as resp:
1945
return json.loads(resp.read().decode("utf-8"))
2046

2147

22-
def tokenize_version(version):
23-
tokens = []
24-
for part in re.split(r"[.\-]", version):
25-
if part.isdigit():
26-
tokens.append((0, int(part)))
27-
else:
28-
upper = part.upper()
29-
if upper.startswith("SNAPSHOT"):
30-
tokens.append((1, -3))
31-
elif upper.startswith("M") and upper[1:].isdigit():
32-
tokens.append((1, -2, int(upper[1:])))
33-
elif upper.startswith("RC") and upper[2:].isdigit():
34-
tokens.append((1, -1, int(upper[2:])))
35-
else:
36-
tokens.append((1, upper))
37-
return tokens
38-
39-
4048
def compare_versions(a, b):
41-
ta = tokenize_version(a)
42-
tb = tokenize_version(b)
43-
max_len = max(len(ta), len(tb))
44-
for i in range(max_len):
45-
va = ta[i] if i < len(ta) else (0, 0)
46-
vb = tb[i] if i < len(tb) else (0, 0)
47-
if va == vb:
48-
continue
49-
return -1 if va < vb else 1
50-
return 0
49+
ka = version_key(a)
50+
kb = version_key(b)
51+
if ka == kb:
52+
return 0
53+
if ka < kb:
54+
return -1
55+
return 1
5156

5257

5358
def parse_range_expression(expr):
@@ -174,7 +179,7 @@ def main():
174179
snapshot_items.append(cloned)
175180

176181
result = current_items + snapshot_items
177-
result.sort(key=lambda item: tokenize_version(item.get("spring-boot-version", "0")), reverse=True)
182+
result.sort(key=lambda item: version_key(item.get("spring-boot-version", "0")), reverse=True)
178183

179184
os.makedirs(os.path.dirname(SUPPORT_FILE), exist_ok=True)
180185
with open(SUPPORT_FILE, "w", encoding="utf-8") as f:

sdk/spring/scripts/generate_spring_versions_and_pr_description.py

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,45 +18,50 @@
1818
PR_DESCRIPTIONS_OUTPUT = "pr-descriptions.txt"
1919

2020

21+
def version_key(version):
22+
match = re.match(r"^(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:[-.]?([A-Za-z]+)(\d*)?)?$", version)
23+
if not match:
24+
return (0, 0, 0, 0, 0, version)
25+
26+
major = int(match.group(1) or 0)
27+
minor = int(match.group(2) or 0)
28+
patch = int(match.group(3) or 0)
29+
qualifier = (match.group(4) or "").upper()
30+
qualifier_num = int(match.group(5) or 0)
31+
32+
# Higher rank means newer release status for the same base version.
33+
if not qualifier:
34+
qualifier_rank = 3 # GA
35+
elif qualifier.startswith("RC"):
36+
qualifier_rank = 2
37+
elif qualifier.startswith("M"):
38+
qualifier_rank = 1
39+
elif qualifier.startswith("SNAPSHOT"):
40+
qualifier_rank = 0
41+
else:
42+
qualifier_rank = 0
43+
44+
return (major, minor, patch, qualifier_rank, qualifier_num, qualifier)
45+
46+
2147
def fetch_json(url):
2248
req = urllib.request.Request(url, headers={"User-Agent": "spring-cloud-azure-tools-migration"})
2349
with urllib.request.urlopen(req, timeout=30) as resp:
2450
return json.loads(resp.read().decode("utf-8"))
2551

2652

27-
def tokenize_version(version):
28-
tokens = []
29-
for part in re.split(r"[.\-]", version):
30-
if part.isdigit():
31-
tokens.append((0, int(part)))
32-
else:
33-
upper = part.upper()
34-
if upper.startswith("SNAPSHOT"):
35-
tokens.append((1, -3))
36-
elif upper.startswith("M") and upper[1:].isdigit():
37-
tokens.append((1, -2, int(upper[1:])))
38-
elif upper.startswith("RC") and upper[2:].isdigit():
39-
tokens.append((1, -1, int(upper[2:])))
40-
else:
41-
tokens.append((1, upper))
42-
return tokens
43-
44-
4553
def compare_versions(a, b):
46-
ta = tokenize_version(a)
47-
tb = tokenize_version(b)
48-
max_len = max(len(ta), len(tb))
49-
for i in range(max_len):
50-
va = ta[i] if i < len(ta) else (0, 0)
51-
vb = tb[i] if i < len(tb) else (0, 0)
52-
if va == vb:
53-
continue
54-
return -1 if va < vb else 1
55-
return 0
54+
ka = version_key(a)
55+
kb = version_key(b)
56+
if ka == kb:
57+
return 0
58+
if ka < kb:
59+
return -1
60+
return 1
5661

5762

5863
def sort_versions_desc(versions):
59-
return sorted(versions, key=lambda v: tokenize_version(v), reverse=True)
64+
return sorted(versions, key=version_key, reverse=True)
6065

6166

6267
def read_current_supported_versions():

0 commit comments

Comments
 (0)