Skip to content

Commit

Permalink
Check URLs always and in parallel.
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed May 2, 2024
1 parent 5e6a027 commit e36e240
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions schemas/validate.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from jsonschema import validate as json_validate
import json
import os
import urllib.request

from jsonschema import validate as json_validate
from multiprocessing.pool import Pool

GENERIC_EA_SCHEMA = 'generic-ea-schema.json'
LATEST_EA_JSON = 'latest-ea.json'
Expand Down Expand Up @@ -40,18 +40,23 @@ def validate_builds(builds):
files = build['files']
assert version in download_base_url, f'version not found in download_base_url: {json.dumps(build)}'
assert all(version in file['filename'] for file in files), f'version not found in all filenames: {json.dumps(build)}'
if os.getenv('GITHUB_EVENT_NAME') != 'pull_request':
check_urls_exist(download_base_url, files)
check_urls_exist(download_base_url, files)


def check_urls_exist(download_base_url, files):
for file in files:
for extension in ['', '.sha256']:
download_url = f'{download_base_url}{file["filename"]}{extension}'
print(f" Checking '{download_url}'...")
request = urllib.request.Request(download_url, method='HEAD')
response = urllib.request.urlopen(request)
assert response.status == 200, f"Expected status code of 200, got {response.status} for '{download_url}'"
with Pool() as pool:
download_urls = [f'{download_base_url}{file["filename"]}{extension}' for extension in ['', '.sha256'] for file in files]
pool.map(check_url_exists, download_urls)


def check_url_exists(download_url):
print(f" Checking '{download_url}'...")
request = urllib.request.Request(download_url, method='HEAD')
try:
response = urllib.request.urlopen(request)
except urllib.error.URLError as e:
assert False, f"Failed to retrieve '{download_url}': {e}"
assert response.status == 200, f"Expected status code of 200, got {response.status} for '{download_url}'"


if __name__ == '__main__':
Expand Down

0 comments on commit e36e240

Please sign in to comment.