Skip to content

set up job for clearing cache #1

set up job for clearing cache

set up job for clearing cache #1

Workflow file for this run

name: Clear cache
on:
push: {} # For testing - change to specific branches later
jobs:
wait-and-clear-cache:
runs-on: ubuntu-latest
steps:
- name: Initial delay
run: sleep 120
- name: Check deployment status
id: check-deployments
env:
DIGITALOCEAN_ACCESS_TOKEN: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
run: |
APP_IDS="52a99a96-7e6a-4258-b523-23d615c05571,7917c4fa-2426-4f51-b8cd-15a680fcaf1f,7f68aa01-e022-4244-81a4-0e5a50893703,476726eb-3be5-4b53-abeb-fba6db77786e"
for app_id in ${APP_IDS//,/ }; do
response=$(curl -s \
-H "Authorization: Bearer $DIGITALOCEAN_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
"https://api.digitalocean.com/v2/apps/$app_id/deployments?page=1&per_page=1")
created_at=$(echo $response | jq -r '.deployments[0].created_at')
status=$(echo $response | jq -r '.deployments[0].phase')
# Check if deployment is from last 10 minutes and is active
if [ "$status" = "ACTIVE" ] && [ $(( $(date +%s) - $(date -d "$created_at" +%s) )) -lt 600 ]; then
echo "status=success" >> $GITHUB_OUTPUT
exit 0
fi
done
echo "status=skip" >> $GITHUB_OUTPUT
- name: Purge Cloudflare cache
if: steps.check-deployments.outputs.status == 'success'
env:
CLOUDFLARE_TOKEN: ${{ secrets.CLOUDFLARE_TOKEN }}
run: |
curl -s -X POST \
"https://api.cloudflare.com/client/v4/zones/04102fd3a28043d9d40a2688282d688a/purge_cache" \
-H "Authorization: Bearer $CLOUDFLARE_TOKEN" \
-H "Content-Type: application/json" \
--data '{"purge_everything":true}'