From 750f3dce9564a971f010b154a1158bd9a4db2d06 Mon Sep 17 00:00:00 2001 From: Xi Xu Date: Tue, 17 Mar 2026 14:20:27 +0800 Subject: [PATCH] Retry CDN purge requests and warn on failure --- .github/workflows/build-and-publish.yml | 60 +++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml index a4a279d..4c186d2 100644 --- a/.github/workflows/build-and-publish.yml +++ b/.github/workflows/build-and-publish.yml @@ -565,10 +565,36 @@ jobs: - name: Purge CDN cache run: | cd basic - for file in $(ls); do - curl -i "https://purge.jsdelivr.net/gh/${{ github.repository }}@basic/${file}" + failed_files=() + for file in *; do + [[ -f "$file" ]] || continue + purge_url="https://purge.jsdelivr.net/gh/${{ github.repository }}@basic/${file}" + purge_succeeded=false + + for attempt in 1 2 3; do + echo "Purging ${file} from basic CDN cache (attempt ${attempt}/3)" + if curl --fail --show-error --silent --location --max-time 30 "$purge_url"; then + purge_succeeded=true + echo + break + fi + + if [[ $attempt -lt 3 ]]; then + echo "Retrying ${file} after transient purge failure" + sleep 2 + fi + done + + if [[ $purge_succeeded == false ]]; then + failed_files+=("$file") + echo "::warning::Failed to purge jsDelivr cache for ${file} on the basic branch after 3 attempts." + fi done + if (( ${#failed_files[@]} > 0 )); then + printf 'Files with purge warnings on basic: %s\n' "${failed_files[*]}" + fi + purge-universal-rulesets-cdn-cache: runs-on: ubuntu-latest needs: build-and-publish-universal-rulesets @@ -583,6 +609,32 @@ jobs: - name: Purge CDN cache run: | cd universal - for file in $(ls); do - curl -i "https://purge.jsdelivr.net/gh/${{ github.repository }}@universal/${file}" + failed_files=() + for file in *; do + [[ -f "$file" ]] || continue + purge_url="https://purge.jsdelivr.net/gh/${{ github.repository }}@universal/${file}" + purge_succeeded=false + + for attempt in 1 2 3; do + echo "Purging ${file} from universal CDN cache (attempt ${attempt}/3)" + if curl --fail --show-error --silent --location --max-time 30 "$purge_url"; then + purge_succeeded=true + echo + break + fi + + if [[ $attempt -lt 3 ]]; then + echo "Retrying ${file} after transient purge failure" + sleep 2 + fi + done + + if [[ $purge_succeeded == false ]]; then + failed_files+=("$file") + echo "::warning::Failed to purge jsDelivr cache for ${file} on the universal branch after 3 attempts." + fi done + + if (( ${#failed_files[@]} > 0 )); then + printf 'Files with purge warnings on universal: %s\n' "${failed_files[*]}" + fi