|
37 | 37 | if best_match: |
38 | 38 | print(f"Best matching range: {best_match}") |
39 | 39 |
|
40 | | - # Get the major version to look for in tags |
| 40 | + # Get the major version to look for in releases |
41 | 41 | 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}") |
45 | 48 |
|
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') |
48 | 51 | 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}") |
52 | 55 |
|
53 | | - # Find the latest version matching the major version |
54 | | - matching_tags = [] |
| 56 | + # Find the latest release matching the major version |
| 57 | + matching_releases = [] |
55 | 58 |
|
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'] |
58 | 61 | 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 |
69 | 68 |
|
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}") |
75 | 73 | 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") |
77 | 75 | else: |
78 | | - # Fallback to min version if no matching tag found |
79 | 76 | 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}") |
81 | 78 | with open(os.environ['GITHUB_OUTPUT'], 'a') as f: |
82 | 79 | f.write(f"nt_branch={min_version}\n") |
83 | 80 | else: |
84 | | - print(f"Failed to get tags: {response.status_code}") |
| 81 | + print(f"Failed to get releases: {response.status_code}") |
85 | 82 | print("Using master as fallback") |
86 | 83 | with open(os.environ['GITHUB_OUTPUT'], 'a') as f: |
87 | 84 | f.write("nt_branch=master\n") |
|
0 commit comments