Skip to content

Commit e079047

Browse files
Copilotyeshan333
andauthored
Add support for prebuilt Erlang/OTP installations on MacOS using @erlef/otp_builds (#13), close #10
* Initial plan * Add MacOS prebuilt support using @erlef/otp_builds Co-authored-by: yeshan333 <39296814+yeshan333@users.noreply.github.com> * Improve MacOS prebuilt file organization logic Co-authored-by: yeshan333 <39296814+yeshan333@users.noreply.github.com> * feat: add support for macOS prebuilt versions and update related configurations * fix: macos prebuilt download link * feat: fetch macOS prebuilt versions and integrate into version update workflow * refactor: optimize version handling and download URL construction for macOS and Windows * fix: update USE_PREBUILT_OTP environment variable to boolean and remove obsolete test script [skip ci]. * fix: update macOS prebuilt versions URL to point to the main branch [skip ci] --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: yeshan333 <39296814+yeshan333@users.noreply.github.com> Co-authored-by: yeshan.ye <yeshan.ye@alibaba-inc.com>
1 parent 518b651 commit e079047

9 files changed

Lines changed: 382 additions & 31 deletions
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: E2E tests on Darwin MacOS (Prebuilt release)
2+
3+
on:
4+
push:
5+
# branches: [main]
6+
pull_request:
7+
workflow_dispatch:
8+
schedule:
9+
# Runs at 12am UTC
10+
- cron: '0 0 * * *'
11+
12+
jobs:
13+
e2e_tests:
14+
strategy:
15+
matrix:
16+
# ref: https://github.com/actions/runner-images
17+
os: [macos-13]
18+
runs-on: ${{ matrix.os }}
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- uses: actions/setup-go@v5
23+
with:
24+
go-version: '^1.24.2' # The Go version to download (if necessary) and use.
25+
26+
- name: build vfox (MacOS)
27+
run: |
28+
git clone https://github.com/version-fox/vfox.git
29+
cd vfox
30+
go build -o vfox
31+
chmod +x vfox
32+
cp vfox /usr/local/bin
33+
34+
- name: add vfox-erlang plugin (Unix-like)
35+
run: |
36+
vfox -version
37+
vfox add --source https://github.com/version-fox/vfox-erlang/archive/${GITHUB_REF}.zip erlang
38+
39+
- name: install Erlang/OTP by vfox-erlang plugin (Darwin prebuilt)
40+
run: |
41+
export USE_PREBUILT_OTP=true
42+
vfox install erlang@26.2.3
43+
vfox use -g erlang@26.2.3
44+
eval "$(vfox activate bash)"
45+
echo "===============PATH==============="
46+
echo $PATH
47+
echo "===============PATH==============="
48+
cd assets
49+
erlc hello.erl
50+
erl -noshell -s hello hello_world -s init stop

.github/workflows/update_otp_versions.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
cd assets
2222
python -m pip install requests
2323
python get_all_otp_versions.py
24+
python get_macos_prebuilt_versions.py
2425
2526
- name: Push updated version file
2627
run: |

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.idea
22
.tool-versions
33
*.beam
4-
available.cache
4+
available.cache
5+
.available.cache

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,32 @@ You can reference the E2E test in in windows-2022: [.github/workflows/e2e_test_w
8585

8686
## install a prebuilt Erlang/OTP version
8787

88-
After vfox-erlang v1.1.0, you can also install a prebuilt Erlang/OTP version in Ubuntu linux system.
88+
After vfox-erlang v1.1.0, you can also install a prebuilt Erlang/OTP version in Ubuntu linux system and MacOS.
8989

9090
**Before install, you must disable vfox search cache.** Reference: [https://vfox.lhan.me/guides/configuration.html#cache-settings](https://vfox.lhan.me/guides/configuration.html#cache-settings)
9191

92+
### Linux (Ubuntu)
93+
9294
This is an installation example in Bash Shell:
9395

9496
```shell
9597
# install an available version, you can also a avaliable version in: https://bobs-list.kobrakai.de/
9698
USE_PREBUILT_OTP="ubuntu-20.04" vfox search erlang
99+
USE_PREBUILT_OTP="ubuntu-20.04" vfox install erlang@26.2.3
100+
```
101+
102+
**USE_PREBUILT_OTP** var value for Linux is one of: ["ubuntu-14.04", "ubuntu-16.04", "ubuntu-18.04", "ubuntu-20.04", "ubuntu-22.04", "ubuntu-24.04"].
103+
104+
### MacOS
105+
106+
For MacOS, you can use prebuilt Erlang/OTP versions from [@erlef/otp_builds](https://github.com/erlef/otp_builds) by setting the `USE_PREBUILT_OTP` environment variable:
107+
108+
```shell
109+
# install a prebuilt version for MacOS (automatically detects architecture)
110+
USE_PREBUILT_OTP=true vfox search erlang
111+
USE_PREBUILT_OTP=true vfox install erlang@26.2.3
97112
```
98113

99-
**USE_PREBUILT_OTP** var value is one of: ["ubuntu-14.04", "ubuntu-16.04", "ubuntu-18.04", "ubuntu-20.04", "ubuntu-22.04", "ubuntu-24.04"].
114+
**USE_PREBUILT_OTP** can be set to any non-empty value (e.g., "1", "true", "macos") to enable prebuilt mode.
115+
116+
Supported architectures: amd64, x86_64, arm64, aarch64. macOS uses a dedicated prebuilt version list that differs from the Ubuntu prebuilt versions.

assets/get_all_otp_versions.py

Lines changed: 102 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,116 @@
11
import json
22
import requests
33

4+
45
# fetch version: -> https://api.github.com/repos/erlang/otp/tags?per_page=100&sort=pushed
56
# github api has rate limt: https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#list-repository-tags
67
# prefer use local version file
78
def update_all_version_from_github_api():
89
all_version = []
9-
for page in range(1,10):
10+
for page in range(1, 10):
1011
url = f"https://api.github.com/repos/erlang/otp/tags?per_page=100&sort=pushed&page={page}"
1112
response = requests.get(url)
1213
data = response.json()
13-
all_version = all_version + data
14+
all_version.extend(data)
1415
if response.status_code != 200:
1516
print("Failed to fetch data from github api")
1617
return
1718

18-
with open("erlang_otp_versions_from_gtihub_api.json", 'w', encoding="utf-8") as file:
19+
with open(
20+
"erlang_otp_versions_from_gtihub_api.json", "w", encoding="utf-8"
21+
) as file:
1922
json.dump(all_version, file, indent=4)
2023

24+
2125
def get_all_prebuilt_version_from_bob():
2226
# ALLOW_OS_RELEASE = ["ubuntu-14.04", "ubuntu-16.04", "ubuntu-18.04", "ubuntu-20.04", "ubuntu-22.04", "ubuntu-24.04"]
2327
ALLOW_OS_RELEASE = ["ubuntu-20.04"]
2428
all_version_info = []
2529
for release in ALLOW_OS_RELEASE:
2630
url = f"https://builds.hex.pm/builds/otp/{release}/builds.txt"
2731
response = requests.get(url)
28-
all_version_info = response.text.split("\n")
29-
32+
all_version_info.extend(response.text.split("\n"))
33+
3034
all_prebuilt_versions = []
3135
for version in all_version_info:
3236
if version.split(" ")[0]:
3337
all_prebuilt_versions.append(version.split(" ")[0])
3438
return all_prebuilt_versions
3539

40+
41+
def get_macos_prebuilt_versions():
42+
"""Fetch all available macOS prebuilt versions from erlef/otp_builds"""
43+
44+
# GitHub API URL for releases
45+
api_url = "https://api.github.com/repos/erlef/otp_builds/releases"
46+
47+
all_versions = []
48+
page = 1
49+
50+
try:
51+
while True:
52+
print(f"Fetching macOS prebuilt versions page {page}...")
53+
url = f"{api_url}?page={page}&per_page=100"
54+
55+
response = requests.get(url)
56+
if response.status_code != 200:
57+
break
58+
59+
releases = response.json()
60+
if not releases:
61+
break
62+
63+
for release in releases:
64+
tag_name = release["tag_name"]
65+
assets = release["assets"]
66+
67+
# Check if there are macOS related assets
68+
has_macos_assets = False
69+
for asset in assets:
70+
asset_name = asset["name"]
71+
# Check if contains macOS related filename patterns
72+
if any(
73+
pattern in asset_name.lower()
74+
for pattern in [
75+
"macos",
76+
"darwin",
77+
"osx",
78+
"aarch64-apple",
79+
"x86_64-apple",
80+
"arm64.tar.gz",
81+
"amd64.tar.gz",
82+
]
83+
):
84+
has_macos_assets = True
85+
break
86+
87+
if has_macos_assets:
88+
# Remove 'OTP-' prefix except for special versions like master-latest
89+
processed_version = tag_name
90+
if processed_version.startswith("OTP-"):
91+
processed_version = processed_version[
92+
4:
93+
] # Remove 'OTP-' prefix
94+
all_versions.append(processed_version)
95+
print(f"Found macOS version: {tag_name} -> {processed_version}")
96+
97+
page += 1
98+
# Limit maximum pages to avoid infinite loop
99+
if page > 20:
100+
break
101+
102+
except Exception as e:
103+
print(f"Error fetching macOS prebuilt data: {e}")
104+
return []
105+
106+
return all_versions
107+
108+
36109
def get_all_version():
37110
version_set = set()
38-
with open("erlang_otp_versions_from_gtihub_api.json", 'r', encoding="utf-8") as file:
111+
with open(
112+
"erlang_otp_versions_from_gtihub_api.json", "r", encoding="utf-8"
113+
) as file:
39114
data = json.load(file)
40115
for item in data:
41116
if "OTP-" not in item["tarball_url"]:
@@ -44,16 +119,33 @@ def get_all_version():
44119
version_set.add(version)
45120
return version_set
46121

122+
47123
if __name__ == "__main__":
48124
update_all_version_from_github_api()
49125
versions = list(get_all_version())
50126
versions.sort(reverse=True)
51127
# print(versions)
52-
with open("versions.txt", 'w') as file:
128+
with open("versions.txt", "w") as file:
53129
for version in versions:
54-
file.write(version + '\n')
55-
with open("prebuilt_versions.txt", 'w') as file:
130+
file.write(version + "\n")
131+
132+
# Generate prebuilt versions for Linux
133+
with open("prebuilt_versions.txt", "w") as file:
56134
prebuilt_versions = get_all_prebuilt_version_from_bob()
57135
prebuilt_versions.sort(reverse=True)
58136
for version in prebuilt_versions:
59-
file.write(version + '\n')
137+
file.write(version + "\n")
138+
139+
# Generate prebuilt versions for macOS
140+
print("\nFetching macOS prebuilt versions...")
141+
macos_versions = get_macos_prebuilt_versions()
142+
if macos_versions:
143+
macos_versions.sort(reverse=True)
144+
with open("macos_prebuilt_versions.txt", "w", encoding="utf-8") as file:
145+
for version in macos_versions:
146+
file.write(version + "\n")
147+
print(
148+
f"Found {len(macos_versions)} macOS prebuilt versions, saved to macos_prebuilt_versions.txt"
149+
)
150+
else:
151+
print("No macOS prebuilt versions found.")

assets/macos_prebuilt_versions.txt

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
master-latest
2+
maint-latest
3+
maint-27-latest
4+
maint-26-latest
5+
maint-25-latest
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

0 commit comments

Comments
 (0)