add additional logging #7
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Clear Cloudflare Cache After Deployments | |
| on: | |
| push: {} # For testing - change to specific branches later | |
| jobs: | |
| clear-cache: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Poll deployments | |
| id: poll-deployments | |
| env: | |
| DIGITALOCEAN_TOKEN: ${{ secrets.DIGITALOCEAN_TOKEN }} | |
| run: | | |
| echo "Initial 30 second delay..." | |
| sleep 30 | |
| APP_IDS="52a99a96-7e6a-4258-b523-23d615c05571,7917c4fa-2426-4f51-b8cd-15a680fcaf1f,7f68aa01-e022-4244-81a4-0e5a50893703,476726eb-3be5-4b53-abeb-fba6db77786e" | |
| CURRENT_COMMIT="${{ github.sha }}" | |
| echo "Current commit: $CURRENT_COMMIT" | |
| for attempt in {1..20}; do | |
| echo "Check attempt $attempt of 20..." | |
| for app_id in ${APP_IDS//,/ }; do | |
| echo "Checking app: $app_id" | |
| response=$(curl -s \ | |
| -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \ | |
| -H "Content-Type: application/json" \ | |
| "https://api.digitalocean.com/v2/apps/$app_id/deployments?page=1&per_page=1") | |
| echo "Raw API Response:" | |
| echo "$response" | jq '.' | |
| created_at=$(echo $response | jq -r '.deployments[0].created_at') | |
| status=$(echo $response | jq -r '.deployments[0].phase') | |
| # Try different possible commit hash fields | |
| commit_hash=$(echo $response | jq -r '.deployments[0].source_commit_hash') | |
| echo "source_commit_hash: $commit_hash" | |
| commit_hash=$(echo $response | jq -r '.deployments[0].commit_hash') | |
| echo "commit_hash: $commit_hash" | |
| commit_hash=$(echo $response | jq -r '.deployments[0].source.commit_hash') | |
| echo "source.commit_hash: $commit_hash" | |
| commit_hash=$(echo $response | jq -r '.deployments[0].source.commit') | |
| echo "source.commit: $commit_hash" | |
| echo "Latest deployment status: $status (created: $created_at)" | |
| # Check if deployment is from last 10 minutes and is active | |
| if [ "$status" = "ACTIVE" ] && \ | |
| [ $(( $(date +%s) - $(date -d "$created_at" +%s) )) -lt 300 ]; then | |
| echo "Found recent successful deployment" | |
| echo "status=success" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| done | |
| if [ $attempt -eq 20 ]; then | |
| echo "Timeout after 10 minutes - no matching successful deployments found" | |
| echo "status=timeout" >> $GITHUB_OUTPUT | |
| exit 1 | |
| fi | |
| echo "No matching successful deployments yet, waiting 30 seconds..." | |
| sleep 30 | |
| done | |
| - name: Purge Cloudflare cache | |
| if: steps.poll-deployments.outputs.status == 'success' | |
| env: | |
| CLOUDFLARE_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| run: | | |
| echo "Purging Cloudflare cache..." | |
| response=$(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}') | |
| if [ "$(echo $response | jq -r '.success')" = "true" ]; then | |
| echo "Successfully purged Cloudflare cache" | |
| else | |
| echo "Failed to purge cache:" | |
| echo $response | |
| exit 1 | |
| fi |