From d440585078414ad7c421c30fb0d267a41e83b6d1 Mon Sep 17 00:00:00 2001 From: pat-s Date: Wed, 26 Mar 2025 13:22:00 +0100 Subject: [PATCH] feat: use function for cache purging --- .../update-package-index-redhat-9-amd64.yaml | 55 +++++++++++++++++-- 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/.crow/update-package-index-redhat-9-amd64.yaml b/.crow/update-package-index-redhat-9-amd64.yaml index 4368604..eea445b 100644 --- a/.crow/update-package-index-redhat-9-amd64.yaml +++ b/.crow/update-package-index-redhat-9-amd64.yaml @@ -62,12 +62,55 @@ steps: BUNNY_API_KEY: from_secret: BUNNY_API_KEY commands: | - curl -sL -X POST -H "AccessKey: $BUNNY_API_KEY" https://api.bunny.net/purge?url=https%3A%2F%2Fcran.devxy.io%2Famd64%2Frhel9%2Flatest%2Fsrc%2Fcontrib%2FPACKAGES&async=false - curl -sL -X POST -H "AccessKey: $BUNNY_API_KEY" https://api.bunny.net/purge?url=https%3A%2F%2Fcran.devxy.io%2Famd64%2Frhel9%2Flatest%2Fsrc%2Fcontrib%2FPACKAGES.gz&async=false - curl -sL -X POST -H "AccessKey: $BUNNY_API_KEY" https://api.bunny.net/purge?url=https%3A%2F%2Fcran.devxy.io%2Famd64%2Frhel9%2Flatest%2Fsrc%2Fcontrib%2FPACKAGES.rds&async=false - curl -sL -X POST -H "AccessKey: $BUNNY_API_KEY" https://api.bunny.net/purge?url=https%3A%2F%2Fcran.devxy.io%2Famd64%2Frhel9%2Flatest%2Fsrc%2Fcontrib%2FPACKAGES.db&async=false - curl -sL -X POST -H "AccessKey: $BUNNY_API_KEY" https://api.bunny.net/purge?url=https%3A%2F%2Fcran.devxy.io%2Famd64%2Frhel9%2Flatest%2Fsrc%2Fcontrib%2FPMeta%2FParchive.rds&async=false - sleep 20 # need to wait a bit to successfully deliver API calls + #!/bin/bash + + # Variables for subdomains, OS identifier and architecture + SUBDOMAIN1="cran.devxy.io" + SUBDOMAIN2="cran.allianceswisspass.devxy.io" + OS_ID="rhel9" + ARCH="amd64" + + # Array of resource paths + resources=( + "src/contrib/PACKAGES" + "src/contrib/PACKAGES.gz" + "src/contrib/PACKAGES.rds" + "src/contrib/PACKAGES.db" + ) + + # Function to URL-encode a string using Python + urlencode() { + python3 -c "import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1], safe=''))" "$$1" + } + + # Function to send the purge request + purge() { + curl -sL -X POST -H "AccessKey: $BUNNY_API_KEY" "$$1" + } + + # Function to generate the purge URLs for a given subdomain + generate_urls() { + local subdomain=$$1 + local urls=() + for resource in "${resources[@]}"; do + # Build the unencoded URL based on variables + local target_url="https://$${subdomain}/$${ARCH}/$${OS_ID}/latest/$${resource}" + # URL-encode the target URL + local encoded=$(urlencode "$$target_url") + # Construct the full API call URL + urls+=( "https://api.bunny.net/purge?url=$${encoded}&async=false" ) + done + echo "$${urls[@]}" + } + + # Generate URLs for both subdomains + urls_combined=( $$(generate_urls "$$SUBDOMAIN1") ) + allianceswisspass_urls=( $$(generate_urls "$$SUBDOMAIN2") ) + + # Purge for first subdomain and then wait + for url in "$${urls_combined[@]}"; do + purge "$$url" + done - name: 'ntfy' image: binwiederhier/ntfy:v2.11.0