Skip to content

Commit d86ac2f

Browse files
committed
refactor: optimize version handling and download URL construction for macOS and Windows
1 parent 03d3d36 commit d86ac2f

3 files changed

Lines changed: 151 additions & 112 deletions

File tree

assets/get_all_otp_versions.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def update_all_version_from_github_api():
1010
url = f"https://api.github.com/repos/erlang/otp/tags?per_page=100&sort=pushed&page={page}"
1111
response = requests.get(url)
1212
data = response.json()
13-
all_version = all_version + data
13+
all_version.extend(data)
1414
if response.status_code != 200:
1515
print("Failed to fetch data from github api")
1616
return
@@ -27,7 +27,7 @@ def get_all_prebuilt_version_from_bob():
2727
for release in ALLOW_OS_RELEASE:
2828
url = f"https://builds.hex.pm/builds/otp/{release}/builds.txt"
2929
response = requests.get(url)
30-
all_version_info = response.text.split("\n")
30+
all_version_info.extend(response.text.split("\n"))
3131

3232
all_prebuilt_versions = []
3333
for version in all_version_info:
@@ -82,8 +82,12 @@ def get_macos_prebuilt_versions():
8282
break
8383

8484
if has_macos_assets:
85-
all_versions.append(tag_name)
86-
print(f"Found macOS version: {tag_name}")
85+
# Remove 'OTP-' prefix except for special versions like master-latest
86+
processed_version = tag_name
87+
if processed_version.startswith("OTP-"):
88+
processed_version = processed_version[4:] # Remove 'OTP-' prefix
89+
all_versions.append(processed_version)
90+
print(f"Found macOS version: {tag_name} -> {processed_version}")
8791

8892
page += 1
8993
# Limit maximum pages to avoid infinite loop

assets/macos_prebuilt_versions.txt

Lines changed: 94 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -3,97 +3,97 @@ maint-latest
33
maint-27-latest
44
maint-26-latest
55
maint-25-latest
6-
OTP-28.0.1
7-
OTP-28.0-rc4
8-
OTP-28.0-rc3
9-
OTP-28.0-rc2
10-
OTP-28.0-rc1
11-
OTP-28.0
12-
OTP-27.3.4.1
13-
OTP-27.3.4
14-
OTP-27.3.3
15-
OTP-27.3.2
16-
OTP-27.3.1
17-
OTP-27.3
18-
OTP-27.2.4
19-
OTP-27.2.3
20-
OTP-27.2.2
21-
OTP-27.2.1
22-
OTP-27.2
23-
OTP-27.1.3
24-
OTP-27.1.2
25-
OTP-27.1.1
26-
OTP-27.1
27-
OTP-27.0.1
28-
OTP-27.0-rc3
29-
OTP-27.0-rc2
30-
OTP-27.0-rc1
31-
OTP-27.0
32-
OTP-26.2.5.9
33-
OTP-26.2.5.8
34-
OTP-26.2.5.7
35-
OTP-26.2.5.6
36-
OTP-26.2.5.5
37-
OTP-26.2.5.4
38-
OTP-26.2.5.3
39-
OTP-26.2.5.2
40-
OTP-26.2.5.13
41-
OTP-26.2.5.12
42-
OTP-26.2.5.11
43-
OTP-26.2.5.10
44-
OTP-26.2.5.1
45-
OTP-26.2.5
46-
OTP-26.2.4
47-
OTP-26.2.3
48-
OTP-26.2.2
49-
OTP-26.2.1
50-
OTP-26.2
51-
OTP-26.1.2
52-
OTP-26.1.1
53-
OTP-26.1
54-
OTP-26.0.2
55-
OTP-26.0.1
56-
OTP-26.0-rc3
57-
OTP-26.0-rc2
58-
OTP-26.0-rc1
59-
OTP-26.0
60-
OTP-25.3.2.9
61-
OTP-25.3.2.8
62-
OTP-25.3.2.7
63-
OTP-25.3.2.6
64-
OTP-25.3.2.5
65-
OTP-25.3.2.4
66-
OTP-25.3.2.3
67-
OTP-25.3.2.21
68-
OTP-25.3.2.20
69-
OTP-25.3.2.2
70-
OTP-25.3.2.19
71-
OTP-25.3.2.18
72-
OTP-25.3.2.17
73-
OTP-25.3.2.16
74-
OTP-25.3.2.15
75-
OTP-25.3.2.14
76-
OTP-25.3.2.13
77-
OTP-25.3.2.12
78-
OTP-25.3.2.11
79-
OTP-25.3.2.10
80-
OTP-25.3.2.1
81-
OTP-25.3.2
82-
OTP-25.3.1
83-
OTP-25.3
84-
OTP-25.2.3
85-
OTP-25.2.2
86-
OTP-25.2.1
87-
OTP-25.2
88-
OTP-25.1.2.1
89-
OTP-25.1.2
90-
OTP-25.1.1
91-
OTP-25.1
92-
OTP-25.0.4
93-
OTP-25.0.3
94-
OTP-25.0.2
95-
OTP-25.0.1
96-
OTP-25.0-rc3
97-
OTP-25.0-rc2
98-
OTP-25.0-rc1
99-
OTP-25.0
6+
28.0.1
7+
28.0-rc4
8+
28.0-rc3
9+
28.0-rc2
10+
28.0-rc1
11+
28.0
12+
27.3.4.1
13+
27.3.4
14+
27.3.3
15+
27.3.2
16+
27.3.1
17+
27.3
18+
27.2.4
19+
27.2.3
20+
27.2.2
21+
27.2.1
22+
27.2
23+
27.1.3
24+
27.1.2
25+
27.1.1
26+
27.1
27+
27.0.1
28+
27.0-rc3
29+
27.0-rc2
30+
27.0-rc1
31+
27.0
32+
26.2.5.9
33+
26.2.5.8
34+
26.2.5.7
35+
26.2.5.6
36+
26.2.5.5
37+
26.2.5.4
38+
26.2.5.3
39+
26.2.5.2
40+
26.2.5.13
41+
26.2.5.12
42+
26.2.5.11
43+
26.2.5.10
44+
26.2.5.1
45+
26.2.5
46+
26.2.4
47+
26.2.3
48+
26.2.2
49+
26.2.1
50+
26.2
51+
26.1.2
52+
26.1.1
53+
26.1
54+
26.0.2
55+
26.0.1
56+
26.0-rc3
57+
26.0-rc2
58+
26.0-rc1
59+
26.0
60+
25.3.2.9
61+
25.3.2.8
62+
25.3.2.7
63+
25.3.2.6
64+
25.3.2.5
65+
25.3.2.4
66+
25.3.2.3
67+
25.3.2.21
68+
25.3.2.20
69+
25.3.2.2
70+
25.3.2.19
71+
25.3.2.18
72+
25.3.2.17
73+
25.3.2.16
74+
25.3.2.15
75+
25.3.2.14
76+
25.3.2.13
77+
25.3.2.12
78+
25.3.2.11
79+
25.3.2.10
80+
25.3.2.1
81+
25.3.2
82+
25.3.1
83+
25.3
84+
25.2.3
85+
25.2.2
86+
25.2.1
87+
25.2
88+
25.1.2.1
89+
25.1.2
90+
25.1.1
91+
25.1
92+
25.0.4
93+
25.0.3
94+
25.0.2
95+
25.0.1
96+
25.0-rc3
97+
25.0-rc2
98+
25.0-rc1
99+
25.0

hooks/pre_install.lua

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,18 @@ function PLUGIN:PreInstall(ctx)
1616
local download_url
1717
local PRE_BUILT_OS_RELEASE = erlangUtils.get_config_from_env("USE_PREBUILT_OTP")
1818
if RUNTIME.osType == "windows" then
19+
-- For Windows, always use OTP- prefix for regular versions
20+
local win_tag = erlang_version
21+
if not (string.match(erlang_version, "latest$") or string.match(erlang_version, "^maint%-")) then
22+
win_tag = "OTP-" .. erlang_version
23+
end
24+
1925
if RUNTIME.archType == "amd64" then
20-
download_url = "https://github.com/erlang/otp/releases/download/OTP-" ..
21-
erlang_version .. "/otp_win64_" .. erlang_version .. ".exe"
26+
download_url = "https://github.com/erlang/otp/releases/download/" ..
27+
win_tag .. "/otp_win64_" .. erlang_version .. ".exe"
2228
else
23-
download_url = "https://github.com/erlang/otp/releases/download/OTP-" ..
24-
erlang_version .. "/otp_win32_" .. erlang_version .. ".exe"
29+
download_url = "https://github.com/erlang/otp/releases/download/" ..
30+
win_tag .. "/otp_win32_" .. erlang_version .. ".exe"
2531
end
2632
elseif RUNTIME.osType == "linux" and PRE_BUILT_OS_RELEASE then
2733
local SUPPORT_OS_RELEASE = { "ubuntu-14.04", "ubuntu-16.04", "ubuntu-18.04", "ubuntu-20.04", "ubuntu-22.04",
@@ -47,26 +53,55 @@ function PLUGIN:PreInstall(ctx)
4753
RUNTIME.archType .. ". Supported architectures: amd64, x86_64, arm64, aarch64")
4854
end
4955

56+
-- Prepare tag name and file prefix for download URL
57+
-- Special versions like master-latest, maint-latest etc. don't need OTP- prefix
58+
-- Regular versions like 28.0.1 need OTP- prefix for GitHub tag but not for filename
59+
local tag_name = erlang_version
60+
local file_prefix = erlang_version
61+
62+
if not (string.match(erlang_version, "latest$") or string.match(erlang_version, "^maint%-")) then
63+
-- Regular version like "28.0.1" -> tag should be "OTP-28.0.1"
64+
tag_name = "OTP-" .. erlang_version
65+
file_prefix = "OTP-" .. erlang_version
66+
end
67+
5068
-- Use different URL patterns based on architecture
5169
if mapped_arch == "aarch64" then
5270
-- https://github.com/erlef/otp_builds/releases/download/maint-25-latest/otp-aarch64-apple-darwin.tar.gz
5371
download_url = "https://github.com/erlef/otp_builds/releases/download/" ..
54-
erlang_version .. "/otp-aarch64-apple-darwin.tar.gz"
72+
tag_name .. "/otp-aarch64-apple-darwin.tar.gz"
5573
elseif mapped_arch == "arm64" then
56-
-- https://github.com/erlef/otp_builds/releases/download/OTP-28.0.1/OTP-28.0.1-macos-arm64.tar.gz
57-
download_url = "https://github.com/erlef/otp_builds/releases/download/" ..
58-
erlang_version .. "/" .. erlang_version .. "-macos-arm64.tar.gz"
74+
if string.match(erlang_version, "latest$") or string.match(erlang_version, "^maint%-") then
75+
-- For latest versions: use aarch64 naming for arm64
76+
download_url = "https://github.com/erlef/otp_builds/releases/download/" ..
77+
tag_name .. "/otp-aarch64-apple-darwin.tar.gz"
78+
else
79+
-- For regular versions: https://github.com/erlef/otp_builds/releases/download/OTP-28.0.1/OTP-28.0.1-macos-arm64.tar.gz
80+
download_url = "https://github.com/erlef/otp_builds/releases/download/" ..
81+
tag_name .. "/" .. file_prefix .. "-macos-arm64.tar.gz"
82+
end
5983
elseif mapped_arch == "amd64" then
60-
-- https://github.com/erlef/otp_builds/releases/download/OTP-28.0.1/OTP-28.0.1-macos-amd64.tar.gz
61-
download_url = "https://github.com/erlef/otp_builds/releases/download/" ..
62-
erlang_version .. "/" .. erlang_version .. "-macos-amd64.tar.gz"
84+
if string.match(erlang_version, "latest$") or string.match(erlang_version, "^maint%-") then
85+
-- For latest versions: use x86_64 naming for amd64
86+
download_url = "https://github.com/erlef/otp_builds/releases/download/" ..
87+
tag_name .. "/otp-x86_64-apple-darwin.tar.gz"
88+
else
89+
-- For regular versions: https://github.com/erlef/otp_builds/releases/download/OTP-28.0.1/OTP-28.0.1-macos-amd64.tar.gz
90+
download_url = "https://github.com/erlef/otp_builds/releases/download/" ..
91+
tag_name .. "/" .. file_prefix .. "-macos-amd64.tar.gz"
92+
end
6393
elseif mapped_arch == "x86_64" then
64-
-- https://github.com/erlef/otp_builds/releases/download/OTP-28.0.1/otp-x86_64-apple-darwin.tar.gz
94+
-- For x86_64, always use the same naming pattern as aarch64
6595
download_url = "https://github.com/erlef/otp_builds/releases/download/" ..
66-
erlang_version .. "/otp-x86_64-apple-darwin.tar.gz"
96+
tag_name .. "/otp-x86_64-apple-darwin.tar.gz"
6797
end
6898
else
69-
download_url = "https://github.com/erlang/otp/archive/refs/tags/OTP-" .. erlang_version .. ".tar.gz"
99+
-- For source code download, always use OTP- prefix for regular versions
100+
local source_tag = erlang_version
101+
if not (string.match(erlang_version, "latest$") or string.match(erlang_version, "^maint%-")) then
102+
source_tag = "OTP-" .. erlang_version
103+
end
104+
download_url = "https://github.com/erlang/otp/archive/refs/tags/" .. source_tag .. ".tar.gz"
70105
end
71106

72107
print("Download Erlang/OTP from " .. download_url)

0 commit comments

Comments
 (0)