diff --git a/scripts/deploy.sh b/scripts/deploy.sh new file mode 100755 index 0000000..c15ea9b --- /dev/null +++ b/scripts/deploy.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +# deploy.sh — Build & deploy dashboard + gateway to Cloudflare +# +# Usage: +# ./scripts/deploy.sh # deploy both +# ./scripts/deploy.sh dashboard # dashboard only +# ./scripts/deploy.sh gateway # gateway only +# +# Env (via `cfg` or export): +# CLOUDFLARE_API_TOKEN — Cloudflare API token +set -euo pipefail + +REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" +cd "$REPO_ROOT" + +CLOUDFLARE_API_TOKEN="${CLOUDFLARE_API_TOKEN:?CLOUDFLARE_API_TOKEN is required}" +export CLOUDFLARE_API_TOKEN + +TARGET="${1:-all}" + +deploy_dashboard() { + echo "🌐 Building dashboard..." + (cd packages/workflow-dashboard && npm run build) + echo "🚀 Deploying dashboard to Cloudflare Pages..." + (cd packages/workflow-gateway && npx wrangler pages deploy \ + ../workflow-dashboard/dist \ + --project-name workflow-dashboard) + echo " ✅ Dashboard → workflow.shazhou.work" +} + +deploy_gateway() { + echo "🚀 Deploying gateway Worker..." + (cd packages/workflow-gateway && npx wrangler deploy) + echo " ✅ Gateway → workflow-gateway.shazhou.workers.dev" +} + +case "$TARGET" in + dashboard) deploy_dashboard ;; + gateway) deploy_gateway ;; + all) deploy_dashboard; deploy_gateway ;; + *) echo "Usage: deploy.sh [dashboard|gateway|all]"; exit 1 ;; +esac + +echo "✅ Deploy complete" diff --git a/scripts/publish.sh b/scripts/publish.sh new file mode 100755 index 0000000..a655ce9 --- /dev/null +++ b/scripts/publish.sh @@ -0,0 +1,139 @@ +#!/usr/bin/env bash +# publish.sh — Bump version & publish all @uncaged/workflow-* packages +# +# Usage: +# ./scripts/publish.sh 0.4.0 # explicit version +# ./scripts/publish.sh patch # 0.3.1 → 0.3.2 +# ./scripts/publish.sh minor # 0.3.1 → 0.4.0 +# +# Env (via `cfg` or export): +# GITEA_TOKEN — Gitea npm registry auth +set -euo pipefail + +REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" +cd "$REPO_ROOT" + +GITEA_TOKEN="${GITEA_TOKEN:?GITEA_TOKEN is required}" +GITEA_NPM_REGISTRY="https://git.shazhou.work/api/packages/uncaged/npm/" + +# ─── Version ───────────────────────────────────────────────────────────────── +current_version() { + node -e "console.log(require('./packages/workflow-protocol/package.json').version)" +} + +bump_version() { + local cur="$1" kind="$2" + IFS='.' read -r major minor patch <<< "$cur" + case "$kind" in + patch) echo "${major}.${minor}.$((patch + 1))" ;; + minor) echo "${major}.$((minor + 1)).0" ;; + major) echo "$((major + 1)).0.0" ;; + *) echo "$kind" ;; + esac +} + +CURRENT=$(current_version) +VERSION=$(bump_version "$CURRENT" "${1:?Usage: publish.sh }") +echo "📦 Publish: $CURRENT → $VERSION" + +# ─── Topological publish order ─────────────────────────────────────────────── +PUBLISH_ORDER=( + workflow-protocol + workflow-util + workflow-cas + workflow-runtime + workflow-reactor + workflow-register + workflow-execute + cli-workflow + workflow-util-agent + workflow-agent-cursor + workflow-agent-hermes + workflow-agent-llm + workflow-template-develop + workflow-template-solve-issue +) + +# ─── Bump version ──────────────────────────────────────────────────────────── +echo "🔢 Bumping versions..." +for dir in packages/*/; do + pkg="$dir/package.json" + [[ -f "$pkg" ]] || continue + is_private=$(node -e "console.log(require('./$pkg').private || false)") + [[ "$is_private" == "true" ]] && continue + node -e " + const fs = require('fs'); + const p = JSON.parse(fs.readFileSync('$pkg','utf8')); + p.version = '$VERSION'; + fs.writeFileSync('$pkg', JSON.stringify(p, null, 2) + '\n'); + " +done + +# ─── Replace workspace:* ───────────────────────────────────────────────────── +echo "🔗 Replacing workspace:* → $VERSION..." +for dir in packages/*/; do + pkg="$dir/package.json" + [[ -f "$pkg" ]] || continue + node -e " + const fs = require('fs'); + const p = JSON.parse(fs.readFileSync('$pkg','utf8')); + let c = false; + for (const k of ['dependencies','peerDependencies','devDependencies']) { + if (!p[k]) continue; + for (const [n, v] of Object.entries(p[k])) { + if (n.startsWith('@uncaged/') && v === 'workspace:*') { p[k][n] = '$VERSION'; c = true; } + } + } + if (c) fs.writeFileSync('$pkg', JSON.stringify(p, null, 2) + '\n'); + " +done + +# ─── Build ─────────────────────────────────────────────────────────────────── +echo "🔨 Building..." +npm run build + +# ─── Publish ───────────────────────────────────────────────────────────────── +echo "🚀 Publishing..." +cat > "$REPO_ROOT/.npmrc" <&1); then + echo " ✅ @uncaged/$pkg_dir@$VERSION" + else + echo " ❌ @uncaged/$pkg_dir" + FAIL=1 + fi +done + +# ─── Restore workspace:* ───────────────────────────────────────────────────── +echo "🔄 Restoring workspace:*..." +for dir in packages/*/; do + pkg="$dir/package.json" + [[ -f "$pkg" ]] || continue + node -e " + const fs = require('fs'); + const p = JSON.parse(fs.readFileSync('$pkg','utf8')); + let c = false; + for (const k of ['dependencies','peerDependencies','devDependencies']) { + if (!p[k]) continue; + for (const [n, v] of Object.entries(p[k])) { + if (n.startsWith('@uncaged/') && v === '$VERSION') { p[k][n] = 'workspace:*'; c = true; } + } + } + if (c) fs.writeFileSync('$pkg', JSON.stringify(p, null, 2) + '\n'); + " +done + +# ─── Commit ────────────────────────────────────────────────────────────────── +echo "📝 Committing..." +git add -A +git commit -m "chore: publish v${VERSION} + +小橘 " +git push + +[[ "$FAIL" -eq 0 ]] && echo "✅ v${VERSION} published" || echo "⚠️ v${VERSION} published with errors" diff --git a/scripts/release.sh b/scripts/release.sh deleted file mode 100755 index f0839a3..0000000 --- a/scripts/release.sh +++ /dev/null @@ -1,190 +0,0 @@ -#!/usr/bin/env bash -# release.sh — Publish all @uncaged/workflow-* packages + deploy dashboard -# -# Usage: -# ./scripts/release.sh # e.g. ./scripts/release.sh 0.4.0 -# ./scripts/release.sh patch # auto-bump patch (0.3.1 → 0.3.2) -# ./scripts/release.sh minor # auto-bump minor (0.3.1 → 0.4.0) -# -# Required env (via `cfg` or export): -# GITEA_TOKEN — Gitea npm registry auth -# CLOUDFLARE_API_TOKEN — Cloudflare Pages deploy -# -# What it does: -# 1. Bump version in all non-private package.json -# 2. Replace workspace:* with concrete version for publishing -# 3. npm publish in dependency order to Gitea registry -# 4. Restore workspace:* for local dev -# 5. Build & deploy dashboard to Cloudflare Pages -# 6. Git commit & push -set -euo pipefail - -REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" -cd "$REPO_ROOT" - -# ─── Env check ─────────────────────────────────────────────────────────────── -GITEA_TOKEN="${GITEA_TOKEN:?GITEA_TOKEN is required}" -CLOUDFLARE_API_TOKEN="${CLOUDFLARE_API_TOKEN:?CLOUDFLARE_API_TOKEN is required}" - -GITEA_NPM_REGISTRY="https://git.shazhou.work/api/packages/uncaged/npm/" - -# ─── Version resolution ───────────────────────────────────────────────────── -current_version() { - node -e "console.log(require('./packages/workflow-protocol/package.json').version)" -} - -bump_version() { - local cur="$1" kind="$2" - IFS='.' read -r major minor patch <<< "$cur" - case "$kind" in - patch) echo "${major}.${minor}.$((patch + 1))" ;; - minor) echo "${major}.$((minor + 1)).0" ;; - major) echo "$((major + 1)).0.0" ;; - *) echo "$kind" ;; # explicit version - esac -} - -CURRENT=$(current_version) -VERSION_ARG="${1:?Usage: release.sh }" -VERSION=$(bump_version "$CURRENT" "$VERSION_ARG") - -echo "📦 Release: $CURRENT → $VERSION" - -# ─── Publish order (topological) ───────────────────────────────────────────── -PUBLISH_ORDER=( - workflow-protocol - workflow-util - workflow-cas - workflow-runtime - workflow-reactor - workflow-register - workflow-execute - cli-workflow - workflow-util-agent - workflow-agent-cursor - workflow-agent-hermes - workflow-agent-llm - workflow-template-develop - workflow-template-solve-issue -) - -# ─── Step 1: Bump version ──────────────────────────────────────────────────── -echo "🔢 Bumping versions to $VERSION..." -for dir in packages/*/; do - pkg="$dir/package.json" - [[ -f "$pkg" ]] || continue - is_private=$(node -e "console.log(require('./$pkg').private || false)") - [[ "$is_private" == "true" ]] && continue - # Replace version - node -e " - const fs = require('fs'); - const pkg = JSON.parse(fs.readFileSync('$pkg', 'utf8')); - pkg.version = '$VERSION'; - fs.writeFileSync('$pkg', JSON.stringify(pkg, null, 2) + '\n'); - " -done - -# ─── Step 2: Replace workspace:* ───────────────────────────────────────────── -echo "🔗 Replacing workspace:* with $VERSION..." -for dir in packages/*/; do - pkg="$dir/package.json" - [[ -f "$pkg" ]] || continue - node -e " - const fs = require('fs'); - const pkg = JSON.parse(fs.readFileSync('$pkg', 'utf8')); - let changed = false; - for (const key of ['dependencies', 'peerDependencies', 'devDependencies']) { - const deps = pkg[key]; - if (!deps) continue; - for (const [name, ver] of Object.entries(deps)) { - if (name.startsWith('@uncaged/') && ver === 'workspace:*') { - deps[name] = '$VERSION'; - changed = true; - } - } - } - if (changed) fs.writeFileSync('$pkg', JSON.stringify(pkg, null, 2) + '\n'); - " -done - -# ─── Step 3: Build ─────────────────────────────────────────────────────────── -echo "🔨 Building..." -npm run build - -# ─── Step 4: Publish ───────────────────────────────────────────────────────── -echo "🚀 Publishing to Gitea npm registry..." - -# Write temporary .npmrc for publish auth -NPMRC="$REPO_ROOT/.npmrc" -cat > "$NPMRC" <&1); then - echo " ✅ @uncaged/$pkg_dir@$VERSION" - else - echo " ❌ @uncaged/$pkg_dir failed" - FAIL=1 - fi -done - -# ─── Step 5: Restore workspace:* ───────────────────────────────────────────── -echo "🔄 Restoring workspace:* for local dev..." -for dir in packages/*/; do - pkg="$dir/package.json" - [[ -f "$pkg" ]] || continue - node -e " - const fs = require('fs'); - const pkg = JSON.parse(fs.readFileSync('$pkg', 'utf8')); - let changed = false; - for (const key of ['dependencies', 'peerDependencies', 'devDependencies']) { - const deps = pkg[key]; - if (!deps) continue; - for (const [name, ver] of Object.entries(deps)) { - if (name.startsWith('@uncaged/') && ver === '$VERSION') { - deps[name] = 'workspace:*'; - changed = true; - } - } - } - if (changed) fs.writeFileSync('$pkg', JSON.stringify(pkg, null, 2) + '\n'); - " -done - -# ─── Step 6: Deploy dashboard ──────────────────────────────────────────────── -echo "🌐 Building & deploying dashboard..." -DASHBOARD_DIR="packages/workflow-dashboard" -if [[ -d "$DASHBOARD_DIR" ]]; then - (cd "$DASHBOARD_DIR" && npm run build) - # wrangler is only available via npx in the gateway package (has it as devDep) - (cd packages/workflow-gateway && npx wrangler pages deploy \ - "../workflow-dashboard/dist" \ - --project-name workflow-dashboard 2>&1) && \ - echo " ✅ Dashboard deployed" || \ - echo " ⚠️ Dashboard deploy failed (non-fatal)" -fi - -# ─── Step 7: Git commit & push ─────────────────────────────────────────────── -echo "📝 Committing..." -git add -A -git commit -m "chore: release v${VERSION} - -Published ${#PUBLISH_ORDER[@]} packages to Gitea npm registry. -Dashboard deployed to Cloudflare Pages. - -小橘 " -git push - -# ─── Done ──────────────────────────────────────────────────────────────────── -if [[ "$FAIL" -eq 0 ]]; then - echo "" - echo "✅ Released v${VERSION} — ${#PUBLISH_ORDER[@]} packages published" -else - echo "" - echo "⚠️ Released v${VERSION} with some failures — check output above" -fi