Skip to content

Commit 661dc77

Browse files
committed
Switch to polling
1 parent e5a8231 commit 661dc77

1 file changed

Lines changed: 34 additions & 28 deletions

File tree

.github/workflows/clear_cache.yml

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Clear cache
1+
name: Clear Cloudflare Cache After Deployments
22

33
on:
44
push: {} # For testing - change to specific branches later
@@ -7,42 +7,48 @@ jobs:
77
clear-cache:
88
runs-on: ubuntu-latest
99
steps:
10-
- name: Initial delay
11-
run: |
12-
echo "Waiting 2 minutes for potential deployments to start..."
13-
sleep 120
14-
15-
- name: Check deployment status
16-
id: check-deployments
10+
- name: Poll deployments
11+
id: poll-deployments
1712
env:
18-
DIGITALOCEAN_ACCESS_TOKEN: ${{ secrets.DIGITALOCEAN_TOKEN }}
13+
DIGITALOCEAN_TOKEN: ${{ secrets.DIGITALOCEAN_TOKEN }}
1914
run: |
20-
echo "Checking deployments on branch: ${{ github.ref_name }}"
15+
echo "Initial 30 second delay..."
16+
sleep 30
2117
2218
APP_IDS="52a99a96-7e6a-4258-b523-23d615c05571,7917c4fa-2426-4f51-b8cd-15a680fcaf1f,7f68aa01-e022-4244-81a4-0e5a50893703,476726eb-3be5-4b53-abeb-fba6db77786e"
2319
24-
for app_id in ${APP_IDS//,/ }; do
25-
echo "Checking app: $app_id"
26-
response=$(curl -s \
27-
-H "Authorization: Bearer $DIGITALOCEAN_ACCESS_TOKEN" \
28-
-H "Content-Type: application/json" \
29-
"https://api.digitalocean.com/v2/apps/$app_id/deployments?page=1&per_page=1")
30-
31-
created_at=$(echo $response | jq -r '.deployments[0].created_at')
32-
status=$(echo $response | jq -r '.deployments[0].phase')
20+
for attempt in {1..20}; do
21+
echo "Check attempt $attempt of 40..."
3322
34-
echo "Latest deployment status: $status (created: $created_at)"
23+
for app_id in ${APP_IDS//,/ }; do
24+
echo "Checking app: $app_id"
25+
response=$(curl -s \
26+
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
27+
-H "Content-Type: application/json" \
28+
"https://api.digitalocean.com/v2/apps/$app_id/deployments?page=1&per_page=1")
29+
30+
created_at=$(echo $response | jq -r '.deployments[0].created_at')
31+
status=$(echo $response | jq -r '.deployments[0].phase')
32+
33+
echo "Latest deployment status: $status (created: $created_at)"
34+
35+
# Check if deployment is from last 10 minutes and is active
36+
if [ "$status" = "ACTIVE" ] && [ $(( $(date +%s) - $(date -d "$created_at" +%s) )) -lt 600 ]; then
37+
echo "Found recent successful deployment"
38+
echo "status=success" >> $GITHUB_OUTPUT
39+
exit 0
40+
fi
41+
done
3542
36-
# Check if deployment is from last 10 minutes and is active
37-
if [ "$status" = "ACTIVE" ] && [ $(( $(date +%s) - $(date -d "$created_at" +%s) )) -lt 600 ]; then
38-
echo "Found recent successful deployment"
39-
echo "status=success" >> $GITHUB_OUTPUT
40-
exit 0
43+
if [ $attempt -eq 40 ]; then
44+
echo "Timeout after 10 minutes - no successful deployments found"
45+
echo "status=timeout" >> $GITHUB_OUTPUT
46+
exit 1
4147
fi
48+
49+
echo "No successful deployments yet, waiting 15 seconds..."
50+
sleep 30
4251
done
43-
44-
echo "No recent deployments found"
45-
echo "status=skip" >> $GITHUB_OUTPUT
4652
4753
- name: Purge Cloudflare cache
4854
if: steps.check-deployments.outputs.status == 'success'

0 commit comments

Comments
 (0)