From 8aa8665eaa0691acb84df627f86296e6e225773d Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sun, 26 Apr 2020 11:04:39 -0400 Subject: Perform retries when downloading OpenSSL in GHA (#5236) --- .github/workflows/download_openssl.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/workflows/download_openssl.py b/.github/workflows/download_openssl.py index a1446cfb..c7dbe927 100644 --- a/.github/workflows/download_openssl.py +++ b/.github/workflows/download_openssl.py @@ -5,9 +5,11 @@ import zipfile import requests +from urllib3.util.retry import Retry -def get_response(url, token): - response = requests.get(url, headers={"Authorization": "token " + token}) + +def get_response(session, url, token): + response = session.get(url, headers={"Authorization": "token " + token}) if response.status_code != 200: raise ValueError("Got HTTP {} fetching {}: ".format( response.status_code, url, response.content @@ -25,6 +27,13 @@ def main(platform, target): else: raise ValueError("Invalid platform") + session = requests.Session() + adapter = requests.adapters.HTTPAdapter( + max_retries=Retry() + ) + session.mount("https://", adapter) + session.mount("http://", adapter) + token = os.environ["GITHUB_TOKEN"] print("Looking for: {}".format(target)) runs_url = ( @@ -32,14 +41,14 @@ def main(platform, target): "{}/runs?branch=master&status=success".format(workflow) ) - response = get_response(runs_url, token).json() + response = get_response(session, runs_url, token).json() artifacts_url = response["workflow_runs"][0]["artifacts_url"] - response = get_response(artifacts_url, token).json() + response = get_response(session, artifacts_url, token).json() for artifact in response["artifacts"]: if artifact["name"] == target: print("Found artifact") response = get_response( - artifact["archive_download_url"], token + session, artifact["archive_download_url"], token ) zipfile.ZipFile(io.BytesIO(response.content)).extractall( os.path.join(path, artifact["name"]) -- cgit v1.2.3