fix: refresh run source during distribution builds

This commit is contained in:
npc0-hue
2026-08-21 23:09:28 +08:00
parent 2381b69d24
commit 0a605495af
12 changed files with 317 additions and 119 deletions
+15 -46
View File
@@ -37,11 +37,15 @@ export RUN_VERSION="${RUN_VERSION:-0.1.0-local-debug}"
export RUN_REGISTRATION_TOKEN="${RUN_REGISTRATION_TOKEN:-local-debug-registration}"
export RUN_WORKSPACE_ROOT="${RUN_WORKSPACE_ROOT:-$LOCAL_DEBUG_ROOT/run/workspace}"
export RUN_BUILD_BUCKET_ROOT="${RUN_BUILD_BUCKET_ROOT:-$LOCAL_DEBUG_ROOT/run/build-buckets}"
export RUN_BUILD_SOURCE_ROOT="${RUN_BUILD_SOURCE_ROOT:-$RUN_BUILD_BUCKET_ROOT/source/current}"
export RUN_BUILD_SOURCE_ROOT="${RUN_BUILD_SOURCE_ROOT:-$RUN_SOURCE_DIR}"
export RUN_BOOTSTRAP_BIN="${RUN_BOOTSTRAP_BIN:-$RUN_BUILD_BUCKET_ROOT/bootstrap/bin/run}"
export PLATFORM_BUILDER_DOCKER_BINARY="${PLATFORM_BUILDER_DOCKER_BINARY:-docker}"
export PLATFORM_BUILDER_IMAGE="${PLATFORM_BUILDER_IMAGE:-browser-platform-distribution-builder:1.0.0}"
export PLATFORM_BUILDER_SOURCE_DIR="${PLATFORM_BUILDER_SOURCE_DIR:-$RUN_BUILD_SOURCE_ROOT}"
export RUN_SOURCE_REPOSITORY="${RUN_SOURCE_REPOSITORY:-git@git.npc0.com:admin343/run.git}"
export RUN_SOURCE_REVISION="${RUN_SOURCE_REVISION:-main}"
export PLATFORM_BUILDER_SOURCE_DIR="${PLATFORM_BUILDER_SOURCE_DIR:-$RUN_SOURCE_DIR}"
export PLATFORM_BUILDER_SOURCE_REPOSITORY="${PLATFORM_BUILDER_SOURCE_REPOSITORY:-$RUN_SOURCE_REPOSITORY}"
export PLATFORM_BUILDER_SOURCE_REVISION="${PLATFORM_BUILDER_SOURCE_REVISION:-$RUN_SOURCE_REVISION}"
export PLATFORM_BUILDER_WORKSPACE_DIR="${PLATFORM_BUILDER_WORKSPACE_DIR:-$PLATFORM_DATA_DIR/distribution-builds}"
export PLATFORM_BUILDER_CACHE_DIR="${PLATFORM_BUILDER_CACHE_DIR:-$PLATFORM_DATA_DIR/distribution-build-cache}"
export PLATFORM_BUILDER_TIMEOUT_SECONDS="${PLATFORM_BUILDER_TIMEOUT_SECONDS:-1800}"
@@ -142,51 +146,16 @@ local_debug_prepare_run_lifecycle_templates() {
local_debug_seed_plugin_lifecycle_template game.scum run-local
}
local_debug_require_bucket_path() {
local target="$1"
local parent
parent="$(dirname "$target")"
mkdir -p "$parent"
local resolved_parent
resolved_parent="$(cd "$parent" && pwd -P)"
local resolved="$resolved_parent/$(basename "$target")"
case "$resolved" in
"$LOCAL_DEBUG_ROOT"/* | /private/tmp/browser-local-debug-*/* | /tmp/browser-local-debug-*/*)
return 0
;;
esac
printf 'refusing to clear non-local-debug build bucket path: %s\n' "$target" >&2
printf 'set RUN_BUILD_BUCKET_ROOT/RUN_BUILD_SOURCE_ROOT under %s or an approved browser-local-debug temp root\n' "$LOCAL_DEBUG_ROOT" >&2
return 1
}
ensure_local_run_repo() {
if [[ ! -f "$RUN_SOURCE_DIR/go.mod" ]]; then
printf 'run source repo not found at %s\n' "$RUN_SOURCE_DIR" >&2
printf 'clone git@git.npc0.com:admin343/run.git into %s/run or set RUN_SOURCE_DIR/RUN_REPO_DIR to another independent run checkout\n' "$LOCAL_DEBUG_ROOT_DIR" >&2
local_debug_prepare_run_build_source() {
if [[ -e "$RUN_SOURCE_DIR" && ! -d "$RUN_SOURCE_DIR/.git" ]]; then
printf 'run source path is not a git checkout: %s\n' "$RUN_SOURCE_DIR" >&2
return 1
fi
}
local_debug_prepare_run_build_source() {
ensure_local_run_repo
local_debug_require_bucket_path "$RUN_BUILD_SOURCE_ROOT"
rm -rf "$RUN_BUILD_SOURCE_ROOT"
mkdir -p "$RUN_BUILD_SOURCE_ROOT"
rsync -a --delete \
--exclude '.git/' \
--exclude '.local-debug/' \
--exclude '.run-workspace/' \
--exclude '.tmp/' \
--exclude 'node_modules/' \
"$RUN_SOURCE_DIR"/ "$RUN_BUILD_SOURCE_ROOT"/
cat >"$RUN_BUILD_SOURCE_ROOT/.local-debug-source.json" <<EOF
{
"sourceDir": "$RUN_SOURCE_DIR",
"buildSourceRoot": "$RUN_BUILD_SOURCE_ROOT",
"createdBy": "scripts/local-debug/env.sh"
}
EOF
if [[ ! -d "$RUN_SOURCE_DIR/.git" ]]; then
mkdir -p "$(dirname "$RUN_SOURCE_DIR")"
git clone --no-checkout "$RUN_SOURCE_REPOSITORY" "$RUN_SOURCE_DIR"
fi
git -C "$RUN_SOURCE_DIR" fetch --depth 1 origin "$RUN_SOURCE_REVISION"
}
local_debug_prepare_distribution_builder() {
@@ -211,7 +180,7 @@ local_debug_build_bootstrap_run() {
local_debug_prepare_run_build_source
mkdir -p "$(dirname "$RUN_BOOTSTRAP_BIN")"
(
cd "$RUN_BUILD_SOURCE_ROOT"
cd "$RUN_SOURCE_DIR"
env GOCACHE="$GOCACHE" go build -trimpath -o "$RUN_BOOTSTRAP_BIN" ./cmd/run
)
chmod +x "$RUN_BOOTSTRAP_BIN"