cloudflare/kumo

Public

mirrored from https://github.com/cloudflare/kumoAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
main

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

ci/versioning/deploy-kumo-docs-preview.sh

79lines · modecode

1#!/bin/bash
2set -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
12echo "📚 Starting kumo-docs preview deployment..."
13
14# Verify Cloudflare credentials
15if [ -z "$CLOUDFLARE_API_TOKEN" ] || [ -z "$CLOUDFLARE_ACCOUNT_ID" ]; then
16 echo "❌ CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID are required"
17 exit 1
18fi
19
20echo "🔨 Building @cloudflare/kumo library..."
21pnpm --filter @cloudflare/kumo build
22
23echo "🔨 Building kumo-docs..."
24pnpm --filter @cloudflare/kumo-docs-astro build
25
26echo "🚀 Uploading version to kumo-docs worker..."
27cd packages/kumo-docs-astro
28echo " Using wrangler version: $(npx wrangler --version)"
29
30# Upload version - capture output regardless of exit code
31COMMIT_SHORT="${GITHUB_SHA:0:7}"
32COMMIT_SHORT="${COMMIT_SHORT:-local}"
33VERSION_OUTPUT=$(npx wrangler versions upload --message "Preview for ${COMMIT_SHORT}" 2>&1) || true
34
35echo "$VERSION_OUTPUT"
36
37# Verify upload succeeded by checking for Worker Version ID
38if ! echo "$VERSION_OUTPUT" | grep -q "Worker Version ID:"; then
39 echo "❌ Failed to upload version - no Worker Version ID in output"
40 exit 1
41fi
42
43# Try to extract Version Preview URL from wrangler output
44PREVIEW_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
48if [ -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
59fi
60
61if [ -z "$PREVIEW_URL" ]; then
62 echo "❌ Failed to determine preview URL"
63 echo "Full output was:"
64 echo "$VERSION_OUTPUT"
65 exit 1
66fi
67
68echo "✅ Version uploaded successfully"
69
70cd ../..
71
72export KUMO_DOCS_PREVIEW_URL="$PREVIEW_URL"
73echo "✅ Kumo docs preview available: $KUMO_DOCS_PREVIEW_URL"
74
75# Output report artifact for the PR reporter job
76echo "📄 Writing report artifact..."
77pnpm tsx ci/scripts/write-kumo-docs-report.ts
78
79echo "🎉 Kumo docs preview deployment complete!"
80