Skip to content

Commit d41b2b6

Browse files
committed
retrying upload to apple, introducing retry script
1 parent 44c30a7 commit d41b2b6

File tree

2 files changed

+78
-35
lines changed

2 files changed

+78
-35
lines changed

.github/retry-if-retcode.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import subprocess
5+
import sys
6+
import time
7+
8+
9+
def run_command(
10+
max_attempts: int, retcode: int, sleep_seconds: int, command: str
11+
) -> int:
12+
attempts = 0
13+
while True:
14+
ps = subprocess.run(command, check=False)
15+
attempts += 1
16+
17+
# either suceeded or returned an unexpected exit-code, returning.
18+
if ps.returncode == 0 or ps.returncode != retcode:
19+
return ps.returncode
20+
21+
if attempts >= max_attempts:
22+
print(f"Reached {max_attempts=}")
23+
return ps.returncode
24+
25+
print(
26+
f"Received retcode={ps.returncode} on attempt #{attempts}. "
27+
f"Retrying in {sleep_seconds}s."
28+
)
29+
if sleep_seconds:
30+
time.sleep(sleep_seconds)
31+
32+
33+
def main():
34+
parser = argparse.ArgumentParser(
35+
prog="retry-if-retcode", epilog=r"/!\ Append your command after those args!"
36+
)
37+
38+
parser.add_argument(
39+
"--retcode",
40+
required=True,
41+
help="Return code to retry when received",
42+
type=int,
43+
)
44+
45+
parser.add_argument(
46+
"--attempts",
47+
required=False,
48+
help="Max number of attempts",
49+
type=int,
50+
default=10,
51+
)
52+
53+
parser.add_argument(
54+
"--sleep",
55+
required=False,
56+
help="Nb. of seconds to sleep in-between retries",
57+
type=int,
58+
default=1,
59+
)
60+
61+
args, command = parser.parse_known_args()
62+
if not command:
63+
print("You must supply a command to run")
64+
return 1
65+
66+
return run_command(
67+
max_attempts=args.attempts,
68+
retcode=args.retcode,
69+
sleep_seconds=args.sleep,
70+
command=command,
71+
)
72+
73+
74+
if __name__ == "__main__":
75+
sys.exit(main())

.github/workflows/cd.yml

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
name: CD
22

33
on:
4-
push:
5-
branches: [cd]
64
schedule:
7-
- cron: '0 1 * * *'
5+
- cron: '32 1 * * *'
86
workflow_dispatch:
97
release:
108
types: [published]
@@ -170,45 +168,15 @@ jobs:
170168
APPLE_STORE_AUTH_KEY_PATH: ${{ env.APPLE_STORE_AUTH_KEY_PATH }}
171169
APPLE_STORE_AUTH_KEY_ID: ${{ secrets.APPLE_STORE_AUTH_KEY_ID }}
172170
APPLE_STORE_AUTH_KEY_ISSUER_ID: ${{ secrets.APPLE_STORE_AUTH_KEY_ISSUER_ID }}
173-
174-
run: xcrun xcodebuild -exportArchive -archivePath $PWD/Kiwix-$VERSION.xcarchive -exportPath $PWD/export/ -exportOptionsPlist export.plist -authenticationKeyPath $APPLE_STORE_AUTH_KEY_PATH -allowProvisioningUpdates -authenticationKeyID $APPLE_STORE_AUTH_KEY_ID -authenticationKeyIssuerID $APPLE_STORE_AUTH_KEY_ISSUER_ID
171+
run: python .github/retry-if-retcode.py --sleep 60 --attempts 5 --retcode 70 xcrun xcodebuild -exportArchive -archivePath $PWD/Kiwix-$VERSION.xcarchive -exportPath $PWD/export/ -exportOptionsPlist export.plist -authenticationKeyPath $APPLE_STORE_AUTH_KEY_PATH -allowProvisioningUpdates -authenticationKeyID $APPLE_STORE_AUTH_KEY_ID -authenticationKeyIssuerID $APPLE_STORE_AUTH_KEY_ISSUER_ID
175172

176173
- name: Export notarized App from archive
177174
if: ${{ matrix.destination.uploadto == 'dmg' }}
178175
env:
179176
APPLE_STORE_AUTH_KEY_PATH: ${{ env.APPLE_STORE_AUTH_KEY_PATH }}
180177
APPLE_STORE_AUTH_KEY_ID: ${{ secrets.APPLE_STORE_AUTH_KEY_ID }}
181178
APPLE_STORE_AUTH_KEY_ISSUER_ID: ${{ secrets.APPLE_STORE_AUTH_KEY_ISSUER_ID }}
182-
run: |
183-
set +e
184-
attempts=0
185-
retcode=-1
186-
until [[ $retcode -eq 0 ]]
187-
do
188-
((attempts++))
189-
xcrun xcodebuild -exportNotarizedApp -archivePath $PWD/Kiwix-$VERSION.xcarchive -exportPath $PWD/export/ -authenticationKeyPath $APPLE_STORE_AUTH_KEY_PATH -allowProvisioningUpdates -authenticationKeyID $APPLE_STORE_AUTH_KEY_ID -authenticationKeyIssuerID $APPLE_STORE_AUTH_KEY_ISSUER_ID
190-
retcode=$?
191-
192-
if [[ $retcode -eq 0 ]]
193-
then
194-
echo "Export suceedeed"
195-
break
196-
fi
197-
198-
if [[ ! $retcode -eq 65 ]]
199-
then
200-
echo "Non-65 exit-code, propagating: {$retcode}"
201-
return $retcode
202-
fi
203-
204-
if [[ $attempts -ge 20 ]]
205-
then
206-
echo "Too many attempts (${attempts}), exiting ${retcode}"
207-
return $retcode
208-
fi
209-
echo "Not notarized ; retrying in a minute"
210-
sleep 60
211-
done
179+
run: python .github/retry-if-retcode.py --sleep 60 --attempts 20 --retcode 65 xcrun xcodebuild -exportNotarizedApp -archivePath $PWD/Kiwix-$VERSION.xcarchive -exportPath $PWD/export/ -authenticationKeyPath $APPLE_STORE_AUTH_KEY_PATH -allowProvisioningUpdates -authenticationKeyID $APPLE_STORE_AUTH_KEY_ID -authenticationKeyIssuerID $APPLE_STORE_AUTH_KEY_ISSUER_ID
212180

213181
- name: Create DMG
214182
if: ${{ matrix.destination.uploadto == 'dmg' }}

0 commit comments

Comments
 (0)