-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathcheck_django_eol.py
More file actions
92 lines (67 loc) · 2.18 KB
/
Copy pathcheck_django_eol.py
File metadata and controls
92 lines (67 loc) · 2.18 KB
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
90
91
92
import requests
import datetime
import sys
import subprocess
import re
from requests import RequestException
THRESHOLD_DAYS = 180
def get_django_version():
result = subprocess.run(
[sys.executable, "-m", "django", "--version"],
capture_output=True,
text=True
)
if result.returncode != 0:
print("ERROR: Unable to determine Django version")
sys.exit(1)
full_version = result.stdout.strip()
# Example:
# 4.2.16 -> 4.2
m = re.match(r"^(\d+)\.(\d+)", full_version)
if not m:
print(f"ERROR: Unexpected Django version format: {full_version}")
sys.exit(1)
cycle = f"{m.group(1)}.{m.group(2)}"
return full_version, cycle
def get_django_eol(cycle):
url = "https://endoflife.date/api/django.json"
try:
response = requests.get(url, timeout=10)
response.raise_for_status()
except RequestException as exc:
print(f"ERROR: Failed to fetch EOL data: {exc}")
sys.exit(1)
data = response.json()
for release in data:
if release["cycle"] == cycle:
return release["eol"]
print(f"ERROR: No EOL data found for Django {cycle}")
sys.exit(1)
def calculate_days_remaining(eol_date):
today = datetime.date.today()
eol = datetime.datetime.strptime(eol_date, "%Y-%m-%d").date()
return (eol - today).days
def main():
full_version, cycle = get_django_version()
eol_date = get_django_eol(cycle)
days_remaining = calculate_days_remaining(eol_date)
status = "OK"
if days_remaining < THRESHOLD_DAYS:
status = "WARNING"
# ---- structured output for GitHub Actions ----
print(f"STATUS={status}")
print(f"DJANGO_VERSION={full_version}")
print(f"DJANGO_CYCLE={cycle}")
print(f"EOL_DATE={eol_date}")
print(f"DAYS_REMAINING={days_remaining}")
# ---- human-readable log ----
print("\n--- Django EOL Report ---")
print(f"Version: {full_version}")
print(f"Cycle: {cycle}")
print(f"EOL date: {eol_date}")
print(f"Days remaining: {days_remaining}")
print(f"Status: {status}")
# keep non-blocking behavior (CI should NOT fail)
sys.exit(0)
if __name__ == "__main__":
main()