|
1 | | -name: Clear cache |
| 1 | +name: Clear Cloudflare Cache After Deployments |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: {} # For testing - change to specific branches later |
|
7 | 7 | clear-cache: |
8 | 8 | runs-on: ubuntu-latest |
9 | 9 | 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 |
17 | 12 | env: |
18 | | - DIGITALOCEAN_ACCESS_TOKEN: ${{ secrets.DIGITALOCEAN_TOKEN }} |
| 13 | + DIGITALOCEAN_TOKEN: ${{ secrets.DIGITALOCEAN_TOKEN }} |
19 | 14 | run: | |
20 | | - echo "Checking deployments on branch: ${{ github.ref_name }}" |
| 15 | + echo "Initial 30 second delay..." |
| 16 | + sleep 30 |
21 | 17 | |
22 | 18 | APP_IDS="52a99a96-7e6a-4258-b523-23d615c05571,7917c4fa-2426-4f51-b8cd-15a680fcaf1f,7f68aa01-e022-4244-81a4-0e5a50893703,476726eb-3be5-4b53-abeb-fba6db77786e" |
23 | 19 | |
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..." |
33 | 22 | |
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 |
35 | 42 | |
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 |
41 | 47 | fi |
| 48 | + |
| 49 | + echo "No successful deployments yet, waiting 15 seconds..." |
| 50 | + sleep 30 |
42 | 51 | done |
43 | | - |
44 | | - echo "No recent deployments found" |
45 | | - echo "status=skip" >> $GITHUB_OUTPUT |
46 | 52 |
|
47 | 53 | - name: Purge Cloudflare cache |
48 | 54 | if: steps.check-deployments.outputs.status == 'success' |
|
0 commit comments