Skip to content

Commit 11becad

Browse files
committed
build: update Elixir version and caching config
1 parent 85d45b2 commit 11becad

10 files changed

Lines changed: 934 additions & 705 deletions

.github/workflows/update_elixir_versions.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# for vfox search
12
name: update_elixir_versions
23

34
on:
@@ -35,6 +36,9 @@ jobs:
3536
git add .
3637
git commit -m "chore(versions.txt): update Elixir version file"
3738
git push https://github-actions[bot]:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
39+
curl https://purge.jsdelivr.net/gh/version-fox/vfox-elixir@main/assets/versions.txt
40+
curl https://purge.jsdelivr.net/gh/version-fox/vfox-elixir@main/assets/versions_win.txt
41+
echo "refreshed jsdelivr cache."
3842
else
3943
echo "never updated."
4044
fi

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.idea
2-
.available.cache
2+
.available.cache
3+
.venv

assets/.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.11

assets/elixir_versions_from_github_api.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,8 +1744,8 @@
17441744
"zipball_url": "https://api.github.com/repos/elixir-lang/elixir/zipball/refs/tags/main-latest",
17451745
"tarball_url": "https://api.github.com/repos/elixir-lang/elixir/tarball/refs/tags/main-latest",
17461746
"commit": {
1747-
"sha": "43aeded37749cd2655842116ebf214e556b6e24f",
1748-
"url": "https://api.github.com/repos/elixir-lang/elixir/commits/43aeded37749cd2655842116ebf214e556b6e24f"
1747+
"sha": "9cc24c9d9284494541f3f2f229f9c68123546456",
1748+
"url": "https://api.github.com/repos/elixir-lang/elixir/commits/9cc24c9d9284494541f3f2f229f9c68123546456"
17491749
},
17501750
"node_id": "MDM6UmVmMTIzNDcxNDpyZWZzL3RhZ3MvbWFpbi1sYXRlc3Q="
17511751
}

assets/elixir_windows_versions_from_github_api.json

Lines changed: 632 additions & 632 deletions
Large diffs are not rendered by default.

assets/get_all_elixir_versions.py

Lines changed: 89 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
1+
# --*- coding: utf-8 --*-
2+
"""Fetch all Elixir versions from GitHub API and save to a local file."""
3+
14
import json
5+
import re
26
import requests
37
from packaging import version
48

9+
510
# fetch version: -> https://api.github.com/repos/elixir-lang/elixir/tags?per_page=100&sort=pushed
611
# github api has rate limt
712
# prefer use local version file
813
def update_all_version_from_github_api():
14+
"""Fetch all Elixir version tags from GitHub API and save to local JSON file.
15+
16+
Makes paginated requests to GitHub API to retrieve all available Elixir version tags.
17+
The fetched data is saved to 'elixir_versions_from_github_api.json' for local use
18+
to avoid hitting GitHub API rate limits on subsequent runs.
19+
20+
Note:
21+
GitHub API has rate limits, so prefer using the local version file when possible.
22+
"""
923
all_version = []
10-
for page in range(1,10):
11-
url = f"https://api.github.com/repos/elixir-lang/elixir/tags?per_page=100&sort=pushed&page={page}"
12-
response = requests.get(url)
24+
for page in range(1, 10):
25+
url = (
26+
f"https://api.github.com/repos/elixir-lang/elixir/tags"
27+
f"?per_page=100&sort=pushed&page={page}"
28+
)
29+
response = requests.get(url, timeout=30)
1330
if response.status_code != 200:
1431
print("Failed to fetch data from github api")
1532
return
@@ -18,45 +35,93 @@ def update_all_version_from_github_api():
1835
data = response.json()
1936
all_version = all_version + data
2037

21-
22-
with open("elixir_versions_from_github_api.json", 'w', encoding="utf-8") as file:
38+
with open("elixir_versions_from_github_api.json", "w", encoding="utf-8") as file:
2339
json.dump(all_version, file, indent=4)
2440

41+
2542
def get_all_version():
43+
"""Extract all Elixir version numbers from GitHub API data.
44+
45+
Reads the local JSON file containing GitHub API response data and extracts
46+
version numbers from tarball URLs that contain 'refs/tags/v' pattern.
47+
48+
Returns:
49+
set: A set of version strings extracted from the GitHub API data.
50+
"""
2651
version_set = set()
27-
with open("elixir_versions_from_github_api.json", 'r', encoding="utf-8") as file:
52+
with open("elixir_versions_from_github_api.json", "r", encoding="utf-8") as file:
2853
data = json.load(file)
2954
for item in data:
3055
if "refs/tags/" not in item["tarball_url"]:
3156
continue
3257
split_info = item["tarball_url"].split("refs/tags/v")
3358
if len(split_info) > 1:
34-
version = split_info[1]
35-
version_set.add(version)
59+
version_str = split_info[1]
60+
version_set.add(version_str)
3661
return version_set
3762

38-
def parse_version(ver):
63+
64+
def parse_version(version_string):
65+
"""Parse a version string and return parsing result with metadata.
66+
67+
Attempts to parse a version string using the packaging library's version parser.
68+
Returns a tuple containing the parsed version (or original string if invalid),
69+
a boolean indicating parsing success, and the original version string.
70+
71+
Args:
72+
version_string (str): The version string to parse.
73+
74+
Returns:
75+
tuple: A 3-tuple containing:
76+
- Parsed version object (or original string if invalid)
77+
- Boolean indicating if parsing was successful
78+
- Original version string
79+
"""
3980
try:
40-
return version.parse(ver), True
81+
return version.parse(version_string), True, version_string
4182
except version.InvalidVersion:
42-
print(f"Invalid version: {ver}")
43-
return ver, False
83+
print(f"Invalid version: {version_string}")
84+
return version_string, False, version_string
85+
86+
87+
def custom_version_sort_key(ver_tuple):
88+
"""Custom sorting key, prioritize semantic versions, sort invalid versions by string"""
89+
parsed_ver, is_valid_ver, original_ver = ver_tuple
90+
if is_valid_ver:
91+
# Valid semantic version, return (0, parsed_version) to ensure it comes first
92+
return (0, parsed_ver)
93+
94+
# Invalid version, try to extract numeric part for sorting
95+
# Try to match version pattern, e.g. "1.18-latest" -> "1.18"
96+
match = re.match(r"^(\d+(?:\.\d+)*)", original_ver)
97+
if match:
98+
try:
99+
# Extract numeric part and parse
100+
numeric_part = match.group(1)
101+
parsed_numeric = version.parse(numeric_part)
102+
return (
103+
1,
104+
parsed_numeric,
105+
original_ver,
106+
) # After valid versions, but sorted by numeric part
107+
except version.InvalidVersion:
108+
pass
109+
# Completely unparseable versions, sort by string
110+
return (2, original_ver)
111+
44112

45113
if __name__ == "__main__":
46114
update_all_version_from_github_api()
47115
versions = list(get_all_version())
48-
valid_versions = [] # semantic version
49-
invalid_versions = []
116+
version_tuples = []
50117
for v in versions:
51-
ver, is_valid = parse_version(v)
52-
if is_valid:
53-
valid_versions.append(ver)
54-
continue
55-
invalid_versions.append(ver)
118+
ver, is_valid, original = parse_version(v)
119+
version_tuples.append((ver, is_valid, original))
120+
121+
# Sort using custom sorting key
122+
sorted_versions = sorted(version_tuples, key=custom_version_sort_key, reverse=True)
56123

57-
versions = sorted(valid_versions, reverse=True)
58124
with open("versions.txt", "w", encoding="utf-8") as file:
59-
for v in versions:
60-
file.write(str(v) + '\n')
61-
for v in invalid_versions:
62-
file.write(v + '\n')
125+
for v_tuple in sorted_versions:
126+
_, _, original = v_tuple
127+
file.write(original + "\n")

assets/get_all_elixir_win_versions.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import json
22
import requests
33

4+
45
# fetch version: -> https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28
56
# github api has rate limt
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/elixir-lang/elixir/releases?page={page}&per_page=100"
1112
response = requests.get(url)
1213
if response.status_code != 200:
@@ -18,13 +19,17 @@ def update_all_version_from_github_api():
1819
data = response.json()
1920
all_version = all_version + data
2021

21-
22-
with open("elixir_windows_versions_from_github_api.json", 'w', encoding="utf-8") as file:
22+
with open(
23+
"elixir_windows_versions_from_github_api.json", "w", encoding="utf-8"
24+
) as file:
2325
json.dump(all_version, file, indent=4)
2426

27+
2528
def get_all_version():
2629
version_set = set()
27-
with open("elixir_windows_versions_from_github_api.json", 'r', encoding="utf-8") as file:
30+
with open(
31+
"elixir_windows_versions_from_github_api.json", "r", encoding="utf-8"
32+
) as file:
2833
data = json.load(file)
2934
for item in data:
3035
for asset in item["assets"]:
@@ -35,11 +40,12 @@ def get_all_version():
3540
version_set.add(fix_version.replace(".exe", "")[1:])
3641
return version_set
3742

43+
3844
if __name__ == "__main__":
3945
update_all_version_from_github_api()
4046
versions = list(get_all_version())
4147
versions = sorted(versions, reverse=True)
4248
print(versions)
43-
with open("versions_win.txt", 'w') as file:
49+
with open("versions_win.txt", "w") as file:
4450
for v in versions:
45-
file.write(v + '\n')
51+
file.write(v + "\n")

assets/pyproject.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[project]
2+
name = "elixir"
3+
version = "0.1.0"
4+
description = "Add your description here"
5+
readme = "README.md"
6+
requires-python = ">=3.11"
7+
dependencies = [
8+
"packaging>=25.0",
9+
"requests>=2.32.5",
10+
]

0 commit comments

Comments
 (0)