Files
probably-rendering-one-more…/scripts/preview/sync.sh
T
codex-bot fe26f03cf4
Unified application CI and deployment / static-checks (push) Successful in 5s
Remote development preview source sync / sync-source (push) Failing after 4m54s
Unified application CI and deployment / static-checks (pull_request) Successful in 5s
python CI and deployment / static-checks (pull_request) Successful in 3s
Unified application CI and deployment / verify-and-release (push) Has been skipped
Unified application CI and deployment / verify-and-release (pull_request) Has been skipped
python CI and deployment / verify-and-deploy (pull_request) Has been skipped
Use numeric container ownership during preview setup
2026-11-04 14:25:41 +08:00

48 lines
2.5 KiB
Bash

#!/usr/bin/env bash
set -Eeuo pipefail
SOURCE=$(realpath "${1:?checkout directory required}")
SHA=${2:?commit SHA required}
BRANCH=${3:?branch required}
[[ "$SHA" =~ ^[0-9a-f]{40}$ ]] || exit 2
ROOT=/opt/prompt-preview
exec 8>/var/lock/prompt-preview-sync.lock
flock -w 30 8
latest=$(git -C "$SOURCE" ls-remote origin "refs/heads/$BRANCH" | cut -f1)
test -n "$latest"
if [ "$latest" != "$SHA" ]; then echo "Skipping superseded preview commit $SHA"; exit 0; fi
candidate=$(node "$SOURCE/scripts/preview/fingerprint.mjs" "$SOURCE")
if [ ! -s "$ROOT/fingerprint" ]; then
echo 'Preview is not initialized; run scripts/preview/init.sh once with a verified tooling image' >&2
exit 1
fi
if [ "$(cat "$ROOT/fingerprint")" != "$candidate" ]; then
echo 'Preview refresh required: dependencies, startup configuration or database schema changed. No install/restart/migration was performed.' >&2
exit 1
fi
id=$(docker compose -p prompt-preview --env-file "$ROOT/env" -f "$ROOT/compose.yml" ps -q waterfall-wiki)
test -n "$id" && test "$(docker inspect --format '{{.State.Running}}' "$id")" = true
# No git credentials, dependency folders, compiler output or environment files are copied.
rsync -a --checksum --no-times --delete --numeric-ids --chown=1000:1000 \
--exclude='.git' --exclude='node_modules' --exclude='.next' --exclude='dist' \
--exclude='*.tsbuildinfo' --exclude='.env' --exclude='.env.*' --exclude='.gitea' \
--exclude='/apps/waterfall-wiki/public/brand/' --exclude='/apps/waterfall-wiki/public/favicon.ico' --exclude='/apps/waterfall-wiki/public/apple-touch-icon.png' "$SOURCE/" "$ROOT/source/"
# Keep generated public marks current using file copies only.
assets="$ROOT/source/packages/brand/assets"
public="$ROOT/source/apps/waterfall-wiki/public"
mkdir -p "$public/brand"
copy_asset() {
cmp -s "$1" "$2" || install -m 0644 "$1" "$2"
}
for name in logo-light.svg logo-dark.svg icon-dark.svg; do copy_asset "$assets/svg/$name" "$public/brand/$name"; done
copy_asset "$assets/icons/favicon.ico" "$public/favicon.ico"
copy_asset "$assets/icons/apple-touch-icon.png" "$public/apple-touch-icon.png"
SHA="$SHA" BRANCH="$BRANCH" DEST="$ROOT/status/status.json" python3 - <<'META'
import os,json,pathlib,datetime
destination=pathlib.Path(os.environ['DEST'])
temporary=destination.with_suffix('.tmp')
temporary.write_text(json.dumps({'sha':os.environ['SHA'],'branch':os.environ['BRANCH'],'syncedAt':datetime.datetime.now(datetime.timezone.utc).isoformat()})+'\n')
temporary.chmod(0o644)
temporary.replace(destination)
META
echo "Preview synchronized: $BRANCH $SHA (container $id)"