Skip to content

Commit b66ea66

Browse files
committed
docs: harden vercel deploy wrapper
1 parent bc15647 commit b66ea66

2 files changed

Lines changed: 43 additions & 15 deletions

File tree

docs/contributing/development.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,22 +104,28 @@ pinned in the root `Cargo.toml` and `crates/orchestrator-cli/Cargo.toml`.
104104
`npm run docs:deploy` wraps the required preflight in order: sync check,
105105
production site build, then a Vercel production deploy. The deploy helper
106106
runs the sync check directly, uses the repo-local `vitepress` binary from
107-
`node_modules/.bin` for the site build, then runs `npx vercel --yes --prod`
108-
through `timeout`/`gtimeout`. The `npx` path points npm at a temporary cache
107+
`node_modules/.bin` for the site build, then prefers a directly installed
108+
`vercel` binary and falls back to `npx vercel --yes --prod` through
109+
`timeout`/`gtimeout`. The `npx` fallback points npm at a temporary cache
109110
directory so the deploy command does not depend on a writable `~/.npm/`.
111+
If VitePress hits the transient missing `.vitepress/.temp/*.md.js` render
112+
failure, the helper clears temp/cache state and retries the local build once
113+
before failing.
110114
The deploy timeout defaults to `300` seconds and can be raised with
111115
`ANIMUS_VERCEL_TIMEOUT_SECONDS=<seconds> npm run docs:deploy`.
112116

113117
The deploy step assumes the shell is already authenticated with Vercel. When
114-
using `npx`, it also assumes the runner can reach `registry.npmjs.org` to
118+
using the `npx` fallback, it also assumes the runner can reach
119+
`registry.npmjs.org` to
115120
resolve `vercel`. In restricted environments, expect the deploy phase to fail
116121
once it needs fresh network access, even when the docs are otherwise in sync.
117122
If `npm`/`npx` are missing from `PATH`, `scripts/deploy-docs.sh` also checks
118123
the repo-local `node_modules/.bin`, the active Node install's sibling `bin/`,
119124
common `nvm`/`volta`/`fnm`/`asdf` locations, and Homebrew paths before giving
120-
up. If none of those locations contain `npx`, the final Vercel deploy cannot
121-
proceed. The script also requires `timeout` (GNU coreutils) or `gtimeout`
122-
to bound the Vercel deploy step.
125+
up. The same PATH search applies to a directly installed `vercel` binary
126+
before the script falls back to `npx`. If neither route is available, the
127+
final Vercel deploy cannot proceed. The script also requires `timeout` (GNU
128+
coreutils) or `gtimeout` to bound the Vercel deploy step.
123129

124130
Protocol schema exports live at the repo root:
125131

scripts/deploy-docs.sh

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,23 @@ resolve_timeout_bin() {
6161
return 1
6262
}
6363

64-
if command -v vitepress >/dev/null 2>&1; then
64+
build_docs_once() {
65+
local vitepress_build_log="$1"
66+
6567
rm -rf docs/.vitepress/.temp docs/.vitepress/.cache
68+
vitepress build docs >"$vitepress_build_log" 2>&1
69+
}
70+
71+
if command -v vitepress >/dev/null 2>&1; then
6672
vitepress_build_log="$(mktemp "${TMPDIR:-/tmp}/animus-vitepress.XXXXXX")"
67-
if ! vitepress build docs >"$vitepress_build_log" 2>&1; then
68-
if rg -q '@rollup/rollup-darwin-arm64|ERR_DLOPEN_FAILED|Team IDs' "$vitepress_build_log"; then
73+
if ! build_docs_once "$vitepress_build_log"; then
74+
if rg -q "ERR_MODULE_NOT_FOUND.*docs/.vitepress/.temp.*\\.md\\.js|Cannot find module '.*/docs/.vitepress/.temp/.*\\.md\\.js'" "$vitepress_build_log"; then
75+
echo "VitePress hit the transient missing-temp-module render failure; retrying once after a clean temp/cache reset." >&2
76+
if ! build_docs_once "$vitepress_build_log"; then
77+
cat "$vitepress_build_log" >&2
78+
exit 1
79+
fi
80+
elif rg -q '@rollup/rollup-darwin-arm64|ERR_DLOPEN_FAILED|Team IDs' "$vitepress_build_log"; then
6981
echo "Local VitePress build is blocked by the known Rollup macOS native-module signing issue." >&2
7082
echo "Continuing to Vercel so the remote build can validate and publish the docs." >&2
7183
else
@@ -82,10 +94,20 @@ fi
8294
echo "Deploying docs with Vercel..."
8395
echo "Prerequisites: network access for Vercel and a valid Vercel login."
8496

85-
npx_bin="$(resolve_node_package_manager_bin npx)" || {
86-
echo "Unable to find npx. Install Node tooling or expose an existing Node install." >&2
87-
exit 1
88-
}
97+
vercel_bin=""
98+
vercel_runner=()
99+
100+
if command -v vercel >/dev/null 2>&1; then
101+
vercel_bin="$(command -v vercel)"
102+
vercel_runner=("$vercel_bin" --yes --prod)
103+
else
104+
npx_bin="$(resolve_node_package_manager_bin npx)" || {
105+
echo "Unable to find npx. Install Node tooling or expose an existing Node install." >&2
106+
exit 1
107+
}
108+
vercel_bin="$npx_bin"
109+
vercel_runner=("$npx_bin" vercel --yes --prod)
110+
fi
89111

90112
npx_cache_dir="$(mktemp -d "${TMPDIR:-/tmp}/animus-vercel.XXXXXX")"
91113
trap 'rm -rf "$npx_cache_dir"' EXIT
@@ -96,7 +118,7 @@ timeout_bin="$(resolve_timeout_bin)" || {
96118
exit 1
97119
}
98120
vercel_timeout_seconds="${ANIMUS_VERCEL_TIMEOUT_SECONDS:-300}"
99-
echo "Using npx via $npx_bin."
121+
echo "Using Vercel command via $vercel_bin."
100122
echo "Using temporary npm cache at $npx_cache_dir."
101123
echo "Bounding Vercel deploy to ${vercel_timeout_seconds}s via $timeout_bin."
102124

@@ -107,7 +129,7 @@ npm_config_fetch_retries=0 \
107129
npm_config_fetch_timeout=10000 \
108130
npm_config_fetch_retry_maxtimeout=10000 \
109131
"$timeout_bin" --foreground "${vercel_timeout_seconds}s" \
110-
"$npx_bin" vercel --yes --prod >"$vercel_deploy_log" 2>&1
132+
"${vercel_runner[@]}" >"$vercel_deploy_log" 2>&1
111133
vercel_exit_code=$?
112134
set -e
113135

0 commit comments

Comments
 (0)