From fa5fd06bd92142032b3fa25b76872a035be8d8cb Mon Sep 17 00:00:00 2001 From: "Mike Kostersitz (Oilcan Productions)" <77457397+oilcan-productions@users.noreply.github.com> Date: Fri, 23 Aug 2024 14:18:23 -0700 Subject: [PATCH] Update deploy-ftp.sh Adding retry logic for creatin the tar ball to ensure what we upload is valid. Looping back to creating the tar ball instead of looping on the download. --- build/deploy-ftp.sh | 64 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 8 deletions(-) diff --git a/build/deploy-ftp.sh b/build/deploy-ftp.sh index 82ed067a3..894253f2d 100644 --- a/build/deploy-ftp.sh +++ b/build/deploy-ftp.sh @@ -18,12 +18,44 @@ echo "login $USER" >> "$NETRC" echo "password $FTP_SECRET" >> "$NETRC" chmod 600 "$NETRC" -upload_file(){ - (cd out; tar czf $EMULATOR.tgz $EMULATOR) +# create_archive will create a tar ball from the out folder +# try to extract it to see if it is valid +# retry 3 times then fail +create_archive() { + MAX_RETRIES=3 + RETRY_COUNT=0 - echo "Deploying as $USER at $HOST" + while [ "$RETRY_COUNT" -lt "$MAX_RETRIES" ]; do + (cd out; tar czf $EMULATOR.tgz $EMULATOR) - ftp "$HOST" </dev/null 2>&1; then + echo "Tarball is valid and can be expanded." + break + else + echo "Tarball is not valid or cannot be expanded. Retrying..." + RETRY_COUNT=`expr "$RETRY_COUNT" + 1` + rm -f $EMULATOR.tgz + continue + fi + done + + if [ "$RETRY_COUNT" = "$MAX_RETRIES" ]; then + echo "Failed to create a valid tarball after $MAX_RETRIES attempts." + return 1 + fi +} + +# upload_file tries to upload the tar ball to the FTP server, will retry 5 times and then fail +upload_file() { + MAX_RETRIES=5 + RETRY_COUNT=0 + + while [ "$RETRY_COUNT" -lt "$MAX_RETRIES" ]; do + echo "Deploying as $USER at $HOST" + + # Attempt to upload the file + if ftp "$HOST" <