From ccb612a59a975f1950dfda1610615eab2f76a88c Mon Sep 17 00:00:00 2001 From: Balazs Perlaki-Horvath Date: Mon, 15 Jan 2024 09:05:15 +0100 Subject: [PATCH] Revert CD archive to use python re-try --- .github/retry-if-retcode.py | 76 +++++++++++++++++++++++++++++++++++++ .github/workflows/cd.yml | 4 +- 2 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 .github/retry-if-retcode.py diff --git a/.github/retry-if-retcode.py b/.github/retry-if-retcode.py new file mode 100644 index 00000000..5ad943ce --- /dev/null +++ b/.github/retry-if-retcode.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python3 + +import argparse +import subprocess +import sys +import time + + +def run_command( + max_attempts: int, retcode: int, sleep_seconds: int, command: str +) -> int: + attempts = 0 + while True: + ps = subprocess.run(command, check=False) + attempts += 1 + + # either suceeded or returned an unexpected exit-code, returning. + if ps.returncode == 0 or ps.returncode != retcode: + return ps.returncode + + if attempts >= max_attempts: + print(f"Reached {max_attempts=}", flush=True) + return ps.returncode + + print( + f"Received retcode={ps.returncode} on attempt #{attempts}. " + f"Retrying in {sleep_seconds}s.", + flush=True, + ) + if sleep_seconds: + time.sleep(sleep_seconds) + + +def main(): + parser = argparse.ArgumentParser( + prog="retry-if-retcode", epilog=r"/!\ Append your command after those args!" + ) + + parser.add_argument( + "--retcode", + required=True, + help="Return code to retry when received", + type=int, + ) + + parser.add_argument( + "--attempts", + required=False, + help="Max number of attempts", + type=int, + default=10, + ) + + parser.add_argument( + "--sleep", + required=False, + help="Nb. of seconds to sleep in-between retries", + type=int, + default=1, + ) + + args, command = parser.parse_known_args() + if not command: + print("You must supply a command to run") + return 1 + + return run_command( + max_attempts=args.attempts, + retcode=args.retcode, + sleep_seconds=args.sleep, + command=command, + ) + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index a4d008bd..993a7f1f 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -172,7 +172,7 @@ jobs: APPLE_STORE_AUTH_KEY_PATH: ${{ env.APPLE_STORE_AUTH_KEY_PATH }} APPLE_STORE_AUTH_KEY_ID: ${{ secrets.APPLE_STORE_AUTH_KEY_ID }} APPLE_STORE_AUTH_KEY_ISSUER_ID: ${{ secrets.APPLE_STORE_AUTH_KEY_ISSUER_ID }} - 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 + 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 - name: Export notarized App from archive if: ${{ matrix.destination.uploadto == 'dmg' }} @@ -180,7 +180,7 @@ jobs: APPLE_STORE_AUTH_KEY_PATH: ${{ env.APPLE_STORE_AUTH_KEY_PATH }} APPLE_STORE_AUTH_KEY_ID: ${{ secrets.APPLE_STORE_AUTH_KEY_ID }} APPLE_STORE_AUTH_KEY_ISSUER_ID: ${{ secrets.APPLE_STORE_AUTH_KEY_ISSUER_ID }} - run: 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 + 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 - name: Create DMG if: ${{ matrix.destination.uploadto == 'dmg' }}