name: Trigger Cloudflare deploy on: push: branches: [main, cloudflare-dev] workflow_dispatch: permissions: {} jobs: deploy: runs-on: ubuntu-latest timeout-minutes: 5 steps: - name: Harden runner uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 with: egress-policy: audit - name: Verify target branch if: github.event_name == 'workflow_dispatch' run: | case "${GITHUB_REF}" in refs/heads/main|refs/heads/cloudflare-dev) ;; *) echo "Manual deploy hook runs must target main or cloudflare-dev (got ${GITHUB_REF})" >&2 exit 1 ;; esac - name: Trigger Cloudflare build env: DEPLOY_HOOK: ${{ secrets.CLOUDFLARE_DEPLOY_HOOK }} run: | if [ -z "$DEPLOY_HOOK" ]; then echo "CLOUDFLARE_DEPLOY_HOOK is not configured" >&2 exit 1 fi max_attempts=4 delay=2 for attempt in $(seq 1 "$max_attempts"); do status=$(curl --silent --show-error --output /tmp/cf-deploy-hook.out --write-out "%{http_code}" \ --connect-timeout 10 --max-time 30 --request POST "$DEPLOY_HOOK") || status="000" if [ "$status" -ge 200 ] && [ "$status" -lt 300 ]; then cat /tmp/cf-deploy-hook.out exit 0 fi if [ "$status" = "503" ] && [ "$attempt" -lt "$max_attempts" ]; then echo "Cloudflare deploy hook returned HTTP 503 (attempt ${attempt}/${max_attempts}); retrying in ${delay}s..." >&2 sleep "$delay" delay=$((delay * 2)) continue fi cat /tmp/cf-deploy-hook.out >&2 || true echo "Cloudflare deploy hook request failed with HTTP ${status}" >&2 exit 1 done