Deploy to Cloudflare Workers #16
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: Deploy to Cloudflare Workers | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| environment: | |
| description: Deployment environment name | |
| required: false | |
| default: production | |
| worker_name: | |
| description: Override worker name | |
| required: false | |
| default: "grok2api" | |
| d1_name: | |
| description: Override D1 database name | |
| required: false | |
| default: "grok2api-db" | |
| kv_name: | |
| description: Override KV namespace name | |
| required: false | |
| default: "grok2api-kv" | |
| concurrency: | |
| group: deploy-cloudflare-workers-${{ github.ref }} | |
| cancel-in-progress: false | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| env: | |
| FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true | |
| CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| CF_ENVIRONMENT: ${{ github.event.inputs.environment || 'production' }} | |
| CF_WORKER_NAME: ${{ github.event.inputs.worker_name || format('grok2api-{0}', github.repository_owner) }} | |
| CF_D1_NAME: ${{ github.event.inputs.d1_name || format('grok2api-{0}-db', github.repository_owner) }} | |
| CF_KV_NAME: ${{ github.event.inputs.kv_name || format('grok2api-{0}-kv', github.repository_owner) }} | |
| CF_WRANGLER_TEMPLATE: cloudflare/wrangler.cloudflare.jsonc | |
| CF_WRANGLER_OUTPUT: .wrangler.generated.jsonc | |
| CF_RESOURCES_OUTPUT: cloudflare/resources.json | |
| CF_DEPLOY_LOG: cloudflare/deploy-output.log | |
| CF_DEPLOY_META: cloudflare/deploy-meta.json | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v5 | |
| - name: Setup Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: '3.13' | |
| - name: Setup Node | |
| uses: actions/setup-node@v5 | |
| with: | |
| node-version: '20' | |
| - name: Validate required secrets | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| test -n "${CLOUDFLARE_ACCOUNT_ID}" | |
| test -n "${CLOUDFLARE_API_TOKEN}" | |
| test -f "${CF_WRANGLER_TEMPLATE}" | |
| test -f "cloudflare/worker-entry.js" | |
| - name: Validate deployment names | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| python - <<'PY' | |
| import os, re | |
| pattern = re.compile(r'^[A-Za-z0-9][A-Za-z0-9._-]{1,62}[A-Za-z0-9]$') | |
| for key in ('CF_WORKER_NAME', 'CF_D1_NAME', 'CF_KV_NAME'): | |
| value = os.environ.get(key, '').strip() | |
| if not value: | |
| raise SystemExit(f'{key} is empty') | |
| if not pattern.fullmatch(value): | |
| raise SystemExit(f'{key} contains invalid characters: {value!r}') | |
| PY | |
| - name: Install Wrangler CLI | |
| run: npm install --global wrangler@4 | |
| - name: Show Wrangler version | |
| run: wrangler --version | |
| - name: Prepare Cloudflare resources | |
| shell: bash | |
| run: | | |
| python scripts/cf_prepare_resources.py --output "${CF_RESOURCES_OUTPUT}" | |
| - name: Render Wrangler config | |
| shell: bash | |
| run: | | |
| python scripts/cf_render_wrangler.py \ | |
| --template "${CF_WRANGLER_TEMPLATE}" \ | |
| --resources "${CF_RESOURCES_OUTPUT}" \ | |
| --output "${CF_WRANGLER_OUTPUT}" | |
| - name: Show rendered Wrangler config path | |
| shell: bash | |
| run: | | |
| echo "Using Wrangler config: ${CF_WRANGLER_OUTPUT}" | |
| test -f "${CF_WRANGLER_OUTPUT}" | |
| - name: Deploy Worker | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| mkdir -p cloudflare | |
| wrangler deploy --config "${CF_WRANGLER_OUTPUT}" 2>&1 | tee "${CF_DEPLOY_LOG}" | |
| - name: Extract deploy metadata | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| python - <<'PY' | |
| import json | |
| import os | |
| import re | |
| from pathlib import Path | |
| log_path = Path(os.environ['CF_DEPLOY_LOG']) | |
| out_path = Path(os.environ['CF_DEPLOY_META']) | |
| text = log_path.read_text(encoding='utf-8', errors='replace') if log_path.exists() else '' | |
| url_match = re.search(r'https://[A-Za-z0-9._/-]+\.workers\.dev(?:/[A-Za-z0-9._~:/?#\[\]@!$&\'\(\)\*\+,;=%-]*)?', text) | |
| data = { | |
| 'worker_url': url_match.group(0).rstrip('/') if url_match else '' | |
| } | |
| out_path.write_text(json.dumps(data, indent=2), encoding='utf-8') | |
| print(json.dumps(data, indent=2)) | |
| PY | |
| - name: Health check | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| worker_url=$(python - <<'PY' | |
| import json | |
| import os | |
| from pathlib import Path | |
| path = Path(os.environ['CF_DEPLOY_META']) | |
| data = json.loads(path.read_text(encoding='utf-8')) if path.exists() else {} | |
| print(data.get('worker_url', '').rstrip('/')) | |
| PY | |
| ) | |
| if [ -z "$worker_url" ]; then | |
| echo "Unable to determine deployed workers.dev URL from deploy output" >&2 | |
| echo "Deploy log:" >&2 | |
| cat "${CF_DEPLOY_LOG}" >&2 | |
| exit 1 | |
| fi | |
| worker_url="${worker_url}/health" | |
| echo "Checking ${worker_url}" | |
| curl --fail --silent --show-error --retry 5 --retry-all-errors --retry-delay 2 "$worker_url" | |
| - name: Ready check | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| worker_url=$(python - <<'PY' | |
| import json | |
| import os | |
| from pathlib import Path | |
| path = Path(os.environ['CF_DEPLOY_META']) | |
| data = json.loads(path.read_text(encoding='utf-8')) if path.exists() else {} | |
| print(data.get('worker_url', '').rstrip('/')) | |
| PY | |
| ) | |
| if [ -z "$worker_url" ]; then | |
| echo "Unable to determine deployed workers.dev URL from deploy output" >&2 | |
| echo "Deploy log:" >&2 | |
| cat "${CF_DEPLOY_LOG}" >&2 | |
| exit 1 | |
| fi | |
| ready_url="${worker_url}/ready" | |
| echo "Checking ${ready_url}" | |
| curl --fail --silent --show-error --retry 5 --retry-all-errors --retry-delay 2 "$ready_url" | |
| - name: Metadata check | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| worker_url=$(python - <<'PY' | |
| import json | |
| import os | |
| from pathlib import Path | |
| path = Path(os.environ['CF_DEPLOY_META']) | |
| data = json.loads(path.read_text(encoding='utf-8')) if path.exists() else {} | |
| print(data.get('worker_url', '').rstrip('/')) | |
| PY | |
| ) | |
| if [ -z "$worker_url" ]; then | |
| echo "Unable to determine deployed workers.dev URL from deploy output" >&2 | |
| echo "Deploy log:" >&2 | |
| cat "${CF_DEPLOY_LOG}" >&2 | |
| exit 1 | |
| fi | |
| meta_url="${worker_url}/meta" | |
| echo "Checking ${meta_url}" | |
| curl --fail --silent --show-error --retry 5 --retry-all-errors --retry-delay 2 "$meta_url" | |
| - name: Config check | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| worker_url=$(python - <<'PY' | |
| import json | |
| import os | |
| from pathlib import Path | |
| path = Path(os.environ['CF_DEPLOY_META']) | |
| data = json.loads(path.read_text(encoding='utf-8')) if path.exists() else {} | |
| print(data.get('worker_url', '').rstrip('/')) | |
| PY | |
| ) | |
| if [ -z "$worker_url" ]; then | |
| echo "Unable to determine deployed workers.dev URL from deploy output" >&2 | |
| echo "Deploy log:" >&2 | |
| cat "${CF_DEPLOY_LOG}" >&2 | |
| exit 1 | |
| fi | |
| config_url="${worker_url}/config" | |
| echo "Checking ${config_url}" | |
| curl --fail --silent --show-error --retry 5 --retry-all-errors --retry-delay 2 "$config_url" | |
| - name: Config sections check | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| worker_url=$(python - <<'PY' | |
| import json | |
| import os | |
| from pathlib import Path | |
| path = Path(os.environ['CF_DEPLOY_META']) | |
| data = json.loads(path.read_text(encoding='utf-8')) if path.exists() else {} | |
| print(data.get('worker_url', '').rstrip('/')) | |
| PY | |
| ) | |
| if [ -z "$worker_url" ]; then | |
| echo "Unable to determine deployed workers.dev URL from deploy output" >&2 | |
| echo "Deploy log:" >&2 | |
| cat "${CF_DEPLOY_LOG}" >&2 | |
| exit 1 | |
| fi | |
| config_sections_url="${worker_url}/config/sections" | |
| echo "Checking ${config_sections_url}" | |
| curl --fail --silent --show-error --retry 5 --retry-all-errors --retry-delay 2 "$config_sections_url" | |
| - name: Config section read check | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| worker_url=$(python - <<'PY' | |
| import json | |
| import os | |
| from pathlib import Path | |
| path = Path(os.environ['CF_DEPLOY_META']) | |
| data = json.loads(path.read_text(encoding='utf-8')) if path.exists() else {} | |
| print(data.get('worker_url', '').rstrip('/')) | |
| PY | |
| ) | |
| if [ -z "$worker_url" ]; then | |
| echo "Unable to determine deployed workers.dev URL from deploy output" >&2 | |
| echo "Deploy log:" >&2 | |
| cat "${CF_DEPLOY_LOG}" >&2 | |
| exit 1 | |
| fi | |
| section_url="${worker_url}/config/app" | |
| echo "Checking ${section_url}" | |
| curl --fail --silent --show-error --retry 5 --retry-all-errors --retry-delay 2 "$section_url" | |
| - name: Config write check | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| worker_url=$(python - <<'PY' | |
| import json | |
| import os | |
| from pathlib import Path | |
| path = Path(os.environ['CF_DEPLOY_META']) | |
| data = json.loads(path.read_text(encoding='utf-8')) if path.exists() else {} | |
| print(data.get('worker_url', '').rstrip('/')) | |
| PY | |
| ) | |
| if [ -z "$worker_url" ]; then | |
| echo "Unable to determine deployed workers.dev URL from deploy output" >&2 | |
| echo "Deploy log:" >&2 | |
| cat "${CF_DEPLOY_LOG}" >&2 | |
| exit 1 | |
| fi | |
| config_url="${worker_url}/config" | |
| echo "Posting to ${config_url}" | |
| curl --fail --silent --show-error \ | |
| --retry 5 --retry-all-errors --retry-delay 2 \ | |
| -H "Content-Type: application/json" \ | |
| -X POST \ | |
| --data '{"app":{"custom_instruction":"cf-workers-smoke-test"},"runtime":{"verification":"milestone-4"}}' \ | |
| "$config_url" | |
| - name: Config section write check | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| worker_url=$(python - <<'PY' | |
| import json | |
| import os | |
| from pathlib import Path | |
| path = Path(os.environ['CF_DEPLOY_META']) | |
| data = json.loads(path.read_text(encoding='utf-8')) if path.exists() else {} | |
| print(data.get('worker_url', '').rstrip('/')) | |
| PY | |
| ) | |
| if [ -z "$worker_url" ]; then | |
| echo "Unable to determine deployed workers.dev URL from deploy output" >&2 | |
| echo "Deploy log:" >&2 | |
| cat "${CF_DEPLOY_LOG}" >&2 | |
| exit 1 | |
| fi | |
| section_url="${worker_url}/config/proxy" | |
| echo "Posting to ${section_url}" | |
| curl --fail --silent --show-error \ | |
| --retry 5 --retry-all-errors --retry-delay 2 \ | |
| -H "Content-Type: application/json" \ | |
| -X POST \ | |
| --data '{"enabled":true,"browser":"chrome136"}' \ | |
| "$section_url" | |
| - name: Config reset check | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| worker_url=$(python - <<'PY' | |
| import json | |
| import os | |
| from pathlib import Path | |
| path = Path(os.environ['CF_DEPLOY_META']) | |
| data = json.loads(path.read_text(encoding='utf-8')) if path.exists() else {} | |
| print(data.get('worker_url', '').rstrip('/')) | |
| PY | |
| ) | |
| if [ -z "$worker_url" ]; then | |
| echo "Unable to determine deployed workers.dev URL from deploy output" >&2 | |
| echo "Deploy log:" >&2 | |
| cat "${CF_DEPLOY_LOG}" >&2 | |
| exit 1 | |
| fi | |
| reset_url="${worker_url}/config/reset" | |
| echo "Posting to ${reset_url}" | |
| curl --fail --silent --show-error \ | |
| --retry 5 --retry-all-errors --retry-delay 2 \ | |
| -H "Content-Type: application/json" \ | |
| -X POST \ | |
| --data '{}' \ | |
| "$reset_url" | |
| - name: Storage check | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| worker_url=$(python - <<'PY' | |
| import json | |
| import os | |
| from pathlib import Path | |
| path = Path(os.environ['CF_DEPLOY_META']) | |
| data = json.loads(path.read_text(encoding='utf-8')) if path.exists() else {} | |
| print(data.get('worker_url', '').rstrip('/')) | |
| PY | |
| ) | |
| if [ -z "$worker_url" ]; then | |
| echo "Unable to determine deployed workers.dev URL from deploy output" >&2 | |
| echo "Deploy log:" >&2 | |
| cat "${CF_DEPLOY_LOG}" >&2 | |
| exit 1 | |
| fi | |
| storage_url="${worker_url}/storage" | |
| echo "Checking ${storage_url}" | |
| curl --fail --silent --show-error --retry 5 --retry-all-errors --retry-delay 2 "$storage_url" | |
| - name: Models bridge check | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| worker_url=$(python - <<'PY' | |
| import json | |
| import os | |
| from pathlib import Path | |
| path = Path(os.environ['CF_DEPLOY_META']) | |
| data = json.loads(path.read_text(encoding='utf-8')) if path.exists() else {} | |
| print(data.get('worker_url', '').rstrip('/')) | |
| PY | |
| ) | |
| if [ -z "$worker_url" ]; then | |
| echo "Unable to determine deployed workers.dev URL from deploy output" >&2 | |
| echo "Deploy log:" >&2 | |
| cat "${CF_DEPLOY_LOG}" >&2 | |
| exit 1 | |
| fi | |
| models_url="${worker_url}/v1/models" | |
| echo "Checking ${models_url}" | |
| curl --fail --silent --show-error --retry 5 --retry-all-errors --retry-delay 2 "$models_url" | |
| - name: Model detail bridge check | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| worker_url=$(python - <<'PY' | |
| import json | |
| import os | |
| from pathlib import Path | |
| path = Path(os.environ['CF_DEPLOY_META']) | |
| data = json.loads(path.read_text(encoding='utf-8')) if path.exists() else {} | |
| print(data.get('worker_url', '').rstrip('/')) | |
| PY | |
| ) | |
| if [ -z "$worker_url" ]; then | |
| echo "Unable to determine deployed workers.dev URL from deploy output" >&2 | |
| echo "Deploy log:" >&2 | |
| cat "${CF_DEPLOY_LOG}" >&2 | |
| exit 1 | |
| fi | |
| model_url="${worker_url}/v1/models/grok-4" | |
| echo "Checking ${model_url}" | |
| curl --fail --silent --show-error --retry 5 --retry-all-errors --retry-delay 2 "$model_url" | |
| - name: Admin verify unauthorized check | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| worker_url=$(python - <<'PY' | |
| import json | |
| import os | |
| from pathlib import Path | |
| path = Path(os.environ['CF_DEPLOY_META']) | |
| data = json.loads(path.read_text(encoding='utf-8')) if path.exists() else {} | |
| print(data.get('worker_url', '').rstrip('/')) | |
| PY | |
| ) | |
| if [ -z "$worker_url" ]; then | |
| echo "Unable to determine deployed workers.dev URL from deploy output" >&2 | |
| echo "Deploy log:" >&2 | |
| cat "${CF_DEPLOY_LOG}" >&2 | |
| exit 1 | |
| fi | |
| verify_url="${worker_url}/v1/admin/verify" | |
| echo "Checking unauthorized response from ${verify_url}" | |
| status_code=$(curl --silent --show-error --output /dev/null --write-out '%{http_code}' "$verify_url") | |
| test "$status_code" = "401" | |
| - name: Admin verify bridge check | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| worker_url=$(python - <<'PY' | |
| import json | |
| import os | |
| from pathlib import Path | |
| path = Path(os.environ['CF_DEPLOY_META']) | |
| data = json.loads(path.read_text(encoding='utf-8')) if path.exists() else {} | |
| print(data.get('worker_url', '').rstrip('/')) | |
| PY | |
| ) | |
| if [ -z "$worker_url" ]; then | |
| echo "Unable to determine deployed workers.dev URL from deploy output" >&2 | |
| echo "Deploy log:" >&2 | |
| cat "${CF_DEPLOY_LOG}" >&2 | |
| exit 1 | |
| fi | |
| verify_url="${worker_url}/v1/admin/verify" | |
| echo "Checking ${verify_url}" | |
| curl --fail --silent --show-error --retry 5 --retry-all-errors --retry-delay 2 \ | |
| -H "Authorization: Bearer grok2api" \ | |
| "$verify_url" | |
| - name: Function verify unauthorized check | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| worker_url=$(python - <<'PY' | |
| import json | |
| import os | |
| from pathlib import Path | |
| path = Path(os.environ['CF_DEPLOY_META']) | |
| data = json.loads(path.read_text(encoding='utf-8')) if path.exists() else {} | |
| print(data.get('worker_url', '').rstrip('/')) | |
| PY | |
| ) | |
| if [ -z "$worker_url" ]; then | |
| echo "Unable to determine deployed workers.dev URL from deploy output" >&2 | |
| echo "Deploy log:" >&2 | |
| cat "${CF_DEPLOY_LOG}" >&2 | |
| exit 1 | |
| fi | |
| verify_url="${worker_url}/v1/function/verify" | |
| echo "Checking unauthorized response from ${verify_url}" | |
| status_code=$(curl --silent --show-error --output /dev/null --write-out '%{http_code}' "$verify_url") | |
| test "$status_code" = "401" | |
| - name: Admin config bridge read check | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| worker_url=$(python - <<'PY' | |
| import json | |
| import os | |
| from pathlib import Path | |
| path = Path(os.environ['CF_DEPLOY_META']) | |
| data = json.loads(path.read_text(encoding='utf-8')) if path.exists() else {} | |
| print(data.get('worker_url', '').rstrip('/')) | |
| PY | |
| ) | |
| if [ -z "$worker_url" ]; then | |
| echo "Unable to determine deployed workers.dev URL from deploy output" >&2 | |
| echo "Deploy log:" >&2 | |
| cat "${CF_DEPLOY_LOG}" >&2 | |
| exit 1 | |
| fi | |
| config_url="${worker_url}/v1/admin/config" | |
| echo "Checking ${config_url}" | |
| curl --fail --silent --show-error --retry 5 --retry-all-errors --retry-delay 2 \ | |
| -H "Authorization: Bearer grok2api" \ | |
| "$config_url" | |
| - name: Admin config bridge write check | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| worker_url=$(python - <<'PY' | |
| import json | |
| import os | |
| from pathlib import Path | |
| path = Path(os.environ['CF_DEPLOY_META']) | |
| data = json.loads(path.read_text(encoding='utf-8')) if path.exists() else {} | |
| print(data.get('worker_url', '').rstrip('/')) | |
| PY | |
| ) | |
| if [ -z "$worker_url" ]; then | |
| echo "Unable to determine deployed workers.dev URL from deploy output" >&2 | |
| echo "Deploy log:" >&2 | |
| cat "${CF_DEPLOY_LOG}" >&2 | |
| exit 1 | |
| fi | |
| config_url="${worker_url}/v1/admin/config" | |
| echo "Posting to ${config_url}" | |
| curl --fail --silent --show-error \ | |
| --retry 5 --retry-all-errors --retry-delay 2 \ | |
| -H "Authorization: Bearer grok2api" \ | |
| -H "Content-Type: application/json" \ | |
| -X POST \ | |
| --data '{"app":{"custom_instruction":"phase-a-admin-config"},"proxy":{"enabled":false}}' \ | |
| "$config_url" | |
| - name: Function verify bridge check | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| worker_url=$(python - <<'PY' | |
| import json | |
| import os | |
| from pathlib import Path | |
| path = Path(os.environ['CF_DEPLOY_META']) | |
| data = json.loads(path.read_text(encoding='utf-8')) if path.exists() else {} | |
| print(data.get('worker_url', '').rstrip('/')) | |
| PY | |
| ) | |
| if [ -z "$worker_url" ]; then | |
| echo "Unable to determine deployed workers.dev URL from deploy output" >&2 | |
| echo "Deploy log:" >&2 | |
| cat "${CF_DEPLOY_LOG}" >&2 | |
| exit 1 | |
| fi | |
| enable_url="${worker_url}/v1/admin/config" | |
| verify_url="${worker_url}/v1/function/verify" | |
| echo "Enabling function access through ${enable_url}" | |
| curl --fail --silent --show-error \ | |
| --retry 5 --retry-all-errors --retry-delay 2 \ | |
| -H "Authorization: Bearer grok2api" \ | |
| -H "Content-Type: application/json" \ | |
| -X POST \ | |
| --data '{"app":{"function_enabled":true,"function_key":"phase-a-function-key"}}' \ | |
| "$enable_url" >/dev/null | |
| echo "Checking ${verify_url}" | |
| curl --fail --silent --show-error --retry 5 --retry-all-errors --retry-delay 2 \ | |
| -H "Authorization: Bearer phase-a-function-key" \ | |
| "$verify_url" | |
| - name: Runtime status bridge check | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| worker_url=$(python - <<'PY' | |
| import json | |
| import os | |
| from pathlib import Path | |
| path = Path(os.environ['CF_DEPLOY_META']) | |
| data = json.loads(path.read_text(encoding='utf-8')) if path.exists() else {} | |
| print(data.get('worker_url', '').rstrip('/')) | |
| PY | |
| ) | |
| if [ -z "$worker_url" ]; then | |
| echo "Unable to determine deployed workers.dev URL from deploy output" >&2 | |
| echo "Deploy log:" >&2 | |
| cat "${CF_DEPLOY_LOG}" >&2 | |
| exit 1 | |
| fi | |
| runtime_status_url="${worker_url}/v1/runtime/status" | |
| echo "Checking ${runtime_status_url}" | |
| curl --fail --silent --show-error --retry 5 --retry-all-errors --retry-delay 2 "$runtime_status_url" | |
| - name: Runtime checks bridge check | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| worker_url=$(python - <<'PY' | |
| import json | |
| import os | |
| from pathlib import Path | |
| path = Path(os.environ['CF_DEPLOY_META']) | |
| data = json.loads(path.read_text(encoding='utf-8')) if path.exists() else {} | |
| print(data.get('worker_url', '').rstrip('/')) | |
| PY | |
| ) | |
| if [ -z "$worker_url" ]; then | |
| echo "Unable to determine deployed workers.dev URL from deploy output" >&2 | |
| echo "Deploy log:" >&2 | |
| cat "${CF_DEPLOY_LOG}" >&2 | |
| exit 1 | |
| fi | |
| checks_url="${worker_url}/v1/runtime/checks" | |
| echo "Checking ${checks_url}" | |
| curl --fail --silent --show-error --retry 5 --retry-all-errors --retry-delay 2 "$checks_url" | |
| - name: Runtime flags read bridge check | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| worker_url=$(python - <<'PY' | |
| import json | |
| import os | |
| from pathlib import Path | |
| path = Path(os.environ['CF_DEPLOY_META']) | |
| data = json.loads(path.read_text(encoding='utf-8')) if path.exists() else {} | |
| print(data.get('worker_url', '').rstrip('/')) | |
| PY | |
| ) | |
| if [ -z "$worker_url" ]; then | |
| echo "Unable to determine deployed workers.dev URL from deploy output" >&2 | |
| echo "Deploy log:" >&2 | |
| cat "${CF_DEPLOY_LOG}" >&2 | |
| exit 1 | |
| fi | |
| flags_url="${worker_url}/v1/runtime/flags" | |
| echo "Checking ${flags_url}" | |
| curl --fail --silent --show-error --retry 5 --retry-all-errors --retry-delay 2 "$flags_url" | |
| - name: Runtime flags write bridge check | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| worker_url=$(python - <<'PY' | |
| import json | |
| import os | |
| from pathlib import Path | |
| path = Path(os.environ['CF_DEPLOY_META']) | |
| data = json.loads(path.read_text(encoding='utf-8')) if path.exists() else {} | |
| print(data.get('worker_url', '').rstrip('/')) | |
| PY | |
| ) | |
| if [ -z "$worker_url" ]; then | |
| echo "Unable to determine deployed workers.dev URL from deploy output" >&2 | |
| echo "Deploy log:" >&2 | |
| cat "${CF_DEPLOY_LOG}" >&2 | |
| exit 1 | |
| fi | |
| flags_url="${worker_url}/v1/runtime/flags" | |
| echo "Posting to ${flags_url}" | |
| curl --fail --silent --show-error \ | |
| --retry 5 --retry-all-errors --retry-delay 2 \ | |
| -H "Content-Type: application/json" \ | |
| -X POST \ | |
| --data '{"maintenance_mode":true,"models_bridge_enabled":true}' \ | |
| "$flags_url" | |
| - name: Runtime flags reset bridge check | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| worker_url=$(python - <<'PY' | |
| import json | |
| import os | |
| from pathlib import Path | |
| path = Path(os.environ['CF_DEPLOY_META']) | |
| data = json.loads(path.read_text(encoding='utf-8')) if path.exists() else {} | |
| print(data.get('worker_url', '').rstrip('/')) | |
| PY | |
| ) | |
| if [ -z "$worker_url" ]; then | |
| echo "Unable to determine deployed workers.dev URL from deploy output" >&2 | |
| echo "Deploy log:" >&2 | |
| cat "${CF_DEPLOY_LOG}" >&2 | |
| exit 1 | |
| fi | |
| flags_reset_url="${worker_url}/v1/runtime/flags/reset" | |
| echo "Posting to ${flags_reset_url}" | |
| curl --fail --silent --show-error \ | |
| --retry 5 --retry-all-errors --retry-delay 2 \ | |
| -H "Content-Type: application/json" \ | |
| -X POST \ | |
| --data '{}' \ | |
| "$flags_reset_url" | |
| - name: Runtime notes read bridge check | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| worker_url=$(python - <<'PY' | |
| import json | |
| import os | |
| from pathlib import Path | |
| path = Path(os.environ['CF_DEPLOY_META']) | |
| data = json.loads(path.read_text(encoding='utf-8')) if path.exists() else {} | |
| print(data.get('worker_url', '').rstrip('/')) | |
| PY | |
| ) | |
| if [ -z "$worker_url" ]; then | |
| echo "Unable to determine deployed workers.dev URL from deploy output" >&2 | |
| echo "Deploy log:" >&2 | |
| cat "${CF_DEPLOY_LOG}" >&2 | |
| exit 1 | |
| fi | |
| notes_url="${worker_url}/v1/runtime/notes" | |
| echo "Checking ${notes_url}" | |
| curl --fail --silent --show-error --retry 5 --retry-all-errors --retry-delay 2 "$notes_url" | |
| - name: Runtime notes write bridge check | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| worker_url=$(python - <<'PY' | |
| import json | |
| import os | |
| from pathlib import Path | |
| path = Path(os.environ['CF_DEPLOY_META']) | |
| data = json.loads(path.read_text(encoding='utf-8')) if path.exists() else {} | |
| print(data.get('worker_url', '').rstrip('/')) | |
| PY | |
| ) | |
| if [ -z "$worker_url" ]; then | |
| echo "Unable to determine deployed workers.dev URL from deploy output" >&2 | |
| echo "Deploy log:" >&2 | |
| cat "${CF_DEPLOY_LOG}" >&2 | |
| exit 1 | |
| fi | |
| notes_url="${worker_url}/v1/runtime/notes" | |
| echo "Posting to ${notes_url}" | |
| curl --fail --silent --show-error \ | |
| --retry 5 --retry-all-errors --retry-delay 2 \ | |
| -H "Content-Type: application/json" \ | |
| -X POST \ | |
| --data '{"note":"phase-2-smoke-test"}' \ | |
| "$notes_url" | |
| - name: Runtime notes reset bridge check | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| worker_url=$(python - <<'PY' | |
| import json | |
| import os | |
| from pathlib import Path | |
| path = Path(os.environ['CF_DEPLOY_META']) | |
| data = json.loads(path.read_text(encoding='utf-8')) if path.exists() else {} | |
| print(data.get('worker_url', '').rstrip('/')) | |
| PY | |
| ) | |
| if [ -z "$worker_url" ]; then | |
| echo "Unable to determine deployed workers.dev URL from deploy output" >&2 | |
| echo "Deploy log:" >&2 | |
| cat "${CF_DEPLOY_LOG}" >&2 | |
| exit 1 | |
| fi | |
| notes_reset_url="${worker_url}/v1/runtime/notes/reset" | |
| echo "Posting to ${notes_reset_url}" | |
| curl --fail --silent --show-error \ | |
| --retry 5 --retry-all-errors --retry-delay 2 \ | |
| -H "Content-Type: application/json" \ | |
| -X POST \ | |
| --data '{}' \ | |
| "$notes_reset_url" | |
| - name: Runtime storage bridge check | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| worker_url=$(python - <<'PY' | |
| import json | |
| import os | |
| from pathlib import Path | |
| path = Path(os.environ['CF_DEPLOY_META']) | |
| data = json.loads(path.read_text(encoding='utf-8')) if path.exists() else {} | |
| print(data.get('worker_url', '').rstrip('/')) | |
| PY | |
| ) | |
| if [ -z "$worker_url" ]; then | |
| echo "Unable to determine deployed workers.dev URL from deploy output" >&2 | |
| echo "Deploy log:" >&2 | |
| cat "${CF_DEPLOY_LOG}" >&2 | |
| exit 1 | |
| fi | |
| storage_url="${worker_url}/v1/runtime/storage" | |
| echo "Checking ${storage_url}" | |
| curl --fail --silent --show-error --retry 5 --retry-all-errors --retry-delay 2 "$storage_url" | |
| - name: OpenAI-style metadata bridge check | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| worker_url=$(python - <<'PY' | |
| import json | |
| import os | |
| from pathlib import Path | |
| path = Path(os.environ['CF_DEPLOY_META']) | |
| data = json.loads(path.read_text(encoding='utf-8')) if path.exists() else {} | |
| print(data.get('worker_url', '').rstrip('/')) | |
| PY | |
| ) | |
| if [ -z "$worker_url" ]; then | |
| echo "Unable to determine deployed workers.dev URL from deploy output" >&2 | |
| echo "Deploy log:" >&2 | |
| cat "${CF_DEPLOY_LOG}" >&2 | |
| exit 1 | |
| fi | |
| metadata_url="${worker_url}/v1/metadata" | |
| echo "Checking ${metadata_url}" | |
| curl --fail --silent --show-error --retry 5 --retry-all-errors --retry-delay 2 "$metadata_url" | |
| - name: Config summary bridge check | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| worker_url=$(python - <<'PY' | |
| import json | |
| import os | |
| from pathlib import Path | |
| path = Path(os.environ['CF_DEPLOY_META']) | |
| data = json.loads(path.read_text(encoding='utf-8')) if path.exists() else {} | |
| print(data.get('worker_url', '').rstrip('/')) | |
| PY | |
| ) | |
| if [ -z "$worker_url" ]; then | |
| echo "Unable to determine deployed workers.dev URL from deploy output" >&2 | |
| echo "Deploy log:" >&2 | |
| cat "${CF_DEPLOY_LOG}" >&2 | |
| exit 1 | |
| fi | |
| summary_url="${worker_url}/v1/config/summary" | |
| echo "Checking ${summary_url}" | |
| curl --fail --silent --show-error --retry 5 --retry-all-errors --retry-delay 2 "$summary_url" | |
| - name: Post deploy summary | |
| shell: bash | |
| run: | | |
| worker_url=$(python - <<'PY' | |
| import json | |
| import os | |
| from pathlib import Path | |
| path = Path(os.environ['CF_DEPLOY_META']) | |
| data = json.loads(path.read_text(encoding='utf-8')) if path.exists() else {} | |
| print(data.get('worker_url', '').rstrip('/')) | |
| PY | |
| ) | |
| python scripts/cf_post_deploy.py \ | |
| --resources "${CF_RESOURCES_OUTPUT}" \ | |
| --worker-name "${CF_WORKER_NAME}" \ | |
| --environment "${CF_ENVIRONMENT}" \ | |
| --worker-url "$worker_url" |