44 push : {} # For testing - change to specific branches later
55
66jobs :
7- wait-and- clear-cache :
7+ clear-cache :
88 runs-on : ubuntu-latest
99 steps :
1010 - name : Initial delay
11- run : sleep 120
11+ run : |
12+ echo "Waiting 2 minutes for potential deployments to start..."
13+ sleep 120
1214
1315 - name : Check deployment status
1416 id : check-deployments
1517 env :
16- DIGITALOCEAN_ACCESS_TOKEN : ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
18+ DIGITALOCEAN_ACCESS_TOKEN : ${{ secrets.DIGITALOCEAN_TOKEN }}
1719 run : |
20+ echo "Checking deployments on branch: ${{ github.ref_name }}"
21+
1822 APP_IDS="52a99a96-7e6a-4258-b523-23d615c05571,7917c4fa-2426-4f51-b8cd-15a680fcaf1f,7f68aa01-e022-4244-81a4-0e5a50893703,476726eb-3be5-4b53-abeb-fba6db77786e"
1923
2024 for app_id in ${APP_IDS//,/ }; do
25+ echo "Checking app: $app_id"
2126 response=$(curl -s \
2227 -H "Authorization: Bearer $DIGITALOCEAN_ACCESS_TOKEN" \
2328 -H "Content-Type: application/json" \
@@ -26,21 +31,35 @@ jobs:
2631 created_at=$(echo $response | jq -r '.deployments[0].created_at')
2732 status=$(echo $response | jq -r '.deployments[0].phase')
2833
34+ echo "Latest deployment status: $status (created: $created_at)"
35+
2936 # Check if deployment is from last 10 minutes and is active
3037 if [ "$status" = "ACTIVE" ] && [ $(( $(date +%s) - $(date -d "$created_at" +%s) )) -lt 600 ]; then
38+ echo "Found recent successful deployment"
3139 echo "status=success" >> $GITHUB_OUTPUT
3240 exit 0
3341 fi
3442 done
43+
44+ echo "No recent deployments found"
3545 echo "status=skip" >> $GITHUB_OUTPUT
3646
3747 - name : Purge Cloudflare cache
3848 if : steps.check-deployments.outputs.status == 'success'
3949 env :
40- CLOUDFLARE_TOKEN : ${{ secrets.CLOUDFLARE_TOKEN }}
50+ CLOUDFLARE_TOKEN : ${{ secrets.CLOUDFLARE_API_TOKEN }}
4151 run : |
42- curl -s -X POST \
52+ echo "Purging Cloudflare cache..."
53+ response=$(curl -s -X POST \
4354 "https://api.cloudflare.com/client/v4/zones/04102fd3a28043d9d40a2688282d688a/purge_cache" \
4455 -H "Authorization: Bearer $CLOUDFLARE_TOKEN" \
4556 -H "Content-Type: application/json" \
46- --data '{"purge_everything":true}'
57+ --data '{"purge_everything":true}')
58+
59+ if [ "$(echo $response | jq -r '.success')" = "true" ]; then
60+ echo "Successfully purged Cloudflare cache"
61+ else
62+ echo "Failed to purge cache:"
63+ echo $response
64+ exit 1
65+ fi
0 commit comments