#!/usr/bin/env bash # # bun run publish [--deploy] "commit message" # # Submodule-aware publish workflow: # 1. sequoia publish → mints AT URI, cross-posts to Bluesky, mutates frontmatter # 2. git stage + commit (scoped to publish artifacts) # 3. (--deploy only) vercel build --prod → produces .vercel/output # 4. (--deploy only) vercel deploy --prebuilt --prod → uploads prebuilt artifacts # 5. revalidate via BLOG_REVALIDATE_URL so the new post is live # 6. git push → keeps git in sync with deployed state # # Environment variables: # BLOG_REVALIDATE_URL → endpoint to call on revalidation (default: none) # REVALIDATE_SECRET → secret header value (from consumer's .env) set -euo pipefail DEPLOY=false ARGS=() for arg in "$@"; do case "$arg" in --deploy) DEPLOY=true ;; *) ARGS+=("$arg") ;; esac done if [ "${#ARGS[@]}" -lt 1 ] || [ -z "${ARGS[0]}" ]; then echo "Usage: bun run publish [--deploy] \"commit message\"" >&2 exit 1 fi COMMIT_MSG="${ARGS[0]}" # Pre-flight: nothing already staged (we manage staging ourselves) if ! git diff --staged --quiet; then echo "Error: you have staged changes. Unstage or commit them separately first." >&2 git diff --staged --name-only >&2 exit 1 fi # 1. Publish to PDS + Bluesky echo "Publishing to sequoia..." sequoia publish # 2. Stage only the artifacts sequoia produces git add src/content/blog/ .sequoia-state.json # 3. Commit (skip if sequoia made no changes — e.g., re-run on unchanged content) if git diff --staged --quiet; then echo "No publish changes to commit. Continuing." else git commit -m "$COMMIT_MSG" fi # 4. (--deploy only) Build with Vercel's toolchain → .vercel/output # 5. (--deploy only) Upload prebuilt artifacts if $DEPLOY; then echo "Deploying to Vercel..." bunx vercel build --prod bunx vercel deploy --prebuilt --prod fi # 6. Revalidate via BLOG_REVALIDATE_URL (consumer-specific) if [ -n "${BLOG_REVALIDATE_URL:-}" ]; then echo "Revalidating: ${BLOG_REVALIDATE_URL}" if [ -n "${REVALIDATE_SECRET:-}" ]; then curl -sf -X POST "$BLOG_REVALIDATE_URL" \ -H "x-revalidate-secret: $REVALIDATE_SECRET" || \ echo "Warning: revalidation request failed (continuing)" else echo "Warning: BLOG_REVALIDATE_URL set but REVALIDATE_SECRET not set; skipping revalidation" fi else echo "No BLOG_REVALIDATE_URL configured; skipping revalidation" fi # 7. Push so origin/main matches deployed state echo "Pushing to remote..." git push