Skip to content

Commit 417602b

Browse files
Update dependency checker to create GH issues (#41717)
* Notify if dependency releases a major version * Renaming and taking co pilot suggestions * black fixes * spell fixes * black fixes * update dependency YAML * review comment fix * Update dependency checker to create GH issues * Update .github/workflows/dependency-checker.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * black fixes * give write permission for issues * give write permission for issues using PAT * give write permission for issues * Major update checker (#41810) * Notify if dependency releases a major version * Renaming and taking co pilot suggestions * black fixes * spell fixes * black fixes * update dependency YAML * review comment fix * Update dependency checker to create GH issues * Update .github/workflows/dependency-checker.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * black fixes * give write permission for issues * give write permission for issues using PAT --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * test without explicit permission and amend title * test with explicit permission --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent c9995bd commit 417602b

File tree

3 files changed

+69
-43
lines changed

3 files changed

+69
-43
lines changed

.github/workflows/dependency-checker.yml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,33 @@ on:
55
- cron: "0 0,12 * * *" # Runs at 00:00 and 12:00 UTC
66
workflow_dispatch: # Optional manual trigger
77

8+
permissions:
9+
issues: write # to create the Issues using API
10+
811
jobs:
9-
build-and-test:
12+
check-dependencies:
1013
runs-on: ubuntu-latest
1114
steps:
12-
- uses: actions/checkout@v2
15+
- name: Checkout repository
16+
uses: actions/checkout@v3
1317

14-
- name: Set up Python 3.11
18+
- name: Set up Python
1519
uses: actions/setup-python@v4
1620
with:
1721
python-version: 3.11
1822

1923
- name: Install Dependencies
2024
run: pip install packaging==25.0 requests==2.32.4
2125

22-
- name: Run Script
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install --upgrade pip
29+
pip install packaging==25.0 requests==2.32.4
30+
31+
- name: Run major dependency update check
2332
run: python sdk/ml/azure-ai-ml/scripts/major_updates.py
33+
34+
- name: Create GitHub issues for major updates
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
run: python sdk/ml/azure-ai-ml/scripts/create_issue.py
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import os
2+
import requests
3+
4+
GITHUB_API = "https://api.github.com"
5+
REPO = "Azure/azure-sdk-for-python"
6+
TOKEN = os.getenv("GITHUB_TOKEN")
7+
8+
9+
def issue_exists(title):
10+
url = f"{GITHUB_API}/search/issues"
11+
headers = {"Authorization": f"token {TOKEN}"}
12+
params = {"q": f"{title} repo:{REPO}"}
13+
response = requests.get(url, headers=headers, params=params)
14+
data = response.json()
15+
return data.get("total_count", 0) > 0
16+
17+
18+
def create_issue(title, body, labels):
19+
url = f"{GITHUB_API}/repos/{REPO}/issues"
20+
headers = {"Authorization": f"token {TOKEN}"}
21+
payload = {"title": title, "body": body, "labels": labels}
22+
response = requests.post(url, headers=headers, json=payload)
23+
if response.status_code == 201:
24+
print(f"Issue created: {title}")
25+
else:
26+
print(f"Failed to create issue: {title} - {response.text}")
27+
28+
29+
with open("updates.txt", "r") as f:
30+
for line in f:
31+
dep, version = line.strip().split()
32+
title = f"Major version update available for {dep} in azure-ai-ml"
33+
body = f"A major version update is available in azure-ai-ml for `{dep}`. Latest version: {version}."
34+
labels = ["dependency", "major-update", "Machine Learning", "needs-team-attention"]
35+
if not issue_exists(title):
36+
create_issue(title, body, labels)
37+
else:
38+
print(f"Issue already exists: {title}")
Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,45 @@
11
import ast
2-
import sys
2+
import requests
3+
from packaging.requirements import Requirement
4+
from packaging.version import Version
35

46

57
def fetch_dependencies_from_setup(file_path):
68
with open(file_path, "r") as file:
79
tree = ast.parse(file.read(), filename=file_path)
810

911
dependencies = []
10-
1112
for node in ast.walk(tree):
1213
if isinstance(node, ast.Call) and getattr(node.func, "id", None) == "setup":
1314
for keyword in node.keywords:
1415
if keyword.arg == "install_requires":
1516
dependencies = [elt.s for elt in keyword.value.elts]
1617
break
17-
1818
return dependencies
1919

2020

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-
3621
def list_versions(package_name):
3722
url = f"https://pypi.org/pypi/{package_name}/json"
3823
response = requests.get(url)
3924
data = response.json()
4025
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
26+
return sorted(versions, key=Version, reverse=True)
4827

4928

5029
def is_major_update(previous, latest):
5130
return Version(latest).major > Version(previous).major
5231

5332

5433
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.")
34+
setup_file_path = "sdk/ml/azure-ai-ml/setup.py"
35+
deps_list = fetch_dependencies_from_setup(setup_file_path)
36+
deps = [Requirement(line) for line in deps_list if line.strip() and not line.strip().startswith("#")]
37+
38+
with open("updates.txt", "w") as f:
39+
for dep in deps:
40+
all_versions = list_versions(dep.name)
41+
if len(all_versions) > 1 and is_major_update(all_versions[1], all_versions[0]):
42+
f.write(f"{dep.name} {all_versions[0]}\n")
6943

7044

7145
check_for_major_updates()

0 commit comments

Comments
 (0)