diff --git a/actions/github/artifact/cache/restore/action.yml b/actions/github/artifact/cache/restore/action.yml index 9842dc7aa0..f4c110b2f2 100644 --- a/actions/github/artifact/cache/restore/action.yml +++ b/actions/github/artifact/cache/restore/action.yml @@ -20,6 +20,14 @@ inputs: wf-path: type: string required: true + max-retries: + type: number + required: false + default: 3 + retry-delay: + type: number + required: false + default: 10 runs: @@ -40,17 +48,33 @@ runs: || steps.cache-id.outputs.id shell: bash run: | - gh api \ - -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - "/repos/${REPOSITORY}/actions/artifacts/${ARTIFACT_ID}/zip" \ - | tar --warning=no-timestamp \ - --keep-directory-symlink \ - -xI unzstd \ - -f - \ - -C ${OUTPUT_PATH} + for attempt in $(seq 1 "$MAX_RETRIES"); do + echo "Attempt $attempt of $MAX_RETRIES" + if gh api \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "/repos/${REPOSITORY}/actions/artifacts/${ARTIFACT_ID}/zip" \ + | tar --warning=no-timestamp \ + --keep-directory-symlink \ + -xI unzstd \ + -f - \ + -C ${OUTPUT_PATH}; then + echo "Cache restored successfully" + exit 0 + fi + if [[ "$attempt" -lt "$MAX_RETRIES" ]]; then + echo "::warning::Attempt $attempt failed, retrying in ${RETRY_DELAY}s..." + find "${OUTPUT_PATH:?}" -mindepth 1 -delete + sleep "$RETRY_DELAY" + fi + RETRY_DELAY=$((RETRY_DELAY * 2)) + done + echo "::error::Failed to restore artifact cache after $MAX_RETRIES attempts" + exit 1 env: GH_TOKEN: ${{ inputs.token }} ARTIFACT_ID: ${{ inputs.id || steps.cache-id.outputs.id }} OUTPUT_PATH: ${{ inputs.path }} REPOSITORY: ${{ inputs.repository }} + MAX_RETRIES: ${{ inputs.max-retries }} + RETRY_DELAY: ${{ inputs.retry-delay }}