Skip to content

Commit

Permalink
fix: add a retry mechanism on latest version retrieval
Browse files Browse the repository at this point in the history
Action could fail if the GitHub API was temporarily unavailable, this new patch
will make it to try again for approximately 2 minutes and output an appropriate
error message in case of a definitive failure.
  • Loading branch information
mtardy committed Jun 29, 2023
1 parent 37a06b3 commit 3a1ccfc
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
name: 'Setup bpftool'
description: 'Install bpftool static binaries'
branding:
icon: 'download'
color: 'gray-dark'
Expand All @@ -22,18 +20,37 @@ runs:
case $(uname -m) in
x86_64) echo "arch=amd64" >> $GITHUB_OUTPUT;;
aarch64) echo "arch=arm64" >> $GITHUB_OUTPUT;;
*) echo "unsupported architecture: $(uname -m)"; exit 1;;
*) echo "Unsupported architecture: $(uname -m)"; exit 1;;
esac
- name: retrieve version
id: version
shell: bash
shell: bash {0}
run: |
if [[ "${{ inputs.version }}" = "latest" ]]; then
echo "version=$(curl -s https://api.github.com/repos/libbpf/bpftool/releases/latest | jq -r '.tag_name')" >> $GITHUB_OUTPUT
max_attempts=7
attempt=1
retry_delay=1
while [ -z "$version" ] && [ "$attempt" -le "$max_attempts" ]; do
echo "Attempt $attempt: Fetching latest version from GitHub..."
version=$(curl -s https://api.github.com/repos/libbpf/bpftool/releases/latest | jq -r '.tag_name | select (.!=null)')
if [ -z "$version" ]; then
delay=$((2 ** (attempt - 1) * retry_delay))
echo "Fetching latest version from GitHub failed. Retrying in $delay seconds..."
sleep "$delay"
fi
attempt=$((attempt + 1))
done
if [ -z "$version" ]; then
echo "Fetching latest version failed after $max_attempts attempts. GitHub API might be unavailable, rerun this workflow later, exiting!"
exit 1
fi
else
echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT
echo "Using custom version '${{ inputs.version }}' defined by user..."
version=${{ inputs.version }}
fi
echo "Version retrieved: '$version'"
echo "version=$version" >> $GITHUB_OUTPUT
- name: cache download
id: cache-download
Expand Down

0 comments on commit 3a1ccfc

Please sign in to comment.