Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Purge Cloudflare cache for all files after uploading R2 artifacts #3568

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions .github/workflows/artifacts-index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,20 @@ jobs:

- name: Flush CloudFlare cache
run: |
curl --silent --show-error --fail -X POST \
"https://api.cloudflare.com/client/v4/zones/${{ secrets.CF_ZONE }}/purge_cache" \
-H "Authorization: Bearer ${{ secrets.CF_PURGE_TOKEN }}" \
-H "Content-Type: application/json" \
--data '{"files": [
"https://os-artifacts.home-assistant.io/index.html",
"https://os-artifacts.home-assistant.io/index.json"
] }'
# Create purge list of all artifacts
jq -r '. | map("https://os-artifacts.home-assistant.io/${{ inputs.version }}/" + .) | join("\n")' < "${{ inputs.version }}.json" > purge_list
# Add indexes to purge list too
echo "https://os-artifacts.home-assistant.io/indexes/${{ inputs.version }}.json" >> purge_list
echo "https://os-artifacts.home-assistant.io/index.html" >> purge_list
echo "https://os-artifacts.home-assistant.io/index.json" >> purge_list
# Split to chunks of 30 files (limit of CF API)
split -d -l30 purge_list purge_list_chunked
# Convert chunked lists to JSON arrays and call CF purge API
for f in purge_list_chunked*; do
files=$(jq -R -s 'split("\n")[:-1]' < "$f")
curl --silent --show-error --fail -X POST \
"https://api.cloudflare.com/client/v4/zones/${{ secrets.CF_ZONE }}/purge_cache" \
-H "Authorization: Bearer ${{ secrets.CF_PURGE_TOKEN }}" \
-H "Content-Type: application/json" \
--data "{\"files\": ${files}}"
done