Skip to content

Commit c21816c

Browse files
committed
Update NT determining logic
1 parent 92ea2ae commit c21816c

1 file changed

Lines changed: 29 additions & 32 deletions

File tree

.github/scripts/determine-nt-version.py

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -37,51 +37,48 @@
3737
if best_match:
3838
print(f"Best matching range: {best_match}")
3939

40-
# Get the major version to look for in tags
40+
# Get the major version to look for in releases
4141
max_pattern = version_data[best_match].get("max", "")
42-
major_version = max_pattern.split('.')[0]
43-
44-
print(f"Looking for latest version with major version: {major_version}")
42+
if max_pattern == "*":
43+
major_version = None
44+
print("Looking for latest available release (no major version restriction)")
45+
else:
46+
major_version = max_pattern.split('.')[0]
47+
print(f"Looking for latest release with major version: {major_version}")
4548

46-
# Get available tags from native-template repository
47-
response = requests.get('https://api.github.com/repos/mendix/native-template/tags')
49+
# Get available releases from native-template repository
50+
response = requests.get('https://api.github.com/repos/mendix/native-template/releases')
4851
if response.status_code == 200:
49-
all_tags = response.json()
50-
tag_names = [tag['name'] for tag in all_tags]
51-
print(f"Available tags: {tag_names}")
52+
all_releases = response.json()
53+
release_names = [release['tag_name'] for release in all_releases]
54+
print(f"Available releases: {release_names}")
5255

53-
# Find the latest version matching the major version
54-
matching_tags = []
56+
# Find the latest release matching the major version
57+
matching_releases = []
5558

56-
for tag in tag_names:
57-
# Remove 'v' prefix if present for comparison
59+
for release in all_releases:
60+
tag = release['tag_name']
5861
clean_tag = tag[1:] if tag.startswith('v') else tag
59-
60-
# Check if the tag starts with the major version
61-
if clean_tag.startswith(f"{major_version}."):
62-
try:
63-
# Try to parse as a version (this handles proper version numbers)
64-
tag_version = version.parse(clean_tag)
65-
matching_tags.append((tag, tag_version))
66-
except:
67-
# Skip tags that don't parse as proper versions
68-
pass
62+
try:
63+
tag_version = version.parse(clean_tag)
64+
if major_version is None or clean_tag.startswith(f"{major_version}."):
65+
matching_releases.append((tag, tag_version))
66+
except:
67+
pass
6968

70-
if matching_tags:
71-
# Sort by version (highest last) and get the last one
72-
matching_tags.sort(key=lambda x: x[1])
73-
latest_version = matching_tags[-1][0]
74-
print(f"Selected Native Template version: {latest_version}")
69+
if matching_releases:
70+
matching_releases.sort(key=lambda x: x[1])
71+
latest_tag = matching_releases[-1][0]
72+
print(f"Selected Native Template release: {latest_tag}")
7573
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
76-
f.write(f"nt_branch={latest_version}\n")
74+
f.write(f"nt_branch={latest_tag}\n")
7775
else:
78-
# Fallback to min version if no matching tag found
7976
min_version = version_data[best_match].get("min", "")
80-
print(f"No matching tag found, using minimum version: {min_version}")
77+
print(f"No matching release found, using minimum version: {min_version}")
8178
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
8279
f.write(f"nt_branch={min_version}\n")
8380
else:
84-
print(f"Failed to get tags: {response.status_code}")
81+
print(f"Failed to get releases: {response.status_code}")
8582
print("Using master as fallback")
8683
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
8784
f.write("nt_branch=master\n")

0 commit comments

Comments
 (0)