Skip to content

Commit

Permalink
chore(ci): enable retries for choco installations
Browse files Browse the repository at this point in the history
  • Loading branch information
pront committed Oct 9, 2024
1 parent 6f36945 commit bb76c3d
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
3 changes: 3 additions & 0 deletions scripts/environment/bootstrap-windows-2019.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ if ($env:RELEASE_BUILDER -ne "true") {
rustup run stable cargo install cargo-nextest --version 0.9.72 --locked
}

# Enable retries to avoid transient network issues.
export NUGET_ENABLE_ENHANCED_HTTP_RETRY=true

# Install some required dependencies / tools.
choco install make
choco install protoc
Expand Down
58 changes: 58 additions & 0 deletions scripts/util/retry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash

# Usage: ./retry.sh -r <max_retries> -d <delay_in_seconds> -c "<command>"
# Example: ./retry.sh -r 5 -d 30 -c "choco install protoc"

max_retries=3
delay=10
command=""

# Parse options
while getopts "r:d:c:" opt; do
case $opt in
r)
max_retries=$OPTARG
;;
d)
delay=$OPTARG
;;
c)
command=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done

# Check if command is provided
if [[ -z "$command" ]]; then
echo "Usage: $0 -r <max_retries> -d <delay_in_seconds> -c \"<command>\""
exit 1
fi

attempt=1

while [[ $attempt -le $max_retries ]]; do
echo "Attempt $attempt to run: $command"

if eval "$command"; then
echo "Command succeeded on attempt $attempt."
exit 0
else
echo "Attempt $attempt failed. Retrying in $delay seconds..."
((attempt++))
sleep $delay
delay=$((delay * 2)) # Exponential backoff (increase delay each time)
fi

if [[ $attempt -gt $max_retries ]]; then
echo "Command failed after $max_retries attempts."
exit 1
fi
done

0 comments on commit bb76c3d

Please sign in to comment.