Skip to content

Commit 9a362a5

Browse files
Notify if dependency releases a major version (#41377)
* Notify if dependency releases a major version * Renaming and taking co pilot suggestions * black fixes * spell fixes * black fixes
1 parent 412f3b7 commit 9a362a5

File tree

3 files changed

+93
-1
lines changed

3 files changed

+93
-1
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Check the dependencies for major version updates in azure-ai-ml
2+
# This workflow checks for major version updates in the azure-ai-ml package
3+
on:
4+
schedule:
5+
- cron: "0 0,12 * * *" # Runs at 00:00 and 12:00 UTC
6+
workflow_dispatch: # Optional manual trigger
7+
8+
jobs:
9+
build-and-test:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
14+
- name: Set up Python 3.11
15+
uses: actions/setup-python@v4
16+
with:
17+
python-version: 3.11
18+
19+
- name: Run Script
20+
run: python sdk/ml/azure-ai-ml/scripts/major_updates.py

sdk/ml/azure-ai-ml/cspell.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"faiss",
1414
"Faiss",
1515
"LLMRAG",
16-
"expirable"
16+
"expirable",
17+
"elts"
1718
]
1819
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import ast
2+
import sys
3+
4+
5+
def fetch_dependencies_from_setup(file_path):
6+
with open(file_path, "r") as file:
7+
tree = ast.parse(file.read(), filename=file_path)
8+
9+
dependencies = []
10+
11+
for node in ast.walk(tree):
12+
if isinstance(node, ast.Call) and getattr(node.func, "id", None) == "setup":
13+
for keyword in node.keywords:
14+
if keyword.arg == "install_requires":
15+
dependencies = [elt.s for elt in keyword.value.elts]
16+
break
17+
18+
return dependencies
19+
20+
21+
# Path to the setup.py file of azure-ai-ml
22+
setup_file_path = "sdk/ml/azure-ai-ml/setup.py"
23+
24+
# Fetch dependencies
25+
deps_list = fetch_dependencies_from_setup(setup_file_path)
26+
27+
print("Dependencies of azure-sdk-for-python repo from setup.py of azure-ai-ml:")
28+
print(deps_list)
29+
30+
from packaging.requirements import Requirement
31+
32+
deps = [Requirement(line) for line in deps_list if line.strip() and not line.strip().startswith("#")]
33+
import requests
34+
35+
36+
def list_versions(package_name):
37+
url = f"https://pypi.org/pypi/{package_name}/json"
38+
response = requests.get(url)
39+
data = response.json()
40+
versions = data["releases"].keys()
41+
version_array = []
42+
for version in versions:
43+
version_array.append(version.split(".")[0])
44+
return sorted(version_array, key=int, reverse=True)
45+
46+
47+
from packaging.version import Version
48+
49+
50+
def is_major_update(previous, latest):
51+
return Version(latest).major > Version(previous).major
52+
53+
54+
def check_for_major_updates():
55+
major_updates = []
56+
for dep in deps:
57+
all_version = list_versions(dep.name)
58+
if len(all_version) > 1 and is_major_update(all_version[1], all_version[0]):
59+
major_updates.append(
60+
f"Current config of `{dep}` and major version updated from {dep.name}: {all_version[1]}{all_version[0]}"
61+
)
62+
if major_updates:
63+
# body = "\n".join(major_updates) # Uncomment this line if you want to send an email or notification
64+
print("Major Dependency Updates Found:")
65+
print(major_updates)
66+
sys.exit(1)
67+
else:
68+
print("No major updates found.")
69+
70+
71+
check_for_major_updates()

0 commit comments

Comments
 (0)