Skip to content

Commit f9901f2

Browse files
committed
allow retry on connection loss
1 parent 27b52d8 commit f9901f2

3 files changed

Lines changed: 72 additions & 37 deletions

File tree

.github/workflows/generator-android.yml

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,23 +87,35 @@ jobs:
8787
import io
8888
import os
8989
import json
90-
91-
r = requests.get('${{ fromJson(inputs.zip_url).url }}/get_zip?filename=${{ fromJson(inputs.zip_url).file }}')
92-
r.raise_for_status()
90+
import time
91+
92+
for attempt in range(5):
93+
try:
94+
print(f"Downloading secrets (Attempt {attempt + 1})...")
95+
r = requests.get('${{ fromJson(inputs.zip_url).url }}/get_zip?filename=${{ fromJson(inputs.zip_url).file }}', timeout=60)
96+
r.raise_for_status()
97+
break
98+
except (requests.exceptions.RequestException, requests.exceptions.Timeout) as e:
99+
if attempt < 4:
100+
print(f"Timeout/Error occurred: {e}. Retrying in 5 seconds...")
101+
time.sleep(5)
102+
else:
103+
print("Max retries reached. Failing.")
104+
raise e
93105
94106
try:
95-
with pyzipper.AESZipFile(io.BytesIO(r.content)) as zf:
96-
zf.setpassword('${{ secrets.ZIP_PASSWORD }}'.encode())
97-
with zf.open('secrets.json') as f:
98-
secrets = json.load(f)
107+
with pyzipper.AESZipFile(io.BytesIO(r.content)) as zf:
108+
zf.setpassword('${{ secrets.ZIP_PASSWORD }}'.encode())
109+
with zf.open('secrets.json') as f:
110+
secrets = json.load(f)
99111
except Exception as e:
100-
print(f"Error: Could not decrypt ZIP. Check if password matches. {e}")
101-
exit(1)
112+
print(f"Error: Could not decrypt ZIP. Check if password matches. {e}")
113+
exit(1)
102114
103115
with open(os.environ['GITHUB_ENV'], 'a') as env_file:
104-
for key, value in secrets.items():
105-
print(f"::add-mask::{value}")
106-
env_file.write(f"{key}={value}\n")
116+
for key, value in secrets.items():
117+
print(f"::add-mask::{value}")
118+
env_file.write(f"{key}={value}\n")
107119
108120
print("Secrets loaded into environment.")
109121

.github/workflows/generator-windows-x86.yml

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ run-name: Custom Windows x86 Client Generator
33
on:
44
workflow_dispatch:
55
inputs:
6-
inputs:
76
version:
87
description: 'version to buld'
98
required: true
@@ -77,23 +76,35 @@ jobs:
7776
import io
7877
import os
7978
import json
80-
81-
r = requests.get('${{ fromJson(inputs.zip_url).url }}/get_zip?filename=${{ fromJson(inputs.zip_url).file }}')
82-
r.raise_for_status()
79+
import time
80+
81+
for attempt in range(5):
82+
try:
83+
print(f"Downloading secrets (Attempt {attempt + 1})...")
84+
r = requests.get('${{ fromJson(inputs.zip_url).url }}/get_zip?filename=${{ fromJson(inputs.zip_url).file }}', timeout=60)
85+
r.raise_for_status()
86+
break
87+
except (requests.exceptions.RequestException, requests.exceptions.Timeout) as e:
88+
if attempt < 4:
89+
print(f"Timeout/Error occurred: {e}. Retrying in 5 seconds...")
90+
time.sleep(5)
91+
else:
92+
print("Max retries reached. Failing.")
93+
raise e
8394
8495
try:
85-
with pyzipper.AESZipFile(io.BytesIO(r.content)) as zf:
86-
zf.setpassword('${{ secrets.ZIP_PASSWORD }}'.encode())
87-
with zf.open('secrets.json') as f:
88-
secrets = json.load(f)
96+
with pyzipper.AESZipFile(io.BytesIO(r.content)) as zf:
97+
zf.setpassword('${{ secrets.ZIP_PASSWORD }}'.encode())
98+
with zf.open('secrets.json') as f:
99+
secrets = json.load(f)
89100
except Exception as e:
90-
print(f"Error: Could not decrypt ZIP. Check if password matches. {e}")
91-
exit(1)
101+
print(f"Error: Could not decrypt ZIP. Check if password matches. {e}")
102+
exit(1)
92103
93104
with open(os.environ['GITHUB_ENV'], 'a') as env_file:
94-
for key, value in secrets.items():
95-
print(f"::add-mask::{value}")
96-
env_file.write(f"{key}={value}\n")
105+
for key, value in secrets.items():
106+
print(f"::add-mask::{value}")
107+
env_file.write(f"{key}={value}\n")
97108
98109
print("Secrets loaded into environment.")
99110

.github/workflows/generator-windows.yml

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,23 +87,35 @@ jobs:
8787
import io
8888
import os
8989
import json
90-
91-
r = requests.get('${{ fromJson(inputs.zip_url).url }}/get_zip?filename=${{ fromJson(inputs.zip_url).file }}')
92-
r.raise_for_status()
90+
import time
91+
92+
for attempt in range(5):
93+
try:
94+
print(f"Downloading secrets (Attempt {attempt + 1})...")
95+
r = requests.get('${{ fromJson(inputs.zip_url).url }}/get_zip?filename=${{ fromJson(inputs.zip_url).file }}', timeout=60)
96+
r.raise_for_status()
97+
break
98+
except (requests.exceptions.RequestException, requests.exceptions.Timeout) as e:
99+
if attempt < 4:
100+
print(f"Timeout/Error occurred: {e}. Retrying in 5 seconds...")
101+
time.sleep(5)
102+
else:
103+
print("Max retries reached. Failing.")
104+
raise e
93105
94106
try:
95-
with pyzipper.AESZipFile(io.BytesIO(r.content)) as zf:
96-
zf.setpassword('${{ secrets.ZIP_PASSWORD }}'.encode())
97-
with zf.open('secrets.json') as f:
98-
secrets = json.load(f)
107+
with pyzipper.AESZipFile(io.BytesIO(r.content)) as zf:
108+
zf.setpassword('${{ secrets.ZIP_PASSWORD }}'.encode())
109+
with zf.open('secrets.json') as f:
110+
secrets = json.load(f)
99111
except Exception as e:
100-
print(f"Error: Could not decrypt ZIP. Check if password matches. {e}")
101-
exit(1)
112+
print(f"Error: Could not decrypt ZIP. Check if password matches. {e}")
113+
exit(1)
102114
103115
with open(os.environ['GITHUB_ENV'], 'a') as env_file:
104-
for key, value in secrets.items():
105-
print(f"::add-mask::{value}")
106-
env_file.write(f"{key}={value}\n")
116+
for key, value in secrets.items():
117+
print(f"::add-mask::{value}")
118+
env_file.write(f"{key}={value}\n")
107119
108120
print("Secrets loaded into environment.")
109121

0 commit comments

Comments
 (0)