|
16 | 16 | jobs: |
17 | 17 | Test: |
18 | 18 | runs-on: ubuntu-latest |
19 | | - timeout-minutes: 10 |
20 | 19 | strategy: |
21 | 20 | fail-fast: false |
22 | 21 | max-parallel: 10 |
@@ -72,82 +71,38 @@ jobs: |
72 | 71 | - name: Check domain redirections |
73 | 72 | shell: python |
74 | 73 | run: | |
75 | | - import time |
76 | | - from urllib.parse import urlparse |
77 | | -
|
78 | 74 | import requests |
79 | | - from requests.adapters import HTTPAdapter |
80 | | - from urllib3.util.retry import Retry |
81 | | -
|
82 | | - VALID_DESTINATIONS = {"ultralytics.com", "www.ultralytics.com", "yolo11.com", "www.yolo11.com"} |
83 | | - REQUEST_TIMEOUT = (10, 20) |
84 | | - BASE_DELAY = 5 |
85 | | - MAX_DELAY = 120 |
86 | | - USER_AGENT = ( |
87 | | - "Mozilla/5.0 (compatible; UltralyticsDomainCheck/1.0; +https://github.com/ultralytics/docs)" |
88 | | - ) |
89 | | -
|
90 | | - def build_session(): |
91 | | - """Create a session with lightweight retries for transient HTTP errors.""" |
92 | | - retry = Retry( |
93 | | - total=2, |
94 | | - connect=2, |
95 | | - read=2, |
96 | | - status=2, |
97 | | - backoff_factor=1, |
98 | | - status_forcelist=(429, 500, 502, 503, 504), |
99 | | - allowed_methods=frozenset(["GET"]), |
100 | | - raise_on_status=False, |
101 | | - ) |
102 | | - adapter = HTTPAdapter(max_retries=retry) |
103 | | - session = requests.Session() |
104 | | - session.headers.update({"User-Agent": USER_AGENT}) |
105 | | - session.mount("https://", adapter) |
106 | | - session.mount("http://", adapter) |
107 | | - return session |
108 | | -
|
109 | | - def is_valid_destination(url): |
110 | | - """Check the final redirect hostname against approved destinations.""" |
111 | | - hostname = (urlparse(url).hostname or "").lower() |
112 | | - return hostname in VALID_DESTINATIONS |
| 75 | + import time |
113 | 76 |
|
114 | | - def check_domain_redirection(domain, prefix, session, max_attempts=5): |
| 77 | + def check_domain_redirection(domain, prefix, max_attempts=5): |
115 | 78 | """Check if the given domain redirects correctly, with exponential delays between retries.""" |
| 79 | + valid_destinations = ["ultralytics.com", "yolo11.com"] |
116 | 80 | url = f"https://{prefix}{domain}" |
117 | 81 | print(f"\nChecking {url}") |
118 | 82 |
|
119 | 83 | for attempt in range(max_attempts): |
120 | | - response = None |
121 | 84 | try: |
122 | 85 | if attempt > 0: |
123 | | - delay = min(BASE_DELAY * (2 ** attempt), MAX_DELAY) # 10, 20, 40, 80... |
| 86 | + delay = min(5 * (2 ** attempt), 120) # 10, 20, 40, 80... |
124 | 87 | print(f"Retrying in {delay}s (attempt {attempt + 1}/{max_attempts})") |
125 | 88 | time.sleep(delay) |
126 | 89 |
|
127 | | - response = session.get(url, allow_redirects=True, timeout=REQUEST_TIMEOUT, stream=True) |
| 90 | + response = requests.get(url, allow_redirects=True, timeout=10) |
128 | 91 | response.raise_for_status() |
129 | 92 |
|
130 | | - if is_valid_destination(response.url) and response.status_code == 200: |
131 | | - print(f"Success ✅ -> {response.url}") |
| 93 | + if any(dest in response.url for dest in valid_destinations) and response.status_code == 200: |
| 94 | + print("Success ✅") |
132 | 95 | return True |
133 | 96 |
|
134 | | - print(f"Unexpected final URL: {response.url} (status {response.status_code}) ❌") |
135 | | - return False |
136 | | -
|
137 | 97 | except requests.RequestException as e: |
138 | 98 | print(f"Error: {e}") |
139 | 99 | if attempt == max_attempts - 1: |
140 | 100 | print(f"Failed after {max_attempts} attempts ❌") |
141 | 101 | return False |
142 | | - finally: |
143 | | - if response is not None: |
144 | | - response.close() |
145 | 102 |
|
146 | 103 | return False |
147 | 104 |
|
148 | | - session = build_session() |
149 | | - success = check_domain_redirection('${{ matrix.domain }}', '${{ matrix.prefix }}', session) |
150 | | - session.close() |
| 105 | + success = check_domain_redirection('${{ matrix.domain }}', '${{ matrix.prefix }}') |
151 | 106 | if not success: |
152 | 107 | raise Exception(f"Domain check failed for ${{ matrix.domain }} with prefix '${{ matrix.prefix }}'") |
153 | 108 |
|
|
0 commit comments