|
15 | 15 |
|
16 | 16 | import httpx
|
17 | 17 |
|
| 18 | + |
| 19 | +def raise_response(response: httpx.Response) -> None: |
| 20 | + """Raise an exception from a response if necessary.""" |
| 21 | + if response.status_code // 100 != 2: |
| 22 | + try: |
| 23 | + print(response.json()) |
| 24 | + except json.JSONDecodeError: |
| 25 | + pass |
| 26 | + |
| 27 | + response.raise_for_status() |
| 28 | + |
| 29 | + |
18 | 30 | if __name__ == "__main__":
|
19 | 31 | owner, repo = parse.urlparse(os.getenv("REPOSITORY_URL")).path.lstrip("/").split("/")[0:2]
|
20 | 32 |
|
|
29 | 41 | ])
|
30 | 42 | print(f"Fetching download URL from {download_url}")
|
31 | 43 | response = httpx.get(download_url, follow_redirects=True)
|
32 |
| - |
33 |
| - if response.status_code // 100 != 2: |
34 |
| - try: |
35 |
| - print(response.json()) |
36 |
| - except json.JSONDecodeError: |
37 |
| - pass |
38 |
| - |
39 |
| - response.raise_for_status() |
| 44 | + raise_response(response) |
40 | 45 |
|
41 | 46 | # The workflow is still pending, retry in a bit
|
42 | 47 | while response.status_code == 202:
|
43 | 48 | print(f"{response.json()['error']}. Retrying in 10 seconds.")
|
44 | 49 | time.sleep(10)
|
45 | 50 | response = httpx.get(download_url, follow_redirects=True)
|
46 | 51 |
|
| 52 | + raise_response(response) |
47 | 53 | url = response.json()["url"]
|
48 | 54 | print(f"Downloading build from {url}")
|
49 |
| - zipped_content = httpx.get(url, follow_redirects=True) |
| 55 | + zipped_content = httpx.get(url, follow_redirects=True, timeout=3 * 60) |
50 | 56 | zipped_content.raise_for_status()
|
51 | 57 |
|
52 | 58 | zip_file = Path("temp.zip")
|
|
0 commit comments