cloudflare/kumo
Publicmirrored from https://github.com/cloudflare/kumoAvailable
ci/versioning/deploy-kumo-docs-preview.sh
79lines · modecode
| 1 | #!/bin/bash |
| 2 | set -euo pipefail |
| 3 | |
| 4 | # Kumo Docs Preview Deployment Script |
| 5 | # Uploads a new version to kumo-docs worker, outputs report artifact |
| 6 | # |
| 7 | # PREREQUISITES: |
| 8 | # - Preview URLs must be enabled in Cloudflare dashboard: |
| 9 | # Workers & Pages > kumo-docs > Settings > Domains & Routes > Preview URLs > Enable |
| 10 | # - wrangler.jsonc must have "preview_urls": true (already configured) |
| 11 | |
| 12 | echo "📚 Starting kumo-docs preview deployment..." |
| 13 | |
| 14 | # Verify Cloudflare credentials |
| 15 | if [ -z "$CLOUDFLARE_API_TOKEN" ] || [ -z "$CLOUDFLARE_ACCOUNT_ID" ]; then |
| 16 | echo "❌ CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID are required" |
| 17 | exit 1 |
| 18 | fi |
| 19 | |
| 20 | echo "🔨 Building @cloudflare/kumo library..." |
| 21 | pnpm --filter @cloudflare/kumo build |
| 22 | |
| 23 | echo "🔨 Building kumo-docs..." |
| 24 | pnpm --filter @cloudflare/kumo-docs-astro build |
| 25 | |
| 26 | echo "🚀 Uploading version to kumo-docs worker..." |
| 27 | cd packages/kumo-docs-astro |
| 28 | echo " Using wrangler version: $(npx wrangler --version)" |
| 29 | |
| 30 | # Upload version - capture output regardless of exit code |
| 31 | COMMIT_SHORT="${GITHUB_SHA:0:7}" |
| 32 | COMMIT_SHORT="${COMMIT_SHORT:-local}" |
| 33 | VERSION_OUTPUT=$(npx wrangler versions upload --message "Preview for ${COMMIT_SHORT}" 2>&1) || true |
| 34 | |
| 35 | echo "$VERSION_OUTPUT" |
| 36 | |
| 37 | # Verify upload succeeded by checking for Worker Version ID |
| 38 | if ! echo "$VERSION_OUTPUT" | grep -q "Worker Version ID:"; then |
| 39 | echo "❌ Failed to upload version - no Worker Version ID in output" |
| 40 | exit 1 |
| 41 | fi |
| 42 | |
| 43 | # Try to extract Version Preview URL from wrangler output |
| 44 | PREVIEW_URL=$(echo "$VERSION_OUTPUT" | grep -oE 'Version Preview URL: https://[^ ]+' | sed 's/Version Preview URL: //') |
| 45 | |
| 46 | # If wrangler didn't output a preview URL, construct it from the version ID |
| 47 | # Format: https://<version-prefix>-<worker-name>.<subdomain>.workers.dev |
| 48 | if [ -z "$PREVIEW_URL" ]; then |
| 49 | echo " Wrangler did not output preview URL, constructing from version ID..." |
| 50 | VERSION_ID=$(echo "$VERSION_OUTPUT" | grep -oE 'Worker Version ID: [a-f0-9-]+' | sed 's/Worker Version ID: //') |
| 51 | if [ -n "$VERSION_ID" ]; then |
| 52 | # Version prefix is first 8 chars of the version ID |
| 53 | VERSION_PREFIX=$(echo "$VERSION_ID" | cut -c1-8) |
| 54 | WORKER_NAME="kumo-docs" |
| 55 | SUBDOMAIN="design-engineering" |
| 56 | PREVIEW_URL="https://${VERSION_PREFIX}-${WORKER_NAME}.${SUBDOMAIN}.workers.dev" |
| 57 | echo " Constructed preview URL: $PREVIEW_URL" |
| 58 | fi |
| 59 | fi |
| 60 | |
| 61 | if [ -z "$PREVIEW_URL" ]; then |
| 62 | echo "❌ Failed to determine preview URL" |
| 63 | echo "Full output was:" |
| 64 | echo "$VERSION_OUTPUT" |
| 65 | exit 1 |
| 66 | fi |
| 67 | |
| 68 | echo "✅ Version uploaded successfully" |
| 69 | |
| 70 | cd ../.. |
| 71 | |
| 72 | export KUMO_DOCS_PREVIEW_URL="$PREVIEW_URL" |
| 73 | echo "✅ Kumo docs preview available: $KUMO_DOCS_PREVIEW_URL" |
| 74 | |
| 75 | # Output report artifact for the PR reporter job |
| 76 | echo "📄 Writing report artifact..." |
| 77 | pnpm tsx ci/scripts/write-kumo-docs-report.ts |
| 78 | |
| 79 | echo "🎉 Kumo docs preview deployment complete!" |
| 80 | |