-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcheck_nodejs.py
89 lines (70 loc) · 2.65 KB
/
check_nodejs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
"""
Fetches Node.js versions for specified major versions from the Node.js previous releases page.
"""
import argparse
import json
import sys
import requests
from bs4 import BeautifulSoup
def get_nodejs_versions(major_versions):
"""
Fetches Node.js versions for specified major versions from the Node.js previous releases page.
Args:
major_versions (list): A list of major versions to filter for.
Returns:
list: A list of Node.js versions that match the specified major versions.
"""
url = "https://nodejs.org/en/about/previous-releases/"
response = requests.get(url, timeout=5)
soup = BeautifulSoup(response.content, "html.parser")
# Find all version numbers on the page
versions = soup.find_all("td", attrs={"data-label": "Version"})
version_list = [
version.get_text().strip().replace("Node.js ", "") for version in versions
]
# Filter for specific major versions
filtered_versions = [
version
for version in version_list
if any(version.startswith("v" + str(major) + ".") for major in major_versions)
]
return filtered_versions
def main():
"""
Fetches Node.js versions for specified major versions from the Node.js previous releases page.
Command-line Arguments:
major_versions (str): A string of major versions separated by commas.
"""
parser = argparse.ArgumentParser(
description="Fetch Node.js versions for specific major versions."
)
parser.add_argument(
"major_versions",
type=str,
help="Comma-separated list of major versions to fetch",
)
args = parser.parse_args()
# Convert comma-separated string to list of integers
major_versions = [int(major) for major in args.major_versions.split(",")]
# Get Node.js versions
nodejs_versions = get_nodejs_versions(major_versions)
# Read current versions from versions.json
with open("versions.json", encoding="utf-8") as f:
current_versions = json.load(f)["nodejs"]
# Check for updates and set NODE_VERSIONS_TO_BUILD
updated_versions = []
for version in nodejs_versions:
major = version[1:].split(".")[0]
if major in current_versions:
if version != current_versions[major]["version"]:
updated_versions.append(version)
else:
# Log a error if the major version is not found
print(
f"Error: Major version {major} not found in current versions.",
file=sys.stderr,
)
if updated_versions:
print(",".join(version[1:] for version in updated_versions))
if __name__ == "__main__":
main()