Skip to content

Commit 8f7e8cd

Browse files
committed
feat(build): implement retry mechanism for file uploads in build workflow
1 parent d10038f commit 8f7e8cd

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

.github/workflows/build.yml

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,35 @@ jobs:
293293
apiToken: ${{ secrets.CF_R2_API_TOKEN }}
294294
wranglerVersion: "4.21.1"
295295
command: |
296-
r2 object put nginx-ui-dev-build/${{ env.DIST }}.tar.gz --file ./${{ env.DIST }}.tar.gz --remote
297-
r2 object put nginx-ui-dev-build/${{ env.DIST }}.tar.gz.digest --file ./${{ env.DIST }}.tar.gz.digest --remote
296+
# Define retry function
297+
retry_upload() {
298+
local file_path="$1"
299+
local remote_path="$2"
300+
local max_attempts=3
301+
local attempt=1
302+
303+
while [ $attempt -le $max_attempts ]; do
304+
echo "Attempt $attempt of $max_attempts: Uploading $file_path to $remote_path"
305+
if r2 object put "$remote_path" --file "$file_path" --remote; then
306+
echo "Successfully uploaded $file_path on attempt $attempt"
307+
return 0
308+
else
309+
echo "Failed to upload $file_path on attempt $attempt"
310+
if [ $attempt -lt $max_attempts ]; then
311+
echo "Waiting 5 seconds before retry..."
312+
sleep 5
313+
fi
314+
attempt=$((attempt + 1))
315+
fi
316+
done
317+
318+
echo "Failed to upload $file_path after $max_attempts attempts"
319+
return 1
320+
}
321+
322+
# Upload files with retry
323+
retry_upload ./${{ env.DIST }}.tar.gz nginx-ui-dev-build/${{ env.DIST }}.tar.gz
324+
retry_upload ./${{ env.DIST }}.tar.gz.digest nginx-ui-dev-build/${{ env.DIST }}.tar.gz.digest
298325
299326
docker-build:
300327
if: github.event_name != 'pull_request'

0 commit comments

Comments
 (0)